Suppose we want to construct a 90% confidence interval for the population variance and standard deviation of the price of a 6-year-old Chevy. First, import or type your data set. Table 4 has been typed into R.
price <- c(41844, 36995, 41995, 36995, 41500, 40990, 38900, 43995, 39995, 37995, 42995, 35950)
Now, let’s construct the confidence interval for the variance. To do so, we write our own function.
conf_int_var <- function(data,confidence) {
df <- length(price) - 1 #Compute the degrees of freedom
variance <- var(price) #Compute the variance
lower <- variance*df/qchisq((1-confidence)/2,df,lower.tail=FALSE) #Determine lower bound
upper <- variance*df/qchisq(confidence+(1-confidence)/2,df,lower.tail=FALSE) #Determine upper bound
c(lower=lower, upper = upper)
}
Now, we may call the function conf_int_var where the arguments are the data and level of confidence.
conf_int_var(data=price, confidence=0.90) #Construct a 90% confidence interval for the variance
## lower upper
## 3823671 16444663
Now, let’s find the confidence interval for the standard deviation.
conf_int_sigma <- function(data,confidence) {
df <- length(price) - 1 #Compute the degrees of freedom
variance <- var(price) #Compute the variance
lower <- variance*df/qchisq((1-confidence)/2,df,lower.tail=FALSE) #Determine lower bound
upper <- variance*df/qchisq(confidence+(1-confidence)/2,df,lower.tail=FALSE) #Determine upper bound
c(lower=sqrt(lower), upper = sqrt(upper))
}
Now, we call the function conf_int_sigma.
conf_int_sigma(data=price,confidence=0.9)
## lower upper
## 1955.421 4055.202
If you have summarized data, then enter them as specific values following df <- and variance <- var(data).