Stat 552

Homework 2

Due 3pm Jan 22 in class


Part One

Hardcopy handed in (may be handwritten or typeset)

1. Consider the simple linear regression model:

where the are independent Normal random errors.

a) Using the matrix form for multiple linear regression, write out the form of , and .

b) Calculate , and .

c) Find the least squares estimates, .

d) (Extra credit) Show the least squares estimates above, are equivalent to the usual form for the estimates in simple linear regression:

2. Using the matrix from of the least squares estimates, derive the form of the estimate of slope in a simple linear regression without an intercept:

where the are independent Normal random errors.

Part Two

Hand in a .Rmd file on canvas, and as a hardcopy of the compiled .Rmd file (i.e. a .pdf of .doc).

1. The dataset teengamb in the package faraway contains survey data from a study to investigate teen gambling in the U.K.


Consider the regression model:

a) Construct the design matrix and response vector in R.

b) Find the least squares estimates using matrix algebra in R. Verify your answers by fitting the regression model using lm.

c) Find the fitted values and residuals using matrix algebra in R and present a plot of residuals against fitted values.

2. Consider the following regression model:

Simulate a realization of the model in R by setting up the matrix, vector, and the error vector and using matrix algebra. Include a plot of against .

3. (Faraway 2.3) Generate some artifical data by:

n <- 20
x <- 1:n
y <- x + rnorm(n)

Fit a polynomial in x for predicting y. Compute in two ways: using lm, and directly using matrix algebra. At what degree of polynomial does the direct calculation fail?

A regression model that uses a polynomial in of degree to predict is

(Take away: while the matrix formulas we use in class are analytically correct, they don’t neccessarily describe a good way to get answers numerically.)