varm

varm(v, m)

Compute the sample variance of a vector `v` with known mean `m`. Note: Julia does not ignore `NaN` values in the computation.

Examples

1. Calculate sample variance with known mean:

``````julia> v = [1, 2, 3, 4, 5];
julia> m = 3.0;
julia> varm(v, m)
2.5``````

This example calculates the sample variance of the vector `v` with a known mean `m` of 3.0.

2. Handle NaN values:

``````julia> v = [1.0, 2.0, NaN, 4.0, 5.0];
julia> m = 3.0;
julia> varm(v, m)
NaN``````

The `varm` function does not ignore `NaN` values in the computation. If the vector `v` contains `NaN` values, the result will be `NaN`.

3. Calculate variance with integer values:
``````julia> v = [10, 20, 30, 40, 50];
julia> m = 30.0;
julia> varm(v, m)
200.0``````

The `varm` function can also be used with integer values. In this example, it calculates the variance of the vector `v` with a known mean `m` of 30.0.

Common mistake example:

``````julia> v = [];
julia> m = 5.0;
julia> varm(v, m)
ERROR: DomainError with NaN result``````

In this example, the vector `v` is empty, resulting in a `DomainError` with a `NaN` result. Ensure that the vector has at least one element before using the `varm` function to avoid such errors.