bailsofhay — Nov 25, 2013, 5:54 PM
###Problem 8.8 ######
data=read.table("http://www.stat.lsu.edu/exstweb/statlab/datasets/KNNLData/CH06PR18.txt")
names(data)=c("y","x1","x2","x3","x4")
### Part a #####
plot(data$x1, data$y, xlab="Property Age", ylab="Rental Rates")
x1=data$x1-mean(data$x1)
fit1=lm(data$y~x1+I(x1^2)+data$x2+data$x4)
fit1
Call:
lm(formula = data$y ~ x1 + I(x1^2) + data$x2 + data$x4)
Coefficients:
(Intercept) x1 I(x1^2) data$x2 data$x4
1.02e+01 -1.82e-01 1.41e-02 3.14e-01 8.05e-06
coeff=fit1$coefficients
# yi= 10.20-.1818X1+.01415X1^2+.3140X2+.000008X4
plot(data$y, fit1$fitted.values,xlab="Rental Rates",ylab="Fitted Value")
# There is a much better fit than when the data was left with just x1,x2 and x4.The data
# appears to be more linear than previously.
#### Part b###
r.square=summary(fit1)$adj.r.squared
# R^2 is:
r.square
[1] 0.5927
# R^2 measures the proportional reduction in the variation of the estimated Y by adding X1^2 into
# linear model.
### part c ####
# Alternatives: Ho: B11=0, Ha: B11 is not equal to zero
# Decision Rule: If t* < or equal to t critical, conclude Ho. If t* is > than t critical
# conclude Ha
coeff=fit1$coefficients
b11=coeff[3]
summary=summary(fit1)$coefficients
ts=summary[3,3]
# t* is
ts
[1] 2.431
tc=qt(.975,76)
# t critical is:
tc
[1] 1.992
## Conclude Ha since t*>>t --> B11 is not equal to 0.
### part e ####
x1=data$x1
fit2=lm(y~x1+I(x1^2)+x2+x4, data=data)
fit2
Call:
lm(formula = y ~ x1 + I(x1^2) + x2 + x4, data = data)
Coefficients:
(Intercept) x1 I(x1^2) x2 x4
1.25e+01 -4.04e-01 1.41e-02 3.14e-01 8.05e-06
# Yi= 12.49-.404X13+.01415X1^2+.3140X2+.000008X4
### part d ####
predict(fit2, newdata=data.frame(x1 = 8, x2 = 16, x4 = 250000),interval = c("confidence"), level = 0.95)
fit lwr upr
1 17.2 16.46 17.94
# Yh= 17.2
# Confidence interval: [16.5,17.9]