std

std(v[, region])

Compute the sample standard deviation of a vector or array v, optionally along dimensions in region. The algorithm returns an estimator of the generative distribution's standard deviation under the assumption that each entry of v is an IID drawn from that generative distribution. This computation is equivalent to calculating sqrt(sum((v - mean(v)).^2) / (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

std(v[, region]) computes the sample standard deviation of a vector or array v, optionally along dimensions specified by region. The function returns an estimator of the generative distribution's standard deviation, assuming each entry of v is independently and identically distributed (IID) from that generative distribution.

The computation is equivalent to calculating sqrt(sum((v - mean(v)).^2) / (length(v) - 1)). It's important to note that Julia does not ignore NaN values in the computation.

Here are some examples of how to use the std function:

  1. Compute the standard deviation of a vector:

    julia> v = [1, 2, 3, 4, 5];
    julia> std(v)
    1.5811388300841898

    This example calculates the standard deviation of the vector v.

  2. Calculate the standard deviation along a specific dimension of an array:

    julia> A = [1 2 3; 4 5 6; 7 8 9];
    julia> std(A, 1)  # Calculate along the rows (dimension 1)
    3-element Array{Float64,1}:
    2.449489742783178
    2.449489742783178
    2.449489742783178

    In this example, the standard deviation is computed along the rows (dimension 1) of the 2-dimensional array A.

  3. Compute the standard deviation of a subset of a vector:
    julia> v = [1, 2, 3, 4, 5];
    julia> std(v[2:end])
    1.5811388300841898

    Here, the standard deviation is calculated for a subset of the vector v excluding the first element.

Remember that std follows the Bessel's correction, dividing by (length(v) - 1) instead of length(v) to estimate the generative distribution's standard deviation accurately from the sample.

Note: If you need to handle missing data, the DataArray package is recommended.

See Also

cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,

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: