Problem Set # 3

William “Luke” Tabbert

date()
## [1] "Thu Oct 18 23:55:31 2012"

Due Date: October 18, 2012
Total Points: 38

1 The use of a cell phone while driving is hypothosized to increase the chance of an accident. The data set reaction.time (UsingR) is simulated data on the time it takes to react to an external event while driving. Subjects with control=C are not using a cell phone, and those with control=T are. The time to respond to some external event is recorded in seconds.
a) Perform a t-test on the difference in mean reaction time for groups T and C. What do you conclude. (2)

require("UsingR")
## Loading required package: UsingR
## Loading required package: MASS
mean_time = mean(reaction.time$time)
temp = split(reaction.time, reaction.time$control)
C = temp$C
T = temp$T
t.test(C$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  C$time 
## t = -1.661, df = 19, p-value = 0.1132
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.343 1.437 
## sample estimates:
## mean of x 
##      1.39 
## 
t.test(T$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  T$time 
## t = 1.58, df = 39, p-value = 0.1221
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.422 1.469 
## sample estimates:
## mean of x 
##     1.446 
## 

CONCLUSION: People who are not using a cell phone are less likely to get into a car accident.

b) Repeat the test separately for women and men. What do you conclude? (4)

require("UsingR")
mean_time = mean(reaction.time$time)
temp = split(reaction.time, reaction.time$gender)
M = temp$M
F = temp$F
t.test(M$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  M$time 
## t = -0.8762, df = 29, p-value = 0.3881
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.378 1.446 
## sample estimates:
## mean of x 
##     1.412 
## 
t.test(F$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  F$time 
## t = 0.9658, df = 29, p-value = 0.3421
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.411 1.472 
## sample estimates:
## mean of x 
##     1.441 
## 

CONCLUSION: Men are less likely to get into a car accident.

c) Repeat the test separately for the two age groups. What do you conclude? (4)

require("UsingR")
mean_time = mean(reaction.time$time)
temp = split(reaction.time, reaction.time$age)
young = temp$`16-24`
old = temp$`25+`
t.test(young$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  young$time 
## t = -2.982, df = 19, p-value = 0.007668
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.351 1.414 
## sample estimates:
## mean of x 
##     1.383 
## 
t.test(old$time, mu = mean_time)
## 
##  One Sample t-test
## 
## data:  old$time 
## t = 1.578, df = 39, p-value = 0.1227
## alternative hypothesis: true mean is not equal to 1.427 
## 95 percent confidence interval:
##  1.421 1.477 
## sample estimates:
## mean of x 
##     1.449 
## 

CONCLUSION: Younger people are less likely to get into a car accident.

2 The data set diamond (UsingR) contains data about the price of 48 diamond rings. The variable price records the price in Singapore dollars and the variable carat records the size of the diamond and you are interested in predicting price from carat size.
a) Make a scatter plot of carat versus price. (2)

require("UsingR")
plot(diamond, main = "Diamond Values", xlab = "Carat", ylab = "Price")

plot of chunk unnamed-chunk-5

b) Add a linear regression line to the plot. (2)

require("ggplot2")
## Loading required package: ggplot2
## Attaching package: 'ggplot2'
## The following object(s) are masked from 'package:UsingR':
## 
## movies
require("UsingR")
ggplot(diamond, aes(x = carat, y = price)) + geom_line() + xlab("Carat") + ylab("Price")

plot of chunk unnamed-chunk-6

c) Use the model to predict the amount a 1/3 carat diamond ring would cost. (4)

3 The data set trees contains the girth (inches), height (feet) and volume of timber from 31 felled Black Cherry trees. Suppose you want to predict the volume of timber from a measure of girth.
a) Create a scatter plot of the data and label the axes. (4)

require("ggplot2")
require("UsingR")
ggplot(trees, aes(x = Girth, y = Height)) + xlab("Girth") + ylab("Height")
## Error: No layers in plot

b) Add a linear regression line to the plot. (2)

require("ggplot2")
require("UsingR")
ggplot(trees, aes(x = Girth, y = Height)) + geom_line() + xlab("Girth") + ylab("Height")

plot of chunk unnamed-chunk-8

c) Determine the sum of squared residuals? (4)
d) Repeat a, b, and c but use the square of the girth instead of girth as the explanatory variable. Which model do you prefer and why? (10)