Do problem 3.12 in the book without using the LM function in R. The corresponding data file is data-table-B8.csv is attached. Specifically, the problem is regressing clathrate formation (y - mass%) on the amount of surfactant (x1 - mass %) and time (x2 - min).
library(MASS)
## Warning: package 'MASS' was built under R version 4.2.2
data<- read.csv("C:\\Users\\abdal\\Downloads\\data-table-B8(2).csv")
X1<-data$x1
X2<-data$x2
y<-data$y
d<- t(y)
Y<-t(d)
ones<-rep(1,36)
X<-cbind(ones,X1,X2)
Beta<-ginv(t(X)%*%X)%*%t(X)%*%y
A.Write the model equation of clathrate formation regressed on both surfactant and time.
codebook:
Y: Clathrate Formation
x1: Surfactant
x2: Time
\(Y=\beta_0+\beta_1x_1+\beta_2x_2+\epsilon\)
B.Fit the model in R without using the LM function. What is the dimensionality of Y? What is the dimensionality of X?
Beta<-ginv(t(X)%*%X)%*%t(X)%*%y
Dimension of Y is 36X1
dim(Y)
## [1] 36 1
Dimension of X is 36X3
dim(X)
## [1] 36 3
C.What are the least squares estimates of the regression parameters in the model?
Beta
## [,1]
## [1,] 11.0869804
## [2,] 350.1192457
## [3,] 0.1089344
\[ \beta_0=11.0869 \\ \beta_1=350.1192457\\ \beta_2=0.1089344 \]