({{, (RefLink[Variance, paclet:ref/Variance])[list]
gives the sample variance of the elements in list. }, {, (RefLink[Variance, paclet:ref/Variance])[dist]
gives the variance of the distribution dist.}})

OpenersNotesSection(Spacer1)Details

(RefLink[Variance, paclet:ref/Variance]) measures dispersion of data or distributions.

(RefLink[Variance, paclet:ref/Variance])[list] gives the unbiased estimate of variance.

(RefLink[Variance, paclet:ref/Variance])[list] is equivalent to (RefLink[Total, paclet:ref/Total])[(list-(RefLink[Mean, paclet:ref/Mean])[list])^2]/((RefLink[Length, paclet:ref/Length])[list]-1) for real-valued data.

For complex data, (RefLink[Variance, paclet:ref/Variance])[list] is equivalent to (list-(RefLink[Mean, paclet:ref/Mean])[list]).(RefLink[Conjugate, paclet:ref/Conjugate])[list-(RefLink[Mean, paclet:ref/Mean])[list]]/((RefLink[Length, paclet:ref/Length])[list]-1).

(RefLink[Variance, paclet:ref/Variance]) handles both numerical and symbolic data.

(RefLink[Variance, paclet:ref/Variance])[{{(Subscript[x, 1]),(Subscript[y, 1]),…},{(Subscript[x, 2]),(Subscript[y, 2]),…},…}] gives {Variance[{(Subscript[x, 1]),(Subscript[x, 2]),…}],Variance[{(Subscript[y, 1]),(Subscript[y, 2]),…}]}.

(RefLink[Variance, paclet:ref/Variance])[dist] is equivalent to (RefLink[Expectation, paclet:ref/Expectation])[(((x-μ))^2),x\[Distributed]dist] with μ=(RefLink[Mean, paclet:ref/Mean])[dist].

OpenersPrimaryExamplesSection(Spacer1)Examples  (33)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Variance of a list of numbers:

Variance[{1.21,3.4,2,4.66,1.5,5.61,7.22}]

Variance of elements in each column:

Variance[{{5.2,7},{5.3,8},{5.4,9}}]

Variance of a parametric distribution:

Variance[LogNormalDistribution[0,1]]

OpenersExampleSection1(Spacer1)Scope  (13)

OpenersExampleSubsection0(Spacer1)Data  (10)

Exact input yields exact output:

Variance[{1,2,3,4}]

Variance[{π,E,3}]//Together

Approximate input yields approximate output:

Variance[{1.,2.,3.,4.}]

Variance[N[{1,2,3,4},30]]

(RefLink[Variance, paclet:ref/Variance]) for a matrix gives columnwise variances:

Variance[Array[(Subscript[a, ##])&,{2,2}]]

(RefLink[Variance, paclet:ref/Variance]) for a tensor gives columnwise variances at the first level:

Variance[Array[(Subscript[a, ##])&,{2,2,2}]]

Works with large arrays:

Variance[RandomReal[1,10^7]]

Variance[RandomReal[1,{10^6,5}]]

(RefLink[SparseArray, paclet:ref/SparseArray]) data can be used just like dense arrays:

Variance[SparseArray[{{1}->1,{100}->1}]]

Variance[SparseArray[{{1,1}->1,{2,2}->2,{3,3}->3,{1,3}->4}]]

Find the variance of (RefLink[WeightedData, paclet:ref/WeightedData]):

Variance[WeightedData[{1,2,3},{(Subscript[w, 1]),(Subscript[w, 2]),(Subscript[w, 3])}]]

data={8,3,5,4,9,0,4,2,2,3};
weights={0.15,0.09,0.12,0.10,0.16,0.,0.11,0.08,0.08,0.09};

Variance[WeightedData[data,weights]]

Find the variance of (RefLink[EventData, paclet:ref/EventData]):

e={1.0,2.1,3.2,4.5,5.7};
ci={0,0,0,1,0};

Variance[EventData[e,ci]]

Find the variance of (RefLink[TemporalData, paclet:ref/TemporalData]):

s1={2,1,6,5,7,4};
s2={4,7,5,6,1,2};
t={1,2,5,10,12,15};

td=TemporalData[{s1,s2},{t}];

Variance[td[10]]

Find the variance of a (RefLink[TimeSeries, paclet:ref/TimeSeries]):

v={3,8,4,11,9,2};
t={1,3,5,7,8,10};
ts=TimeSeries[v,{t}];

Variance[ts]//N

The variance depends only on the values:

Variance[ts["Values"]]//N

Find the variance of data involving quantities:

data=Quantity[RandomReal[1,6],"Meters"]

Variance[data]

OpenersExampleSubsection1(Spacer1)Distributions and Processes  (3)

Find the variance for univariate distributions:

Variance[BinomialDistribution[n,p]]

Variance[NormalDistribution[μ,σ]]

Multivariate distributions:

Variance[MultivariateHypergeometricDistribution[n,{(Subscript[m, 1]),(Subscript[m, 2])}]]

Variance[BinormalDistribution[{(Subscript[μ, 1]),(Subscript[μ, 2])},{σ1,σ2},ρ]]

Variance for derived distributions:

Variance[TransformedDistribution[(x^2),x\[Distributed]NormalDistribution[μ,σ]]]

Variance[ProbabilityDistribution[(Sqrt[2]/π)(1/(1+(((x-2))^4))),{x,-∞,∞}]]

Data distribution:

data=RandomVariate[NormalDistribution[],10^3];

Variance[HistogramDistribution[data]]

Variance function for a random process:

Variance[BrownianBridgeProcess[a,b][t]]

Plot[Evaluate[%/.{a->3,b->5}],{t,3,5},PlotRange->All]

OpenersExampleSection2(Spacer1)Applications  (5)

(RefLink[Variance, paclet:ref/Variance]) is a measure of dispersion:

𝒟=NormalDistribution[0,σ];

Variance[𝒟]

Table[Plot[PDF[𝒟,x],{x,-4,4},PlotRange->{0,0.4},Filling->Axis,Ticks->{Automatic,None},PlotLabel->Row[{"(σ^2) = ",(σ^2)}]],{σ,{1,1.5,2}}]

Compute a moving variance for samples of three random processes:

times={0,1,.01};
td1=RandomFunction[WienerProcess[],times];
td2=RandomFunction[OrnsteinUhlenbeckProcess[0,1,1/3,0],times];
td3=RandomFunction[FractionalBrownianMotionProcess[1/4],times];

ListLinePlot[{td1,td2,td3},PlotRange->All,PlotLegends->(lgd={"Wiener process sample","Ornstein-Uhlenbeck process sample","FBM process sample"})]

Compare data volatility by smoothing with moving variance:

mvar=Map[MovingMap[Variance,#,Quantity[20,"Events"]]&,{td1,td2,td3}];

ListLinePlot[mvar,PlotRange->All,PlotLegends->lgd]

Find the mean and variance for the number of great inventions and scientific discoveries in each year from 1860 to 1959:

data=ExampleData[{"Statistics","ScientificDiscoveries"},"EventSeries"]

ListPlot[data,Filling->0]

{Mean[data],Variance[data]}//N

Investigate weak stationarity of the process data by analyzing variance of slices:

data=TemporalData[];

times=Range[0,1,.1];

var=Map[{#,Variance[data[#]]}&,times];

ListLinePlot[var]

Use a larger plot range to see how relatively small the variations are:

ListLinePlot[var,PlotRange->{0,.5}]

Find the variance of the heights for the children in a class:

heights = Quantity[{134,143,131,140,145,136,131,136,143,136,133,145,147,
        150,150,146,137,143,132,142,145,136,144,135,141},"Centimeters"];

ListPlot[heights,Filling->Axis,AxesLabel->Automatic]

Variance[heights]//N

OpenersExampleSection3(Spacer1)Properties & Relations  (11)

The square root of (RefLink[Variance, paclet:ref/Variance]) is (RefLink[StandardDeviation, paclet:ref/StandardDeviation]):

Variance[{1,2,3,4}]

StandardDeviation[{1,2,3,4}]

(RefLink[Variance, paclet:ref/Variance]) is a scaled squared (RefLink[Norm, paclet:ref/Norm]) of deviations from the (RefLink[Mean, paclet:ref/Mean]):

data=RandomReal[10,20];

Variance[data]

Norm[data-Mean[data]]^2/(Length[data]-1)

(RefLink[Variance, paclet:ref/Variance]) is a scaled (RefLink[CentralMoment, paclet:ref/CentralMoment]):

data=RandomReal[10,20];

Variance[data]

CentralMoment[data,2] Length[data]/(Length[data]-1)

The square root of (RefLink[Variance, paclet:ref/Variance]) is a scaled (RefLink[RootMeanSquare, paclet:ref/RootMeanSquare]) of the deviations:

data=RandomReal[10,10];

RootMeanSquare[data-Mean[data]]Sqrt[Length[data]/(Length[data]-1)]

Variance[data]//Sqrt

(RefLink[Variance, paclet:ref/Variance]) is a scaled (RefLink[Mean, paclet:ref/Mean]) of squared deviations from the (RefLink[Mean, paclet:ref/Mean]):

data=RandomReal[5,20];

Variance[data]

Mean[(data-Mean[data])^2] Length[data]/(Length[data]-1)

(RefLink[Variance, paclet:ref/Variance]) is a scaled (RefLink[SquaredEuclideanDistance, paclet:ref/SquaredEuclideanDistance]) from the (RefLink[Mean, paclet:ref/Mean]):

data=RandomReal[10,20];

mean=Mean[data]

len=Length[data]

SquaredEuclideanDistance[data,Table[mean,{len}]]/(len-1)

Variance[data]

(RefLink[Variance, paclet:ref/Variance]) is less than (RefLink[MeanDeviation, paclet:ref/MeanDeviation]) if all absolute deviations are less than 1:

data=RandomReal[1,10];

MeanDeviation[data]

Variance[data]

(RefLink[Variance, paclet:ref/Variance]) is greater than (RefLink[MeanDeviation, paclet:ref/MeanDeviation]) if all absolute deviations are greater than 1:

data=Join[RandomReal[{1,2},5],RandomReal[{5,6},5]];

MeanDeviation[data]

Variance[data]

(RefLink[Variance, paclet:ref/Variance]) of a random variable as an (RefLink[Expectation, paclet:ref/Expectation]):

dist=GammaDistribution[α,β];

Expectation[(x-Mean[dist])^2,x\[Distributed]dist]

Variance[dist]

(RefLink[Variance, paclet:ref/Variance]) gives an unbiased sample estimate:

n=6;
var=Variance[Array[Subscript[x,#]&,n]]/.Conjugate->Identity

Unbiased means that the expected value of the sample variance with respect to the population distribution equals the variance of the underlying distribution:

Table[Expectation[var,Array[Subscript[x,#]\[Distributed]dist&,n]],{dist,{UniformDistribution[],ExponentialDistribution[λ],NormalDistribution[μ,σ]}}]

Variance/@{UniformDistribution[],ExponentialDistribution[λ],NormalDistribution[μ,σ]}

(RefLink[Variance, paclet:ref/Variance]) gives an unbiased weighted sample estimate:

n=5;
wdata=WeightedData[Array[Subscript[x,#]&,n],Array[Subscript[w,#]&,n]]

(var=Variance[wdata])//Short

Unbiased means that the expected value of the sample variance with respect to the population distribution equals the variance of the underlying distribution:

Table[Expectation[var,Array[Subscript[x,#]\[Distributed]dist&,n]],{dist,{BetaDistribution[α,β],GammaDistribution[α,β],NormalDistribution[μ,σ]}}]

Variance/@{BetaDistribution[α,β],GammaDistribution[α,β],NormalDistribution[μ,σ]}

OpenersExampleSection4(Spacer1)Neat Examples  (1)

The distribution of (RefLink[Variance, paclet:ref/Variance]) estimates for 20, 100, and 300 samples:

Variance[ExponentialDistribution[0.9]]

SmoothHistogram[Table[Variance[RandomVariate[ExponentialDistribution[0.9],{s,1000}]],{s,{20,100,300}}],Filling->Axis,PlotLegends->{20,100,300},PlotRange->{{0,3},Automatic}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[StandardDeviation, paclet:ref/StandardDeviation])  ▪  (RefLink[Covariance, paclet:ref/Covariance])  ▪  (RefLink[Correlation, paclet:ref/Correlation])  ▪  (RefLink[TrimmedVariance, paclet:ref/TrimmedVariance])  ▪  (RefLink[WinsorizedVariance, paclet:ref/WinsorizedVariance])  ▪  (RefLink[BiweightMidvariance, paclet:ref/BiweightMidvariance])  ▪  (RefLink[QnDispersion, paclet:ref/QnDispersion])  ▪  (RefLink[SnDispersion, paclet:ref/SnDispersion])  ▪  (RefLink[Mean, paclet:ref/Mean])  ▪  (RefLink[MeanDeviation, paclet:ref/MeanDeviation])  ▪  (RefLink[MedianDeviation, paclet:ref/MedianDeviation])  ▪  (RefLink[Kurtosis, paclet:ref/Kurtosis])  ▪  (RefLink[CentralMoment, paclet:ref/CentralMoment])  ▪  (RefLink[Expectation, paclet:ref/Expectation])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Basic Statistics, paclet:tutorial/BasicStatistics])}, {▪(RefLinkPlain[Descriptive Statistics, paclet:tutorial/DescriptiveStatistics])}, {▪(RefLinkPlain[Discrete Distributions, paclet:tutorial/DiscreteDistributions])}, {▪(RefLinkPlain[Continuous Distributions, paclet:tutorial/ContinuousDistributions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Descriptive Statistics, paclet:guide/DescriptiveStatistics])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}, {▪(RefLinkPlain[Math & Counting Operations on Lists, paclet:guide/MathematicalAndCountingOperationsOnLists])}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}, {▪(RefLinkPlain[Statistical Moments and Generating Functions, paclet:guide/StatisticalMomentsAndGeneratingFunctions])}, {▪(RefLinkPlain[Numerical Data, paclet:guide/NumericalData])}, {▪(RefLinkPlain[Scientific Data Analysis, paclet:guide/ScientificDataAnalysis])}, {▪(RefLinkPlain[Precollege Education, paclet:guide/PrecollegeEducation])}, {▪(RefLinkPlain[Image Processing & Analysis, paclet:guide/ImageProcessing])}, {▪(RefLinkPlain[Probability & Statistics, paclet:guide/ProbabilityAndStatistics])}, {▪(RefLinkPlain[Audio Processing, paclet:guide/AudioProcessing])}})}})