# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- # Ex 7.47: # DF = read.csv( "../../Data/CH07/ex7-47.txt", header=TRUE, quote="'" ) X = DF$strength n = length(X) xbar = mean(X) s = sd(X) z_crit = qnorm( 1 - 0.05/2 ) xbar + ( s / sqrt(n) ) * z_crit * c(-1,+1) p_hat = sum( X > 10 ) / length(X) ci_population_proportion( p_hat, n, 0.05 ) # Ex 7.49: # DF = read.csv( "../../Data/CH07/ex7-49.txt", header=TRUE, quote="'" ) X = DF$Volume.. boxplot( X ) qqnorm( X ) qqline( X ) grid () n = length(X) m = mean(X) s = sd(X) t_crit = qt( 1 - 0.02/2, n-1 ) m + ( s / sqrt(n) ) * t_crit * c(-1,+1) # Ex 7.50: # ci = c( 229.764, 233.504 ) m = 0.5 * sum( ci ) t_crit = qt( 1 - 0.05/2, n-1 ) ci_std_partial = t_crit / sqrt(n) s = diff( ci ) / ( 2 * ci_std_partial ) t_crit = qt( 1 - 0.01/2, n-1 ) # the new CI critical value m + ( s / sqrt(n) ) * t_crit * c(-1,+1) # 7.51: # p_hat = 136/200 ci_population_proportion( p_hat, 200, 0.1 ) q_hat = 1 - p_hat w = 0.05 z_crit = qnorm( 1-0.1/2 ) ( 4 * z_crit^2 * p_hat * q_hat ) / ( w^2 ) # Ex 7.52 # n = 5 m = 24.3 s = 4.1 t_crit = qt( 1 - 0.05/2, n-1 ) m + ( s / sqrt(n) ) * t_crit * c(-1,+1) alpha = 0.1 sqrt( (n-1) * s^2 / qchisq( alpha, n-1 ) ) s_prediction = s * sqrt( 1 + 1/n ) t_crit = qt( 1 - 0.05/2, n-1 ) m + s_prediction * t_crit * c(-1,+1) # Ex 7.53: # theta_hat = (1/3) * ( 10.5 + 10.0 + 10.1 ) - 10.7 var_theta_hat = (1/9) * ( 1.5^2 / 100 + 1.3^2 / 90 + 1.8^2 / 100 ) + 1.6^2 / 120 alpha = 0.05 z_crit = qnorm( 1 - alpha/2 ) theta_hat + sqrt( var_theta_hat ) * z_crit * c(-1,+1) # Ex 7.54: # p_hat = 11/55 ci_population_proportion( p_hat, 55, 0.10 ) # Ex 7.55: # s = 0.8 z_crit = qnorm( 1 - 0.05/2 ) w = 0.2 ( 2*s*z_crit / w )^2 # Ex 7.56: # DF = read.csv( "../../Data/CH07/ex7-56.txt", header=TRUE, quote="'" ) X = DF$compliance qqnorm( X ) qqline( X ) grid() n = length(X) m = mean(X) s = sd(X) t_crit = qt( 1 - 0.05/2, n-1 ) m + ( s / sqrt(n) ) * t_crit * c(-1,+1) # Ex 7.57: # n = 20 data = c( 11, 15, 29, 33, 35, 40, 47, 55, 58, 72 ) r = length( data ) tr = sum( data ) + (n-r) * data[length(data)] alpha = 0.05 2 * tr / c( qchisq( 1 - alpha/2, 2*r ), qchisq( alpha/2, 2*r ) ) # Ex 7.58: # DF = read.csv( "../../Data/CH07/ex7-58.txt", header=TRUE, quote="'" ) X = DF$alanine n = length(X) range( X ) # Ex 7.59: # X = c( 4.2, 3.5, 1.7, 1.2, 2.4 ) n = length(X) y = max(X) alpha = 0.05 alpha_over_two = alpha / 2 ci_1 = c( y / ( ( 1 - alpha_over_two )^(1/n) ), y / ( alpha_over_two^(1/n) ) ) ci_2 = c( y, y / alpha^(1/n) ) # Ex 7.61: # DF = read.csv( "../../Data/CH07/ex7-45.txt", header=TRUE, quote="'" ) X = DF$toughness n = length(X) # the suggested robust CI: # conservative_t_crit = 1.94 # Compute the fourth spread: # tilde_mu = median(X) lower_fourth = median( X[ X<=tilde_mu ] ) upper_fourth = median( X[ X>=tilde_mu ] ) fs = upper_fourth - lower_fourth tilde_mu + ( conservative_t_crit / 1.075 ) * ( fs / sqrt(n) ) * c(-1,+1) # a standard t-based CI: # s = sd(X) alpha = 0.05 t_crit = qt( 1 - alpha/2, n-1 ) mean(X) + ( s / sqrt(n) ) * t_crit * c(-1,+1) # Ex 7.62: # X = c( 41.53, 18.73, 2.99, 30.34, 12.33, 117.52, 73.02, 223.63, 4.00, 26.78 ) n = length(X) alpha = 0.05 chisq_crit = qchisq( alpha, 2*n ) chisq_crit / ( 2*sum(X) ) chisq_crit = qchisq( 1-alpha, 2*n ) lamb = chisq_crit / ( 2*sum(X) ) exp( -lamb * (100) )