# Roger Palay copyright 2016-03-04 # Saline, MI 48176 # hypoth_2test_var <- function( n_top, s_top, n_bot, s_bot, H1_type, sig_level=0.05) { # perform a hypothsis test for equality of # the variances of two populations # based on two samples of n_top and n_not # items yielding sample # standard deviations s_top and s_bot # 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 <- "do not reject" v_top = s_top^2 v_bot = s_bot^2 quotient <- v_top / v_bot alpha <- sig_level if ( H1_type == 0 ) { alpha <- alpha/2 } #find the critical value(s) xlow <- qf(alpha,n_top-1,n_bot-1) xhigh <- qf( alpha, n_top-1, n_bot-1, lower.tail=FALSE) if( H1_type == 0 ) { if( (quotient < xlow) | (quotient>xhigh) ) { decision <- "Reject" } if (quotient < 1 ) { attained = 2*pf(quotient,n_top-1,n_bot-1)} else { attained = 2*pf(quotient, n_top-1, n_bot-1, lower.tail=FALSE) } H1 <- "v_1 != v_2" } else if( H1_type < 0 ) { if( quotient < xlow ) { decision <- "Reject" } attained = pf( quotient,n_top-1,n_bot-1) xhigh <- "n.a." H1 <- "v_1 < v_2" } else { if( quotient > xhigh ) { decision <- "Reject" } attained = pf( quotient,n_top-1, n_bot-1,lower.tail=FALSE) xlow <- "n.a." H1 <- "v_1 > v_2" } result <- c( H1, n_top, s_top, v_top, n_bot, s_bot, v_bot, quotient, xlow, xhigh, decision, attained ) names(result) <- c( "H1","n top", "s top", "v top", "n bot", "s bot", "v bot", "quotient", "crit low", "crit high", "decision", "attained") return (result) }