Docsity

Multiple Regression Analysis: Prediction Intervals and Diagnostic Plots for NO2 Levels, Assignments of Descriptive statistics

Partial preview of the text

Download Multiple Regression Analysis: Prediction Intervals and Diagnostic Plots for NO2 Levels and more Assignments Descriptive statistics in PDF only on Docsity!

  • Statistics 135 Spring Quarter
    • Answers to HW #

(cont…)

7.21 For simplicity, we will consider the multiple regression model:

Y = β 0 + β 1 z 1 + β 2 z 2 + ε.

(Optional note: it is always a good idea to plot the data first to review what form of the model

would be suitable for the data. pairs () command will do so for a multivariate dataset.

For these data situation, the predictors Z 1 and Z 2 to not appear to be linearly associated with the

responses Y 1 and Y 2 , thus the above model could be meaningless in terms of prediction!!! In

fact, both response variables appear to have a quadratic relationship with Z 2 , thus it makes

more sense to include the quadratic terms in the model.)

(a)

(i) Under the multiple regression model defined above, with Y = y 1 , the fitted regression

equation:

y ˆ 1 = 10.11454 – 0.21129 z 1 + 0.02055 z 2.

(ii) A plot of residuals versus the fitted values suggests the error terms may not have constant

variance. A Q-Q plot of the residuals does not appear to be linear, thus the normality

assumption of the error terms is suspect. One may consider transforming the variables to

remedy this situation.

(iii) The 95% prediction interval is:

z 0

T

!ˆ^ ± t(1-0.05/2, n-r-1)*√[s

*(1+ z 0

T

(Z

T

Z)

z 0 )], where n=42, r=2, s

=11.67, then

Thus, for wind speed of 10mph and for solar radiation of 80, the levels of NO2 are predicted to

be measured somewhere between 2.427 and 16.864.

(b)

(i) Under the multiple regression model defined above, with Y = ( Y 1 , Y 2 ), the fitted regression

equations are:

y ˆ 1 = 10.11454 – 0.21129 z 1 + 0.02055 z 2 ,

y ˆ 2 = 8.276192 – 0.78682 z 1 + 0.09518 z 2.

(ii) Both plots of residuals versus the fitted values suggest the error terms may not have

constant variance. Both Q-Q plot of the residuals do not appear to be linear, thus the normality

assumption of the error terms is suspect. One may consider transforming the variables to

remedy this situation.

R code: Pr. 7.

data=read.table("Sta135jiming/Wichern_data/T1-5.dat") names(data)=c("z1","z2","x3","x4","y1","y2","x7") pairs(data[,c( 5 , 6 , 1 , 2 )]) y1=data[, 5 ] Y=as.matrix(data[, 5 : 6 ]) Z=cbind( 1 ,data[, 1 ],data[, 2 ]) #(a) B=solve(t(Z)%%Z)%%t(Z)%%y B Yhat=Z%%B residuals=y1-Yhat par(mfrow=c( 1 , 2 )) plot(Yhat,residuals) abline(h= 0 ) qqnorm(residuals) qqline(residuals) par(mfrow=c( 1 , 1 ))

z0=c( 1 , 10 , 80 ) n=nrow(Z) r=ncol(Z)- 1 n-r- 1 s2=t(y1-Yhat)%%(y1-Yhat)/(n-r- 1 ) c(t(z0)%%B - qt( 1 - 0.05/ 2 ,n-r- 1 )sqrt(s2( 1 +t(z0)%%solve(t(Z)%%Z)%%z0)), t(z0)%%B + qt( 1 - 0.05/ 2 ,n-r- 1 )sqrt(s2( 1 +t(z0)%%solve(t(Z)%%Z)%%z0))) #(b) B=solve(t(Z)%%Z)%%t(Z)%%Y B Yhat=Z%%B residuals=Y-Yhat par(mfrow=c( 2 , 2 )) plot(Yhat[, 1 ],residuals[, 1 ],xlab="Yhat",ylab="Residulas", main="Residual vs Predicted values (of Response 1)") abline(h= 0 ) plot(Yhat[, 2 ],residuals[, 2 ],xlab="Yhat",ylab="Residulas", main="Residual vs Predicted values (of Response 2)") abline(h= 0 ) qqnorm(residuals[, 1 ], main="Q-Q plot of residuals (of Response 1)") qqline(residuals[, 1 ]) qqnorm(residuals[, 2 ], main="Q-Q plot of residuals (of Response 2)") qqline(residuals[, 2 ]) par(mfrow=c( 1 , 1 )) z0=c( 1 , 10 , 80 ) n=nrow(Z) r=ncol(Z)- 1 m= 2 n-r- 1 S=t(Y-Yhat)%%(Y-Yhat)/(n-r- 1 ) predMean=t(z0)%%B predMean solve(S) c2=( 1 +t(z0)%%solve(t(Z)%%Z)%%z0)m(n-r- 1 )/(n-r-m)qf(0.95,m,n-r-m) c eig=eigen(solve(S)) V1=eig$vec[, 1 ] V2=eig$vec[, 2 ] e1=sqrt( 1 /eig$val[ 1 ]c2) e2=sqrt( 1 /eig$val[ 2 ]c2) angle=( 0 : 100 ) 2 pi/ 100 mu1=e1V1[ 1 ]cos(angle) + e2V2[ 1 ]sin(angle) + predMean[ 1 ] mu2=e1V1[ 2 ]cos(angle) + e2V2[ 2 ]sin(angle) + predMean[ 2 ] plot(mu1,mu2,type="l",col= 4 , xlab="Y_01", ylab="Y_02", main="95% prediction ellipse for the response") points(predMean,pch= 19 ) c(t(z0)%%B - qt( 1 - 0.05/ 2 ,n-r- 1 )sqrt(s2( 1 +t(z0)%%solve(t(Z)%%Z)%%z0)), t(z0)%%B + qt( 1 - 0.05/ 2 ,n-r- 1 )sqrt(s2( 1 +t(z0)%%solve(t(Z)%%Z)%*%z0)))