---
title: "STAT 3340 Assignment 4, Fall  2026, due Monday, November 16, 11:59 PM"
output:
  pdf_document: default
  html_document: default
  word_document: default
---



1.  The regression model  $y = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \epsilon$
  was fit to a data set   with $n=24$ observations, and resulted in MSE=16, with $\hat \beta$ and  $(X'X)^{-1}$ given by:

```{r}  
Mhatbeta= c(1000, 100, -200)
xpxinverse=matrix(c(15,8,7,8,12,5,7,5,20), byrow=T,ncol=3)
```
  + 1a) Construct a 95\% confidence interval for $\beta_1$.

  + 1b) Construct simultaneous 90\% confidence intervals for $\beta_1$ and $\beta_2$.

  + 1c) Construct a 99\% confidence interval for $\beta_0 - 2 \beta_1 + \beta_2$.

  + 1d) Is the value $\beta=c(950, 90, -230)$ contained in the 95\% confidence ellipse
for $\beta$?   (Hint: Calculate  the value of ${({\hat \beta} - \beta)}^T (X'X) (\hat \beta - \beta)$ and compare it to
$p MSE \,\, qf(.95, p, n-p)$.)  Show your work.
\newpage

2.  The following calculates the SSE and MSE for the model
$y = \beta_0 + \beta_1 X_1+ \beta_2 X_2+ \beta_3 X_3+ \beta_4 X_4 + \epsilon$, for the "cement" data set.

```{r}
data=read.csv("http://www.mathstat.dal.ca/~bsmith/stat3340/Data/cement.csv")
  #read data
 X=as.matrix(cbind(rep(1,13),data[,-c(1,2)])) #construct the X matrix
 y=matrix(data[,2],byrow=T,ncol=1)   #construct Y
  n=dim(X)[1]   #number of observations
  k=dim(X)[2]-1 #number of predictor variables in full model

beta=solve(t(X)%*%X)%*%t(X)%*%y  #calculate least squares estimates
SSEfull=t(y)%*%y-t(beta)%*%t(X)%*%y  #get the error SS for full model
MSEfull=SSEfull/(n-k-1)                  #MSE under full model
```

Answer the following questions by computing SSE for the appropriate reduced models using
matrix operations, then calculating the F statistic for the partial F test, and
calculating the p-value using the "pf" command.  (You can check your results using the
builtin "anova" function.)

   + 2a)  Test the hypothesis that $\beta_1=0$.

```{r}
#Xred=X[,???] construct the appropriate X matrix for the reduced model
#betared=solve(t(Xred)%*%Xred)%*%t(Xred)%*%y  #calculate LSE for reduced model
#SSEred=t(y)%*%y-t(betared)%*%t(Xred)%*%y   #get the SSE for the reduced model
#Fobs=((?-?)/?)/?  # calculate the F statistic
#Fobs # print the observed F
#pv=1-pf(Fobs,?,?) #calculate the p-value
#pv #print the p-value
```

   + 2b) Test the hypothesis that $\beta_1 = \beta_2 = 0$.
```{r}
# enter your R commnds here
```

   + 2c) Test the hypothesis that $\beta_1 = \beta_2 = \beta_3 = \beta_4 =0$.
```{r}
# enter your R commnds here
```


\newpage

3.  Prove that the matrices $I-J/n$, and $H-J/n$ are orthogonal to one another.  You can use the fact that $HX=X$.


