library(reshape2) source('utils.R') source('http://waxworksmath.com/Authors/A_F/Devore/Code/Chapter15/friedmans_test.R') # Section 5; Question 1: # source('chap_14_sect_5_question_1_data.R') res = friedmans_test( DF, 'Block', 'Treatment', 'Strength' ) print( sprintf( 'g= %.3f; g_crit= %.3f; p_value= %.6f', res$Fr, res$f_crit, res$p_value ) ) # Section 5; Question 2: # source('../Chapter13/case_study_13_2_3_data.R') DF_melt = melt(DF, id.vars='month', variable.name='time', value.name='value') res = friedmans_test( DF_melt, 'month', 'time', 'value' ) print( sprintf( 'g= %.3f; g_crit= %.3f; p_value= %.6f', res$Fr, res$f_crit, res$p_value ) ) # Section 5; Question 3: # source('chap_14_sect_5_question_3_data.R') DF$Sample = 1:dim(DF)[1] DF_melt = melt(DF, id.vars='Sample', variable.name='method', value.name='value') res = friedmans_test( DF_melt, 'Sample', 'method', 'value' ) print( sprintf( 'g= %.3f; g_crit= %.3f; p_value: %.6f', res$Fr, res$f_crit, res$p_value )) # Section 5; Question 4: # source('../Chapter8/chap_8_sect_2_question_4_data.R') DF$Group = 1:dim(DF)[1] DF_melt = melt(DF, id.vars='Group', variable.name='density', value.name='number_of_encounters') res = friedmans_test( DF_melt, 'Group', 'density', 'number_of_encounters' ) print( sprintf( 'g= %.3f; g_crit= %.3f; p_value= %.6f', res$Fr, res$f_crit, res$p_value )) # with ANOVA: # DF_melt$Group = as.factor( DF_melt$Group ) # both of these variables are factors DF_melt$density = as.factor( DF_melt$density ) m = aov( number_of_encounters ~ Group + density, data=DF_melt ) print( summary(m) ) # Section 5; Question 5; # source('../Chapter13/case_study_13_2_1_data.R') DF_melt = melt(DF, id.vars='Block', variable.name='method', value.name='score_change') res = friedmans_test( DF_melt, 'Block', 'method', 'score_change', alpha=0.01 ) print( sprintf( 'g= %.3f; g_crit= %.3f; p_value= %.6f', res$Fr, res$f_crit, res$p_value ) ) # with ANOVA: # DF_melt$method = as.factor( DF_melt$method ) m = aov( score_change ~ Block + method, data=DF_melt ) print( summary(m) )