# How to compute a confidence interval for the ratio of two population variances (in R)

## Task

Let’s say we want to compute a confidence interval for two population variances. We take two samples of data, $x_1, x_2, x_3, \ldots, x_k$ and $x’_1, x’_2, x’_3, \ldots, x’_k$, and compute their variances, $\sigma_1^2$ and $\sigma_2^2$. How do we compute a confidence interval for $\frac{\sigma_1^2}{\sigma_2^2}$?

Related tasks:

- How to compute a confidence interval for a mean difference (matched pairs)
- How to compute a confidence interval for a regression coefficient
- How to compute a confidence interval for a population mean
- How to compute a confidence interval for a single population variance
- How to compute a confidence interval for the difference between two means when both population variances are known
- How to compute a confidence interval for the difference between two means when population variances are unknown
- How to compute a confidence interval for the difference between two proportions
- How to compute a confidence interval for the expected value of a response variable
- How to compute a confidence interval for the population proportion

## Solution

We’ll use R’s dataset EuStockMarkets as an example; of course you should replace this example data with your actual data when using this code. This dataset has information on the daily closing prices of 4 European stock indices. We’re going to compare the variability of Germany’s DAX and France’s CAC closing prices here.

1
2
3
4
5
6
7
8
9

# install.packages("datasets") # if you have not done so already
library(datasets)
# Load in the EuStockMarkets data and convert to a DataFrame
EuStockMarkets <- data.frame(EuStockMarkets)
# Our two samples are its DAX and CAC columns
sample.1 <- EuStockMarkets$DAX
sample.2 <- EuStockMarkets$CAC

Now that we have our data loaded we can compute the confidence interval. You can change the confidence level by changing the value of $\alpha$ below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# The degrees of freedom in each sample is its length minus 1
df_1 = length(sample.1) - 1
df_2 = length(sample.2) - 1
# Compute the ratio of the variances
test.stat.ratio <- var(sample.1)/var(sample.2)
# Find the critical values from the F-distribution
alpha <- 0.05 # replace with your chosen alpha (here, a 95% confidence level)
lower_critical_value <- 1 / qf(p = alpha/2, df1 = df_1, df2 = df_2, lower.tail = FALSE)
upper_critical_value <- qf(p = alpha/2, df1 = df_2, df2 = df_1, lower.tail = FALSE)
# Compute the confidence interval and print it out
lower_bound <- test.stat.ratio*lower_critical_value
upper_bound <- test.stat.ratio*upper_critical_value
lower_bound
upper_bound

1
2
3
4
5

[1] 3.190589
[1] 3.827044

The 95% confidence interval for the ratio of the variances for Germany’s DAX and France’s CAC is $[3.191, 3.827]$.

Content last modified on 24 July 2023.

See a problem? Tell us or edit the source.

Contributed by Elizabeth Czarniak (CZARNIA_ELIZ@bentley.edu)