1. Using the cheddar data: (a) Fit a linear model with taste as the response and
ID: 3816716 • Letter: 1
Question
1. Using the cheddar data: (a) Fit a linear model with taste as the response and the other three variables as predictors. (b) Suppose that the observations were taken in time order. Create a time variable Plot the residuals of the model against time and comment on what can be seen. (c) Fit a GLS model with same form as above and allow for an AR(1) correlation among the errors. Is there evidence of such a correlation? (d) Fit a OLS model but with time as an additional predictor. Investigate the significance of time in the modelExplanation / Answer
NOTE: The data 'x' is not given, so the general code is given as follows.
(a)
library(faraway)
data(cheddar)
x=cheddar
t=c(x[,1])
a=c(x[,2])
h=c(x[,3])
l=c(x[,4])
A=lm(t~a+h+l)
A
Call:
lm(formula = t ~ a + h + l)
Coefficients:
(Intercept) a h l
-28.8768 0.3277 3.9118 19.6705
(b)
tt=1:length(x[,1])
res=resid(A)
plot(tt,res,ylab="Residuals", xlab="Time",main="cheddar")
abline(0,0)
The scatterplots show no obvious patterns, although the residuals tend to be negative for large values of the time predictor.
(c)
rm(list=ls(all=TRUE))
library(nlme)
library(faraway)
data(cheddar)
x=cheddar
t=c(x[,1])
a=c(x[,2])
h=c(x[,3])
l=c(x[,4])
xx=gls(t~a+h+l, correlation = corAR1(form = ~ 1 ))
xx
Generalized least squares fit by REML
Model: t ~ a + h + l
Data: NULL
Log-restricted-likelihood: -101.47
Coefficients:
(Intercept) a h l
-30.332472 1.436411 4.058880 15.826468
Correlation Structure: AR(1)
Formula: ~1
Parameter estimate(s):
Phi
0.2641944
Degrees of freedom: 30 total; 26 residual
Residual standard error: 10.33276
(d)
rm(list=ls(all=TRUE))
library(nlme)
library(faraway)
data(cheddar)
x=cheddar
t=c(x[,1])
a=c(x[,2])
h=c(x[,3])
l=c(x[,4])
tt=1:length(x[,1])
xx=lm(t~a+h+l+tt)
xx
Coefficients:
(Intercept) a h l tt
-36.6127 4.1275 3.5387 17.9527 -0.5459
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.