# Problems on EPage 474 # # Section 3; Question 1: # large_sales = c( 21, 23, 13, 22, 7, 17, 19, 11, 2, 30, 15, 43 ) #=X small_sales = c( 21, 21, 14, 31, 19, 19, 11, 29, 20, 27, 27, 24 ) #=Y n = length( large_sales ) m = length( small_sales ) sx2 = var( large_sales ) sy2 = var( small_sales ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L=%.6f; f_crit_R= %.6f; f= %.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 2: # fixed = c( 5.5, 5.5, 5.25, 5.125, 5.875, 5.625, 5.25, 4.875 ) #=X arm = c( 3.875, 5.125, 5.0, 4.75, 4.375 ) #=Y n = length( fixed ) m = length( arm ) sx2 = var( fixed ) sy2 = var( arm ) f = sy2/sx2 alpha = 0.1 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f=%.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 3: # normal = c( 8, 4, 6, 3, 1, 4, 4, 6, 4, 2, 2, 1, 1, 4, 3, 3, 2, 6, 3, 4 ) schizophrenic = c( 2, 1, 1, 3, 2, 7, 2, 1, 3, 1, 0, 2, 4, 2, 3, 3, 0, 1, 2, 2 ) n = length( normal ) m = length( schizophrenic ) sx2 = var( normal ) sy2 = var( schizophrenic ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f=%.6f', alpha, f_crit_L, f_crit_R, f)) # Now test if mu_X = mu_Y: # xbar = mean( normal ) ybar = mean( schizophrenic ) sp2 = ( (n-1)*sx2 + (m-1)*sy2 ) / ( n+m-2 ) t = ( xbar - ybar )/sqrt( sp2*(1/n + 1/m) ) p_value = 2*(1-pt(abs(t), n+m-2)) # two-sided test alpha = 0.05 t_crit = qt( 1-alpha/2, n+m-2 ) print(sprintf('t= %.6f; p_value= %.6f; t_crit= %.6f', t, p_value, t_crit)) # Section 3; Question 4: # source('chap_9_sect_3_question_4_data.R') n = length( control ) m = length( test ) sx2 = var( control ) sy2 = var( test ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f=%.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 5: # source('chap_9_sect_3_question_5_data.R') n = length( normal ) m = length( raynauds ) sx2 = var( normal ) sy2 = var( raynauds ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f= %.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 6: # source('chap_9_sect_3_question_6_data.R') n = length( american ) m = length( national ) sx2 = var( american ) sy2 = var( national ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f= %.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 7: # source('chap_9_sect_2_question_8_data.R') X = DF[ DF$Sex=='F', ] n = dim(X)[1] sx2 = var(X$Halflife) Y = DF[ DF$Sex=='M', ] m = dim(Y)[1] sy2 = var(Y$Halflife) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f=%.6f', alpha, f_crit_L, f_crit_R, f)) # Section 3; Question 8: # source('chap_9_sect_3_question_8_data.R') n = length( african_american ) m = length( white ) sx2 = var( african_american ) sy2 = var( white ) f = sy2/sx2 alpha = 0.05 f_crit_L = qf( alpha/2, m-1, n-1 ) f_crit_R = qf( 1-alpha/2, m-1, n-1 ) print(sprintf('alpha= %.2f; f_crit_L= %.6f; f_crit_R= %.6f; f= %.6f', alpha, f_crit_L, f_crit_R, f))