In this section we’ll look at how to calculate Variance in R.
Variance is defined as the sum of squares of deviations of the set of numbers from the mean value. It is a measure of how far a set of data are dispersed out from their mean value . It is always a non -negative number. It is generally denoted by sigma squared σ2
(sigma squared)
Where
x
= Data set valuesµ
= Mean valueN
= Total number of observationsLet’s have a look at an example that we considered for calculation of mean 3, 5, 7, 9, 11, 13, 15
.
The mean value in this case is (3 + 5 + 7 + 9 + 11 + 13 + 15 ) / 7 = 9
(3-9)^2 = 36, (5-9)^2 = 16, (7-9)^2 = 4, (9-9)^2 = 0, (11-9)^2 = 4, (13-9)^2 = 16, (15-9)^2 = 36
(36 + 16 + 4 + 0 + 4 + 16 + 36 ) / 7 = 16
. Hence the variance in this example is 16
.R provides an in-built function var()
to compute the variance of all data values in the dataset with respect to the mean. The function takes numeric or integer vector as an argument and returns the result.
x
is a variable that takes the integer vectors using c()
functionvar(x)
is displayed using print
In the next section we’ll look at Standard Deviation
Help us improve this content by editing this page on GitHub