linear models assignment: vi
TRANSCRIPT
-
8/14/2019 Linear Models Assignment: VI
1/7
Linear Models Assignment: VI
Subhadip Pal
Due date: 28th November 2009
1.
A) We are concentrating regression of BAC on NOB/(Weightp) for differentvalues of between 0 and 1. We have to estimate by obtaining, numerically, the
value of p that minimizes the residual squared error in the regression of BAC on
NOB/(Weightp). is a parameter. Based on the observed data we have to get an
estimate of the unknown constant.
To get an estimate we took a very crude method to calculate the Residual Sum Of
square (RSS) assuming the model for 10000 equidistant points
as a value of. Then we took the point as as estimate of optimal value of p for which
the RSS is minimum. And after implementing the process in R we get
=0.5793579
Fig1. Assuming the model for different
values of the p the Error Sum of Squares of the model
after fitting to the given data is plotted against the
different values of
-
8/14/2019 Linear Models Assignment: VI
2/7
B)
Fig2. Scatter plot of ( , BAC) data points and 95%
prediction band for the future observation .The size of the datapoint is increasing function of NOB
C. Assume that in the regression of BAC on , we really do have
simple linear regression, with normal errors, and equal variances. The (point wise)coverage probability of the band is (c) greater than: 0.95 . Because to get the 95%band we used an estimate of the variance of the errors and the variance estimate is
. but so the band we have formed is wider than the
-
8/14/2019 Linear Models Assignment: VI
3/7
actual 95% band that we could formed using the . Hence the probability of a
point would be inside the band is actually greater that 0 .95 .
2.
A) Amount of Sweat is related with that means Ln(S) is linearly
related with Ln(L) where S=Amount of Sweat and L=LoopLength . We are assuming
the model ln( . here is actually Ln(a) and =b . In R we fit the
linear model to get estimate of and and hence estimate of and and
we get and
B)
-
8/14/2019 Linear Models Assignment: VI
4/7
Fig3. 95% prediction band for the amount of sweat as a
function of distance, as distance ranges continuously from 3 to 9.
Appendix:
R code used for problem 1:
######################data import part #########################
data_import
-
8/14/2019 Linear Models Assignment: VI
5/7
library(lattice)p
-
8/14/2019 Linear Models Assignment: VI
6/7
X=NOB/(Weight^opt[1,1])fit1=lm(BAC~X)library(lattice)trellis.device(pdf,file="C:\\My Computer\\edu\\Lm\\plot.pdf")par(cex.axis=1,cex.lab=1.2)par(mar=c(5,4+1,4,2))plot(X,BAC,type="p",cex=.3+NOB/mean(NOB),xlab="X : NOB/Weight^p_opt",ylab="Blood Alcohol content")abline(fit1)title("95% prediction band of BAC as a function of NOB/Weight^p")#legend(.6,0.0059,c("Optimal value of p"),col=c("red"),pch=c(21),cex=1.2)
grid=seq(0,max(X)+.1,length=1000)nd=data.frame(X=grid)#newData=grid#pred=predict(fit1,newdata=nd,interval="confidence")pred=predict(fit1,newdata=nd,interval="prediction")lines(grid,pred[,2],lty=1,col="blue")lines(grid,pred[,3],lty=1,col="blue")
dev.off()}
################################ to execute the functions########################################data_import()#ass6(10000,0) ###### l=10000 is precission parametre more l means moreprecission in estimation and more time to executeb=conf_int(10000)
R Code used for problem 2:
data_prep
-
8/14/2019 Linear Models Assignment: VI
7/7
plot(LoopLength,Sweat)lines(fine.grid,exp(predY[,2]),col="red", lty=1)lines(fine.grid,exp(predY[,3]),col="red", lty=1)lines(fine.grid,exp(predY[,1]),col="brown", lty=1)#lines(fine.grid,b[1]*fine.grid^b[2],col="green" ,lty=1)return (z)}
## to execute the functionsdata_prep()z=ass6.2()