source('utils.R') source('http://waxworksmath.com/Authors/A_F/Devore/Code/Chapter15/kruskal_wallis_test.R') # Section 4; Question 1: # source('../Chapter8/chap_8_sect_2_question_7_data.R') res = kruskal_wallis_test( DF, 'group_number', 'iq_change', check_sample_sizes=FALSE, debugging=FALSE ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Section 4; Question 2: # source('../Chapter9/chap_9_sect_5_question_2_data.R') res = kruskal_wallis_test( DF, 'With_Domes', 'Percent_Time', check_sample_sizes=FALSE, debugging=FALSE ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Section 4; Question 3: # source('../Chapter9/chap_9_sect_2_question_8_data.R') res = kruskal_wallis_test( DF, 'Sex', 'Halflife' ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Section 4; Question 4: # source('../Chapter9/case_study_9_2_1_data.R') res = kruskal_wallis_test( DF, 'author', 'prop' ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Section 4; Question 5: # source('../Chapter12/case_study_12_2_1_data.R') res = kruskal_wallis_test( DF, 'smoker_type', 'value' ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Section 4; Question 6: # source('chap_14_sect_4_question_6_data.R') library(reshape2) DF_melt = melt(DF, id.vars=c(), variable.name='Plant', value.name='Value') # Part (a): # res = kruskal_wallis_test( DF_melt, 'Plant', 'Value' ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Part (b): # DF$Plant = as.factor( DF$Plant ) am = aov( Value ~ Plant, data=DF_melt ) summary(am) # Part (c): # row_of_interest = DF_melt$Value == 2246 DF_melt[ row_of_interest, 'Value'] = 1500 res = kruskal_wallis_test( DF_melt, 'Plant', 'Value' ) print( sprintf( '2246 => 1500: B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) ) # Part (d): # am = aov( Value ~ Plant, data=DF_melt ) summary(am) # Section 4; Question 7: # source('chap_14_sect_4_question_7_data.R') library(reshape2) DF_melt = melt(DF, id.vars=c(), variable.name='Type', value.name='Value') res = kruskal_wallis_test( DF_melt, 'Type', 'Value' ) print( sprintf( 'B= %.3f; B_crit= %.3f; p_value= %.6f', res$K, res$k_crit, res$p_value ) )