On this page we look at creating a

For populations that are approximately

We can walk through an example here. Let us say that for an apparently normal population we have a sample of size

lval <- qchisq(0.025,33) lval rval <- qchisq(0.025, 33, lower.tail=FALSE) rval s<-4.71 s sqrt(33*s*s/rval) sqrt(33*s*s/lval)The console view of those commands is shown in Figure 1.

Thus, the

This model can be used to do any other problem. For example, to find the

lval <- qchisq(0.05,15) lval rval <- qchisq(0.05, 15, lower.tail=FALSE) rval s<-1.388 s sqrt(15*s*s/rval) sqrt(15*s*s/lval)The console view of those commands is shown in Figure 2.

Thus, the

Considering that we are doing the same steps every time we find a problem asking for the confidence interval for the population mean based on a sample standard deviation, this looks like a perfect time to create a function to do these steps for us. Here is the text of such a function.

ci_stddev <- function( n=30, s=0, cl=0.95) { # try to avoid some common errors if( cl <=0 | cl>=1) {return("Confidence interval must be strictly between 0.0 and 1") } if( s <= 0 ) {return("Sample standard deviation must be positive")} if( n <= 1 ) {return("Sample size needs to be more than 1")} if( as.integer(n) != n ) {return("Sample size must be a whole number")} # to get here we have some "reasonable" values alpha = (1-cl)/2 # area at each side lval <- qchisq(alpha,n-1) rval <- qchisq(alpha,n-1,lower.tail=FALSE) low_end <- sqrt((n-1)*s*s/rval) high_end <- sqrt((n-1)*s*s/lval) result <- c(low_end, high_end, n-1, lval, rval) names(result)<-c("CI Low","CI High","deg. of freedom","left chisq", "right chisq") return( result ) }The function is also available in the file ci_stddev.R. Figure 3 shows two instances of the new function, one for each of the problems that we solved above. Fortunately, we get the same results as before.

There is one more aspect of this confidence interval that is worth noting. Unlike the confidence intervals that we had for the population mean, these confidence intervals are not symmetric about the point estimate that we have. Thus, in the last example, the confidence interval was

One last, complete example may help. Consider the values in

We can create this same data in R and find both the

Now that we know those three values we could construct a 90% confidence interval for the population mean. We can do this in a step by step approach or we can use the function that we created in an earlier page,

`ci_unknown()`

.
Assuming that we have "loaded" that function it seems to be the better approach.
Figure 5 shows the use of that function and the resulting values.
Our interpretation of the result is to say that we have a confidence interval of

We can use the same data to generate a

`ci_stddev()`

that we just developed.
Assuming that we have "loaded" that function it seems to be the better approach.
Figure 6 shows the use of that function and the resulting values.
Our interpretation of the result is to say that we have a confidence interval of

Just as we have seen in other confidence intervals, if we increase the confidence level, we get wider confidence interval. For example, Figure 7 shows the same computation but with the goal of producing a

R commands used in preparing this web page.

source("../gnrnd4.R") source("../ci_unknown.R") lval <- qchisq(0.025,33) lval rval <- qchisq(0.025, 33, lower.tail=FALSE) rval s<-4.71 s sqrt(33*s*s/rval) sqrt(33*s*s/lval) lval <- qchisq(0.05,15) lval rval <- qchisq(0.05, 15, lower.tail=FALSE) rval s<-1.388 s sqrt(15*s*s/rval) sqrt(15*s*s/lval) ci_stddev <- function( n=30, s=0, cl=0.95) { # try to avoid some common errors if( cl <=0 | cl>=1) {return("Confidence interval must be strictly between 0.0 and 1") } if( s <= 0 ) {return("Sample standard deviation must be positive")} if( n <= 1 ) {return("Sample size needs to be more than 1")} if( as.integer(n) != n ) {return("Sample size must be a whole number")} # to get here we have some "reasonable" values alpha = (1-cl)/2 # area at each side lval <- qchisq(alpha,n-1) rval <- qchisq(alpha,n-1,lower.tail=FALSE) low_end <- sqrt((n-1)*s*s/rval) high_end <- sqrt((n-1)*s*s/lval) result <- c(low_end, high_end, n-1, lval, rval) names(result)<-c("CI Low","CI High","deg. of freedom","left chisq", "right chisq") return( result ) } ci_stddev(34, 4.71, 0.95) ci_stddev(16, 1.388, 0.90) gnrnd4( key1=840848504, key2=0003500483 ) L1 mean(L1) sd(L1) length(L1) ci_unknown(s=34.5677, n=86, x_bar=480.0581, cl=0.90) ci_stddev(n=86, s=34.5677, cl=0.90) ci_stddev(n=86, s=34.5677, cl=0.95) ci_stddev(n=86, s=34.5677, cl=0.99)

©Roger M. Palay Saline, MI 48176 January, 2016