# Section 2; Question 1 (EPage 661): # source('../Chapter8/chap_8_sect_2_question_9_data.R') n = dim(DF)[1] mu0_tilde = 9 k = sum( DF$Number > mu0_tilde ) p_value = sum( c( dbinom( 0:(n-k), n, 0.5 ), dbinom( k:n, n, 0.5 ) ) ) print( sprintf( 'k= %d; p_value= %10.6f', k, p_value ) ) # Section 2; Question 2 (EPage 662): # source('../Chapter8/chap_8_sect_2_question_12_data.R') n = dim(DF)[1] mu0_tilde = 0.12 k = sum( DF$Chirp_Length > mu0_tilde ) exact_prob = sum( dbinom( 0:k, n, 0.5 ) ) z = ( k - n/2 )/sqrt( n/4 ) norm_approx = pnorm( z ) print( sprintf( 'exact_prob= %.6f; norm_approx= %.6f', exact_prob, norm_approx ) ) # Section 2; Question 3: # source('chap_14_sect_2_question_3_data.R') mu0_tilde = log(2) n = length(data) k = sum( data > mu0_tilde ) z = ( k - n/2 )/sqrt( n/4 ) p_value = pnorm(z) + ( 1 - pnorm(-z) ) print( sprintf( 'p_value= %.6f', p_value ) ) # Section 2; Question 4: # n = 22 sigma2 = 6.0 z_alpha = -qnorm( 0.05 ) x_crit = sqrt(n/4) * z_alpha + n/2 p_alt = 1 - pnorm( 10, mean=11, sd=sqrt(6) ) 1 - pbinom( floor(x_crit), n, p_alt ) # Section 2; Question 5: # n = 7 dbinom( 0:n, n, 1/2 ) ts = 0:n alphas = 1 - pbinom( ts, n, 1/2 ) # check vs. the back of the book: db = c( 1, 7, 21, 35, 35, 21, 7, 1 )/128 cumsum( db ) # Section 2; Question 6: # source('../Chapter7/case_study_7_4_2_data.R') golden_ratio = ( sqrt(5) - 1 ) / 2 k = sum( data > golden_ratio ) n = length(data) z = ( k - n/2 ) / sqrt( n/4 ) p_value = pnorm( -z ) + ( 1 - pnorm( z ) ) print( sprintf( 'p_value= %.6f', p_value ) ) # Section 2; Question 7: # source('../Chapter5/chap_5_sect_3_question_2_data.R') n = dim(DF)[1] k = sum( DF$Ratio > 0.8 ) z = ( k - n/2 ) / sqrt( n/4 ) p_value = pnorm( z ) print( sprintf( 'large sample sign test p_value= %.6f', p_value ) ) print( t.test( DF$Ratio, mu=0.8, alternative=c("less"), conf.level=0.90 ) ) # Section 2; Question 8: # source('../Chapter13/chap_13_sect_2_question_1_data.R') k = sum( DF$hypnotic > DF$waking ) n = dim(DF)[1] z = ( k - n/2 )/sqrt( n/4 ) p_value = 1 - pnorm( z ) print( sprintf( 'p_value= %.6f', p_value ) ) # Section 2; Question 9: n = 28 k = 19 z = ( k - n/2 )/sqrt( n/4 ) p_value = pnorm( -z ) + ( 1 - pnorm( z ) ) print( sprintf( 'p_value= %.6f', p_value ) ) # Section 2; Question 10: # t = 6 theta = t/0.25 n = 36 n * 0.25 n * 0.25 * (1-0.25) y_plus_values = 0:n prob_y_plus_values = dbinom( y_plus_values, n, 22/28 ) z_values = ( y_plus_values - 9 ) / sqrt( 6.75 ) z_alpha = -qnorm( 0.05 ) dont_reject_null = abs( z_values ) < z_alpha prob_type_II_error = sum( prob_y_plus_values[dont_reject_null] ) print( sprintf( 'p_value= %.6f', prob_type_II_error ) ) # Section 2; Question 11: # source('../Chapter13/case_study_13_3_1_data.R') n = dim(DF)[1] k = sum( DF$After > DF$Before ) p_value = sum( c( dbinom( 0:k, n, 0.5 ), dbinom( (n-k):n, n, 0.5 ) ) ) print( sprintf( 'k= %d; p_value= %.6f', k, p_value ) )