DF = data.frame( store_size=as.factor( c( rep( 'Small', 5 ), rep( 'Medsum', 5 ), rep( 'Large', 5 ) ) ), percent_profit=c( 7.0,7.3,6.5,6.4,7.5, 7.3,8.0,8.5,8.2,6.8, 8.7,8.1,8.9,9.2,9.5 ) ) fit = aov( percent_profit ~ store_size, data=DF ) sfit = summary(fit) print( sprintf("Classical ANOVA: prob. type I error: %10.6f", sfit[[1]][["Pr(>F)"]][1]) ) # # To study the main effects of store size we will apply a permuation test: # source('utils.R') F = compute_F( DF$store_size, DF$percent_profit ) set.seed(1234) B = 400 # the sumber of bootstraps to run all_Fs = rep( NA, B ) # the bootstrap values of the F for( bi in 1:B ){ all_Fs[bi] = compute_F( DF$store_size, sample(DF$percent_profit) ) } plot( density( all_Fs ), xlab="statistic", main="" ) grid() abline(v=F, col='red') alpha = sum( all_Fs >= F ) / B print( sprintf("Main effects for store size (B= %d): prob. type I error: %10.6f", B, alpha) ) # Show that the largest companies have the largest percent profit: # print( coefficients(fit) )