Statistics Homework due in 24 hours. (Spencer_m)

profileRicardo2222
hw4.pdf

STATISTICS 462 – Summer 2016 Homework 4

DUE Wednesday, July 20th

Unless otherwise stated, you can use R for any of the calculations, but make sure you include your code. Your code should not be a copy of anyone else’s! Any code you turn in should be well organized and commented so the grader can understand your answers.

All programming questions should be submitted to the dropbox on ANGEL for this assignment as a .pdf file using the naming convention HWNum_FirstInitialLastName.pdf. For example, John Doe would submit a file titled HW1_JDoe.pdf for the first assignment. Your answer to programming questions should include both code and a description of your result. I recommend using R-markdown for writing up your answers. A template for writing up an assignment in R-markdown can be found on ANGEL. R-markdown files can be compiled directly within R-Studio. Alternatively, answers may be saved in a word document or LaTeX, and converted into a .pdf file.

Non-coding questions can either be written and submitted in the same file as your coding questions using LaTeX typesetting (see https://latex-project.org/intro.html) or they may be handwritten and turned in separately during class.

1. Review chapter 5 if you cannot answer any of these matrix algebra questions. Let

A =

  1 02 7 −1 2

  , B = [1 2 1

0 3 −4

] c′ = [1,0,2], and d = 2, a scalar.

Perform the following operations, if possible. If the operation is not possible, explain why and give a possible solution.

(a) c′A;

(b) A′c;

(c) B′ + A;

(d) cA′;

(e) A − d; (f) dB + A.

2. (a) Let

B =

  0 0 1 1 0 1 0 1 1 0 0 1 0 0 0 1

  .

Compute in R, D = B(B′B)−1B′.

(b) Find aij elements to make the following matrix symmetric 

1 2 a13 4 2 3.5 8 a24 7 a32 9 −4 a41 2 −4 1

  .

(c) Find the inverse of the following matrix in R

A =

 7 0 00 13 9 0 8 1

  .

(d) Let X =

 

1 .1 0 1 .3 0 1 .4 0 1 .2 0 1 .5 .1 1 .5 .1 1 .7 .1 1 .9 .1

  , Y =

 

342 340 336 330 339 338 331 326

  .

Compute X′X and X′Y . Verify by separate calculations that the (i,j) = (2,2) element in X′X is the sum of squares of column 2 in X. Verify that the (2,3) element is the sum of products between columns 2 and 3 of X. Identify the elements in X′Y in terms of sums of squares or products of the columns of X and Y.

(e) Obtain (X′X)−1. Verify by matrix multiplication that (X′X)−1X′X = I.

(f) Compute P = X(X′X)−1X′.

3. The multiple linear regression model is Y = Xβ + �. Assume there are 30 observations and five independent variables (containing no linear dependencies). Give the dimensions of:

(a) Y.

(b) X (without an intercept in the model).

(c) X (with an intercept in the model).

(d) β (without an intercept in the model).

(e) β (with an intercept in the model).

(f) �

(g) X′X (with an intercept in the model).

(h) P (with an intercept in the model).

(i) Run in R the following commands

set.seed(1234) library(MASS) X=mvrnorm(30,rep(0,5),diag(5)) Y=rnorm(30,2,1)

Compute (X′X)−1X′Y.

4. Load the dataset Real Estate from the file “realestatesales.csv” using

read.table(file = "./realestate_sales.csv", header = T, sep = ",")

Data was collected on 521 houses recently sold in a city. It consisted of the sales price (in dollars), house size (in square feet), the number of bedrooms, and the number of bathrooms (as well as a few other variables which we are not concerned with at present).

(a) Suppose we are only interested in working with a subset of the variables (e.g., SalePrice, Size and AirSize). Investigate how the variables are related to one another through a scatterplot matrix. Comment on your output.

(b) Given the response variable SalePrice, and the predictors Size and AirSize deter- mine the dimensions of Y, X, β, and �. Describe what β and � represent.

(c) Write out the population regression model using matrix notation.

(d) What is the formula used to calculate the vector of estimated coefficients, β̂?

5. Use the Real Estate dataset from question 4. Suppose we are only interested in working with a subset of the variables (e.g., SalePrice, Size and AirSize).

(a) Given the response variable SalePrice, and the predictors X1=Size and X2=AirSize, calculate the vector of slope coefficients in R.

(b) Suppose that we add a third predictor, to the model, X3 = X1X2. Now re-define the dimensions of the design matrix, X. Does anything else change in the model from part 2 of exercise 4?

(c) Explain what problem we would run into if we added a predictor X3 = X1 + 3X2 to the model. Specifically, what happens when we try to solve for β̂ and why?