Professional Documents
Culture Documents
MATH 423/533 - ASSIGNMENT 2: Johra October 26, 2017
MATH 423/533 - ASSIGNMENT 2: Johra October 26, 2017
Johra
October 26, 2017
(a) We can calculate the estimate, using the formula for the least squares solution:
X <- cbind(1,x1)
XTX <- t(X)%*%X
beta1 <- solve(XTX,t(X)%*%y)
print(beta1)
## [,1]
## 12129.371
## x1 3307.585
0 = 12129.371
1 = 3307.585
(b) To compute the value of the omitted entry for the Residual standard error on line 20 we can write the
following code:
## [1] 2324.779
We have that the value for sigma is 2324.7789, which is similar to the output (2324.7789).
(c) From the table we have that the missing standard error is:
e.s.e() = 1197.35
1
Which can be calculated as following:
## x1
## 1433648.9 -359160.75
## x1 -359160.8 97159.55
## x1
## 1197.3508 311.7043
SS <- (length(y)-1)*var(y)
SS2 <- SS-SS.Res
(R2 <- SS2/SS)
## [1] 0.6967813
SSR = 608555014.633
## [1] 183987.7
and:
(coef(fit.Salary)[2]*S.xy)
## x1
## 608555015
2
## [1] 183987.7
(coef(fit.Salary)[2]*S.xy)
## x1
## 608555015
(f) From the previous computation the F statistic is confirmed as 112.5995. We can calculated as following:
Fstat<-(SS2/(2-1))/(SS.Res/(length(y)-2))
Fstat
## [1] 112.5995
summary(fit.Salary)$fstatistic
## [1] 50
sum(diag(H-H1))
## [1] 1
plot(x1,y,pch=19,cex=0.75)
abline(coef(fit.Salary),col='red')
3
40000
30000
y
20000
3 4 5 6 7 8
x1
We can analyze residuals as following:
plot(x1,residual,pch=19,cex=0.75,ylim=range(-6000,6000))
abline(h=0,lty=2)
6000
2000
residual
2000
6000
3 4 5 6 7 8
x1
We can observe an outlier. But there is not evidence that the assumption concerning to the model and the
residuals error are invalid.
4
We can demonstrate the orthogonality as following:
sum(residual)
## [1] -1.67347e-10
## [,1]
## [1,] -1.67347e-10
(i) We have that the prediction is computed using the fitted straight line as:
format(as.numeric(c(1,4.8) %*%coef(fit.Salary)),digits=8)
## [1] "28005.779"
(j) As we may write the predicted value Ynew as a linear combination of the estimator vector elements. On
this way, we can replace the variance by its estimate.
## [,1]
## [1,] 224261.7
sqrt(pred.var)
## [,1]
## [1,] 473.5628
predict(fit.Salary,newdata = data.frame(x1=4.8),se.fit=TRUE)
## $fit
## 1
## 28005.78
##
## $se.fit
## [1] 473.5628
##
## $df
5
## [1] 49
##
## $residual.scale
## [1] 2324.779