var

var(v[, region])

Compute the sample variance of a vector or array v, optionally along dimensions in region. The algorithm will return an estimator of the generative distribution's variance under the assumption that each entry of v is an IID drawn from that generative distribution. This computation is equivalent to calculating sumabs2(v - mean(v)) / (length(v) - 1). Note: Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArray package is recommended.

Examples

  1. Compute sample variance of a vector:

    julia> v = [1, 2, 3, 4, 5];
    julia> var(v)
    2.5

    This example calculates the sample variance of the vector v.

  2. Compute sample variance along a specific dimension of an array:

    julia> A = [1 2 3; 4 5 6; 7 8 9];
    julia> var(A, 1)
    6-element Array{Float64,1}:
    9.0
    9.0
    9.0

    Here, the var function calculates the sample variance along the first dimension (1) of the array A.

  3. Compute sample variance along multiple dimensions of an array:
    julia> B = [1 2 3; 4 5 6; 7 8 9];
    julia> var(B, (1, 2))
    1-element Array{Float64,1}:
    6.666666666666667

    In this example, the var function calculates the sample variance along both dimensions (1 and 2) of the array B.

Note: Julia does not ignore NaN values in the computation. If your data contains NaN values and you want to handle missing data, it is recommended to use the DataArray package.

Please let me know if there's anything else I can help you with!

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: