R Variance
Variance
The variance is another number that tells how spread out the values are.
It is closely connected to the standard deviation: the variance is the standard deviation multiplied by itself. So the standard deviation is the square root of the variance.
Use the var() function to find the variance:
Example
b <- c(1, 5, 9)
var(b)
sqrt(var(b))
sd(b)
Result:
[1] 16
[1] 4
[1] 4The variance is 16, and the square root of 16 is 4, which is the same as the standard deviation.
Variance of a Data Set
Find the variance of the weight (wt) of the cars in the mtcars data set:
Example
Data_Cars <- mtcars
var(Data_Cars$wt)
Result:
[1] 0.957379Variance or Standard Deviation?
The standard deviation is often easier to understand, because it uses the same unit as the data (for example, 1000 lbs). The variance uses that unit squared.
The variance is still useful, because many statistical methods are built on it.