# Roger Palay copyright 2016-02-08 # Saline, MI 48176 # hypoth_test_sigma <- function( H0_sigma, n, samp_sigma, H1_type, sig_level=0.05) { # perform a hypothsis test for the population # standard deviation=H0_sigma # based on a sample of n items yielding a # sample standard deviation, samp_sigma, # where the alternative hypothesis is # != if H1_type==0 # < if H1_type < 0 # > if H1_type > 0 # Do the test at sig_level significance, # # It is important that the population is a normal # distribution. decision <- "Reject" x2 <- (n-1)*(samp_sigma^2)/(H0_sigma^2) if( H1_type < 0 ) { crit_low <- qchisq( sig_level, n-1 ) crit_high <- "n.a." if( x2 > crit_low ) { decision <- "Do Not Reject" } attained <- pchisq( x2, n-1 ) alt <- paste("sigma < ", H0_sigma) } else if( H1_type > 0 ) { crit_high <- qchisq( sig_level, n-1, lower.tail=FALSE ) crit_low <- "n.a." if( x2 < crit_high ) { decision <- "Do Not Reject" } attained <- pchisq( x2, n-1, lower.tail=FALSE ) alt <- paste("sigma > ", H0_sigma) } else { crit_low <- qchisq( sig_level/2, n-1 ) crit_high <- qchisq( sig_level/2, n-1, lower.tail=FALSE ) if (x2 >crit_low & x2 < crit_high ) { decision <- "Do Not Reject" } if( samp_sigma < H0_sigma ) { attained =2*pchisq( x2, n-1 ) } else { attained =2*pchisq( x2, n-1, lower.tail=FALSE ) } alt <- paste("sigma != ", H0_sigma) } result <- c(H0_sigma, n, samp_sigma, alt, sig_level, crit_low, crit_high, x2, attained, decision) names(result) <- c("H0_sigma","Sample Size", "Samp Sigma", "H1", "sig level", "crit low","crit high","chi2 val", "attained","Decision") return( result ) }