# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # # Computations used for the problems in this section of the text. # #----- source('utils.R') print( 'Ex 10.11:' ) I = 5 J = 4 MSE = 272.8 q_crit = qtukey( 1-0.05, I, I*(J-1) ) w = q_crit * sqrt( MSE / J ) xbars = c( 437.5, 462.0, 469.3, 512.8, 532.1 ) xbars = sort( xbars ) print( xbars ) print( diff( xbars ) ) print( 'Ex 10.12:' ) xbars = c( 427.5, 462.0, 469.3, 512.8, 532.1 ) xbars = sort( xbars ) print( xbars ) print( diff(xbars) ) print('Ex 10.13:') xbars = c( 427.5, 462.0, 469.3, 502.8, 532.1 ) xbars = sort( xbars ) print( xbars ) print( diff(xbars) ) print( 'Ex 10.14:' ) I = 4 J = 8 MSE = 1.056157 # calculated in the previous section q_crit = qtukey( 1-0.05, I, I*(J-1) ) w = q_crit * sqrt( MSE / J ) print(w) xbars = c( 4.39, 4.52, 5.49, 6.39 ) xbars = sort( xbars ) print( xbars ) print( diff(xbars) ) print( 'Ex 10.15:' ) DF = read.csv( "../../Data/CH10/ex10-06.txt", header=TRUE, quote="'" ) res = ANOVA( DF$FE, DF$Formation ) # compute the group means xbar_i_dot = res$x_i_dot / res$J xbar_i_dot = sort( xbar_i_dot ) print( xbar_i_dot ) print( diff( xbar_i_dot ) ) MSE = 15.64 # given in the exercise statement q_crit = qtukey( 1-0.01, I, I*(J-1) ) w = q_crit * sqrt( MSE / J ) print( w ) print( 'Ex 10.16:' ) I = 5 J = 7 q_crit = 4.10 MSE = 1049 w = q_crit * sqrt( MSE / J ) print( w ) xbars = c( 333.21, 368.06, 375.13, 407.36, 437.17 ) print( diff(xbars) ) print( 'Ex 10.17:' ) cs = c( 0.5, 0.5, -1 ) # stats on the data: xbars = c( 1.63, 1.56, 1.42 ) ss = c( 0.27, 0.24, 0.26 ) I = length(xbars) J = 10 MSE = sum( ss^2 ) / I m = sum( cs * xbars ) v = MSE * sum( cs^2 ) / J t_crit = qt( 1 - 0.05/2, I*(J-1) ) m + sqrt( v ) * t_crit * c(-1,+1) print( 'Ex 10.18:' ) DF = read.csv( "../../Data/CH10/ex10-18.txt", header=TRUE, quote="'" ) J = 4 DF$group = rep( 1:5, J ) res = ANOVA( DF$growth, DF$group ) print( res$p_value ) # Given the MSE compute the group means and the significant spacing w: # xbar_i_dot = res$x_i_dot / res$J xbar_i_dot = sort( xbar_i_dot ) print( xbar_i_dot ) print( diff( xbar_i_dot ) ) q_crit = qtukey( 1-0.05, res$I, res$I*(res$J-1) ) w = q_crit * sqrt( res$MSE / res$J ) print( w ) print( 'Ex 10.19:') I = 3 J = 5 xbars = c( 10, 12, 20 ) # the sample means x_dots = xbars * J # the sample sums x_dot_dot = sum(x_dots) SSTr = sum( x_dots^2 ) / J - x_dot_dot^2 / ( I * J ) MSTr = SSTr / (I-1) # # f = MSTr / MSE = I*(J-1)*MSTr / SSE # # Compute f critical: # f_crit = qf( 1-0.05, I-1, I*(J-1) ) # The largest value that the SSE can be: # SSE_max = I*(J-1)*MSTr / f_crit print( SSE_max ) # what does Tukey's w give? # q_crit = qtukey( 1-0.05, I, I*(J-1) ) print( ( 10 / q_crit )^2 * I * J * (J-1) ) print( 'Ex 10.20:') I = 3 J = 5 f_crit = qf( 1-0.05, I-1, I*(J-1) ) xbars = c( 10, 15, 20 ) x_dots = xbars * J # the sample sums x_dot_dot = sum(x_dots) SSTr = sum( x_dots^2 ) / J - x_dot_dot^2 / ( I * J ) MSTr = SSTr / (I-1) # The largest value that the SSE can be: # SSE_max = I*(J-1)*MSTr / f_crit print( SSE_max ) print( 'Ex 10.21:') I = 6 J = 14 xbars = c( 166, 303, 266, 212, 202, 184 ) ss = c( 32, 53, 54, 35, 34, 31 ) # Do an ANOVA test on this data (following the function ANOVA): # x_i_dot = xbars * J x_dot_dot = sum(x_i_dot) SSTr = sum( x_i_dot^2 ) / J - x_dot_dot^2 / ( I * J ) MSTr = SSTr / (I-1) MSE = sum( ss^2 ) / I f = MSTr / MSE p_value = 1 - pf( f, I-1, I*(J-1) ) # Fit simultaneous confidence intervals for the two sets of coefficients: # alpha = 0.01 t_crit = qt( 1-alpha/2, I*(J-1) ) cs_1 = c( 1, rep( -0.2, 5 ) ) cs_2 = c( 0, rep( 0.25, 4 ), -1 ) # The confidence interval for the FIRST set of coefficients: # m = sum( cs_1 * xbars ) v = MSE * sum( cs_1^2 ) / J print( "First CI" ) print( m + sqrt( v ) * t_crit * c(-1,+1) ) # The confidence interval for the SECOND set of coefficients: # m = sum( cs_2 * xbars ) v = MSE * sum( cs_2^2 ) / J print( "Second CI" ) print( m + sqrt( v ) * t_crit * c(-1,+1) )