## R Lab Session 2, 10/3/08 ## ## Review: Boxplots some.data <- c(13,10,7,7,12,13,12.5,7,11,11,13,13,12,13,10,12,13,8,11.5,12,11.5,14,5.5) boxplot(some.data, ylab="Homework Scores", main="Boxplot of Homework Scores") ## Review: Normal probabilities # ACT Test; Mean = 21.0, SD = 4.7 [range: 1-36] # Probability of scoring between 25 and 32? pnorm(25, mean=21, sd=4.7) - pnorm(32, mean=21, sd=4.7, lower.tail=F) pnorm(25, mean=21, sd=4.7) - pnorm(-((32-21)/4.7), mean=0, sd=1) # Probability of scoring over 30? pnorm(30, mean=21, sd=4.7, lower.tail=F) pnorm(-((30-21)/4.7), mean=0, sd=1) # Probability of scoring either below 17 or above 33? pnorm(17, mean=21, sd=4.7) + pnorm(33, mean=21, sd=4.7, lower.tail=F) pnorm(17, mean=21, sd=4.7) + pnorm(-((33-21)/4.7), mean=0, sd=1) ## Independent Events # Coin Toss, 3 heads in a row? 0.5 * 0.5 * 0.5 ## Box Models # SAT => +1 point for getting a question right; -1/4 point for getting a question wrong (or fail to answer*). Multiple choice questions have 4 answers, one of which is right. 100 questions. EV? SE of EV? Pr(>= 10 questions right)? box.input <- c(1, rep(-0.25, 3)) draws <- 100 G <- 10000 holder <- rep(NA, G) for(g in 1:G){ holder[g] <- sum(sample(box.input, draws, replace=T)) } mean(holder) sd(holder) sum(holder >= 10)/G (1 + (-0.25*3))/4 = 0.0625 0.0625 * 100 = 6.25 sqrt((1^2 + 3*((-0.25)^2))/4) * sqrt(100) = 5.45