Open In App

How to Calculate Pooled Variance in R

Last Updated : 19 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss what is Pooled Variance in R and How to Calculate Pooled Variance in the R Programming Language.

What is Pooled Variance?

Pooled variance refers to the combined or weighted average of variances from two or more groups. It is used in comparing means from different groups, especially in independent samples.

When dealing with multiple groups with different variances, the pooled variance provides an accurate estimate of the overall variance than the individual variances. This is important in statistical tests like the t-test when assuming equal variances between groups.

Mathematically, The pooled variance is denoted as sp2 and is calculated as:

sp^2 = \frac{((n_1 - 1)s_1^2 + (n_2 - 1)s_2^2)}{(n_1 + n_2 - 2)}

For example, suppose we want to calculate the pooled variance between the following two groups:

DataSet 1

DataSet 2

10

12

20

19

21

22

23

24

24

22

25

25

27

26

28

27

29

25

The following code shows how to calculate the pooled variance between these groups in R:

Step 1: Define groups of data

y1 <- c(10,20,21,23,24,25,27,28,29)
y2 <- c(12,19,22,24,22,25,26,27,25)

Step 2: Calculate sample size of each group

length1 <- length(y1)
length2<- length(y2)

Step 3: Calculate sample variance of each group

variance1 <- var(y1)
variance2 <- var(y2)

Step 4: Calculate pooled variance between the two groups

pooled <- ((length1-1)*variance1 + (length2-1)*variance2) / (length1+length2-2)
R
#Step 1: Define groups of data
y1 <- c(10,20,21,23,24,25,27,28,29)
y2 <- c(12,19,22,24,22,25,26,27,25)

#Step 2: Calculate sample size of each group
length1 <- length(y1)
length2<- length(y2)

#Step 3: Calculate sample variance of each group
variance1 <- var(y1)
variance2 <- var(y2)

#Step 4: Calculate pooled variance between the two groups
pooled <- ((length1-1)*variance1 + (length2-1)*variance2) / (length1+length2-2)

#Step 5: Display pooled variance
pooled

Output:

 27.13889

Conclusion

In this article, we learnt about How to Calculate Pooled Variance in R.Pooled variance refers to the combined or weighted average of variances from two or more groups. It is used in comparing means from different groups, especially in independent samples.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads