Stat 401B Fall 2015 Lab #6 (Due October 15)

advertisement
Stat 401B Fall 2015 Lab #6 (Due October 15)
There is an R code set at the end of this lab and posted on the course web page that will prove useful
for doing this lab. Use it in doing the following.
1. Return to the class "Depth of Cut" data set and example. Now treat "pulses" as a quantitative
variable and consider analysis based on an approximately linear relationship
depth ≈ β 0 + β1 pulses
a) Use R to make a plot with sample means for 100, 500, and 1000 pulses plotted against number of
pulses. Connect the consecutive (in terms of number of pulses) plotted points with line segments.
Then add the 12 data pairs to the plot. How "linear" does the plot appear to be?
b) Evaluate the sample correlation between the pulses and depth variables.
c) Add the least squares line to the plot in a).
d) Use the lm() to get details of the least squares fit. What is the value of the coefficient of
determination ( R 2 ) here?
2. Do Exercise 4, page 140 of Vardeman and Jobe. Use R to do the plotting and calculations for this
problem. In addition to what is requested in the problem, also make a plot of the data on the original
(not logged) scales with a fitted version of Taylor's equation for tool life plotted on the same graph.
(Use your linear fitting on the log scales to get the coefficients for the equation.)
1
Code Set for Stat 401B Laboratory #6
#Here is some R code for the class "Depth of Cut" example
#First is code from Lab 5 ignoring the quantitative nature of the
factor "pulses"
pulses<-c(rep("A(100)",4),rep("B(500)",4),rep("C(1000)",4))
depth<-c(7.4,8.6,5.6,8.0,24.2,29.5,26.5,23.8,33.4,37.5,35.9,34.8)
Depth<-data.frame(depth,pulses)
Depth
plot(depth ~ pulses,data=Depth)
plot(as.factor(pulses),depth)
summary(Depth)
aggregate(Depth$depth,by=list(Depth$pulses),mean)
aggregate(Depth$depth,by=list(Depth$pulses),sd)
depth.aov<-aov(depth ~ pulses,data=Depth)
summary(depth.aov)
#Now some code making use of the quantitative nature of the factor
pulses and a straight line
#model for how mean depth of cut changes with number of pulses
npulses<-c(rep(100,4),rep(500,4),rep(1000,4))
plot(npulses,depth,xlim=c(0,1100),ylim=c(0,40))
nDepth<-data.frame(npulses,depth)
cor(nDepth)
2
plot(c(100,500,1000),c(7.4,26.0,34.8),type="l",xlim=c(0,1100),ylim=c
(0,40))
points(npulses,depth,xlim=c(0,1100),ylim=c(0,40))
abline(lm(depth~npulses),xlim=c(0,1100),ylim=c(0,40))
lm.out1<-lm(depth~npulses)
lm.out1
summary(lm.out1)
aov(lm.out1)
plot(lm.out1)
#Here is some code for Exercise 4 of Section 4.1 Vardeman and Jobe
page 140
speed<-c(rep(800,4),rep(700,4),rep(600,4),rep(500,4),rep(400,4))
life<c(1.00,.90,.74,.66,1.00,1.20,1.50,1.60,2.35,2.65,3.00,3.60,6.40,7.80
,9.80,16.50,21.50,24.50,26.00,33.00)
plot(speed,life)
plot(log(speed),log(life))
lm.out2<-lm(life~speed)
lm.out2
summary(lm.out2)
aov(lm.out2)
plot(lm.out2)
lm.out2$coef
3
lm.out2$coef[1]
lm.out2$coef[2]
plot(speed,life)
abline(lm(life~speed))
lm.out3<-lm(log(life)~log(speed))
lm.out3
summary(lm.out3)
aov(lm.out3)
plot(lm.out3)
lm.out3$coef
lm.out3$coef[1]
lm.out3$coef[2]
plot(speed,life)
curve(exp(lm.out3$coef[1])*x^lm.out3$coef[2],add=TRUE)
4
Download