# Section 3; Question 1: # sigma = 15 n = 50 y_bar = 107.9 z_crit = qnorm( 1 - 0.05/2 ) print( y_bar + sigma/sqrt(n) * z_crit * c(-1,+1) ) # Section 3; Question 2: # source('chap_5_sect_3_question_2_data.R') x_bar = mean( DF$Ratio ) n = dim(DF)[1] sigma = 0.09 z_crit = qnorm( 1 - 0.05/2 ) print( x_bar + sigma/sqrt(n) * z_crit * c(-1,+1) ) # Section 3: Question 3: # data = c( 52, 69, 73, 88, 87, 56 ) sigma = 8 n = length(data) x_bar = mean(data) z_crit = qnorm( 1 - 0.05/2 ) print( x_bar + sigma/sqrt(n) * z_crit * c(-1,+1) ) # Section 3: Question 4: # n = 38 x_bar = 188.4 sigma = 40.7 z_crit = qnorm( 1 - 0.05/2 ) print( x_bar + sigma/sqrt(n) * z_crit * c(-1,+1) ) # Section 3: Question 5: # sigma = 14.3 alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) print( ( 2 * z_crit * sigma / 3.06 )^2 ) # Section 3: Question 6: # z_left = c( -1.64, -10, -1.64 ) z_right = c( 2.33, 2.58, 0 ) print( round( pnorm( z_right ) - pnorm( z_left ), 2 ) ) # Section 3: Question 7: # p = pnorm( 1.06 ) - pnorm( -0.96 ) print( sum( dbinom( 4:5, 5, p ) ) ) # Section 3: Question 9: # data = c( 2.5, 3.2, 0.5, 0.4, 0.3, 0.1, 0.1, 0.2, 7.4, 8.6, 0.2, 0.1, 0.4, 1.8, 0.3, 1.3, 1.4, 11.2, 2.1, 10.1 ) print( c( length(data), mean(data) ) ) hist( data ) # note that this data is not normal looking # Section 3: Question 10: # n = 540 p_hat = 192/n alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) print( p_hat + z_crit * s * c( -1, +1 ) ) # Section 3: Question 11: # n = 1015 p_hat = 281/n alpha = 0.1 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) print( p_hat + z_crit * s * c( -1, +1 ) ) # Section 3: Question 12: # n = 100 p_hat = 54/n alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) print( p_hat + z_crit * s * c( -1, +1 ) ) # Section 3: Question 13: # n = 2253 p_hat = 0.63 alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) print( p_hat + z_crit * s * c( -1, +1 ) ) # Section 3: Question 14: # int = c( 0.57, 0.63 ) p_hat = mean( int ) print( p_hat ) alpha = 1-0.5 z_crit = qnorm( 1 - alpha/2 ) print( z_crit ) print( 1 / ( (diff( int )/(2*z_crit))^2 / (p_hat * (1-p_hat)) ) ) # Section 3: Question 15: # alpha = 0.01 z_crit = qnorm( 1 - alpha/2 ) print( 1 / ( 4 * ( 0.02/(2*z_crit) )^2 ) ) # Section 3: Question 16: # n = 14000 ps = seq( 0.52, 0.6, length.out=500 ) lhs = rep( NA, length(ps) ) for( ii in 1:length(ps) ){ lhs[ii] = sum( dbinom( 8088:14000, n, ps[ii] ) ) } plot( ps, lhs, type='l' ) abline(h=0.2, col='red') grid() mi = which.min(abs(lhs-0.2)) print( c(lhs[mi], ps[mi]) ) # Section 3: Question 17: # print( pnorm( 0.67 ) - pnorm( -0.67 ) ) # area covered by the first interval print( 1 - pnorm( 0 ) ) # area covered by the second interval # Section 3: Question 19: # n = 998 p_hat = 0.59 d = 1.96/(2*sqrt(n)) print(sprintf('d= %f', d)) alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) print( p_hat + z_crit * s * c( -1, +1 ) ) # Section 3: Question 20: # n = 202 p_hat = 86/n d = 1.96/(2*sqrt(n)) print(sprintf('p_hat= %f; d= %f', p_hat, d)) # Section 3: Question 22: # n = 350 p_hat = 126/n alpha = 0.1 z_crit = qnorm( 1 - alpha/2 ) s = sqrt( p_hat * ( 1 - p_hat ) / n ) ci = p_hat + z_crit * s * c( -1, +1 ) print(sprintf('ci Part (a): (%f, %f)', ci[1], ci[2])) N = 3000 s = sqrt( p_hat * ( 1 - p_hat ) / n ) * sqrt( (N-n)/(N-1) ) ci = p_hat + z_crit * s * c( -1, +1 ) print(sprintf('ci Part (b): (%f, %f)', ci[1], ci[2])) # Section 3: Question 23: # d = 0.06 n = 1/( (2*(d/1.96))^2 ) print(n) print(4*n) # Section 3: Question 25: # alpha_1 = 0.04 d_1 = 0.05 z_crit = qnorm( 1 - alpha_1/2 ) n_1 = z_crit^2 / (4*d_1^2) alpha_2 = 0.08 d_2 = 0.04 z_crit = qnorm( 1 - alpha_2/2 ) n_2 = z_crit^2 / (4*d_2^2) print( c( n_1, n_2 ) ) # Section 3: Question 26: # B = 0.4*0.6 alpha = 0.01 z_crit = qnorm( 1 - alpha/2 ) d = 0.05 print( ((z_crit^2)*B)/(d^2) ) # Section 3: Question 27: # alpha = 0.2 d = 0.02 z_crit = qnorm( 1 - alpha/2 ) n = z_crit^2 / (4*d^2) print( n ) # Section 3: Question 28: # alpha = 0.15 d = 0.03 z_crit = qnorm( 1 - alpha/2 ) n = z_crit^2 / (4*d^2) print( n ) B = 0.09 # using the known bound on B we get n = ((z_crit^2)*B)/ d^2 print( n )