22S:166 Solutions to practice problems for the final exam 1. Courses file Course id (unique primary key) Course number Course section Course semester Textbook file Textbook ISBN (unique primary key) Title First author Publisher Copyright date Selling price Linking file Course id Textbook ISBN Note: both of these fields are foreign keys. Together they make up the primary key for the linking file. 2a. > y <- rbinom( 1, 16, 0.5) > y [1] 9 2b. > binom.test(y,16) Exact binomial test data: y and 16 number of successes = 9, number of trials = 16, p-value = 0.8036 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.2987769 0.8024659 sample estimates: probability of success 0.5625 2c. > binom.test(y,16)$p.value [1] 0.8036194 We cannot reject the null hypothesis that p = 0.5 at the .05 significance level, because the p-value is 0.804, which is larger than .05. --------------------------------------------------------------------------- 2d. > binom.simstudy function(reps, sampsize) { # reps: number of replicate samples # sampsize: sample size of each sample y <- rbinom(reps, sampsize, 0.5) p.values <- matrix(0,nrow=reps, ncol=3) for(i in 1:reps) { p.values[i,1] <- binom.test(y[i],sampsize, p=0.5)$p.value p.values[i,2] <- prop.test(y[i],16,p=0.5, correct=T)$p.value p.values[i,3] <- prop.test(y[i],16,p=0.5,correct=F)$p.value } reject <- matrix( p.values < 0.05, nrow=reps) results <- matrix(apply(reject,2,mean),nrow=1) results <- rbind( results, sqrt(results * (1-results)/reps) ) dimnames(results) <- list(c("size","std err"), c("binom.test","prop.test, Yates corr","prop.test, no correction")) results } ----------------------------------------------------------------------------- > binom.simstudy(20000,16) binom.test prop.test, Yates corr prop.test, no correction size 0.0200000000 0.0200000000 0.075000000 std err 0.0009899495 0.0009899495 0.001862458