Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MATH 423:  Applied Regression

Fall 2022

Assignment 2

Q1.  Case study:  We consider the kidney tness data from the book Computer Age

Statistical Inference” .  The data is originated in the nephrology laboratory of Dr. Brian Myers, Stanford University. It contains data points (xi , yi ) on n = 157 healthy volunteers (potential donors), where

● xi  (age): age of the i-th volunteer (in years)

● yi  (tot): a composite measure of overall kidney function of the i-th volunteer.

Kidney function generally declines with age, as evident in the downward scatter of the points. The rate of decline is an important question in kidney transplantation: in the past, potential donors past age 60 were prohibited, though, given a shortage of donors, this is no longer enforced.  First, install a necessary package for loading the data:

 

We’ll use age as a predictor, and tot as the response. Complete the following tasks: (a) Plot the observations for the response against the observations for the predictor. Is the relationship between tot and age linear?

(b) Create a  test” set, that is a grid of age values at which we will predict tot. The range of the grid is [mini (agei ), maxi (agei )].

(c) Plot the KNN predictions using the test” set defined in task (b) for various k = {1, 5, 10, 25, 50, 157}. Which value of k gives the best prediction?

Q2. Use the informations from Question 1:

(a) Now change the range of the grid for the test set to [1,18]. Repeat task Q1(c) for this test set. How do the predictions change? What’s the problem of the predictions?

(b) Now change the range of the grid for the test set to  [88,120].   Repeat task Q1(c) for this test set. How do the predictions change? What’s the problem of the predictions?

Hint:  For task Q2(a) and Q2(b), since the range of predictions in the  test” set (e.g.  [88,120]) is outside of the range of age in the training” set (i.e.  [18, 88]), a part of the prediction curve will not be properly shown in your gure. To x this you can increase the range of the plot by adding an additional argument xlim=c(0,120) in plot() function, which set the range of age from [mini (agei ), maxi (agei )]= [18, 88] to [0, 120]. For example

plot(tot ~ age, data = kidney, cex = .8,

col = dodgerblue”, main = “k = 1”, xlim = c(0, 120))

Q3.  Suppose that Y is a random variable and

Y = βà + e

where 匝(e) = 0 and Var(e) = σ 2 .  Note that the term β|X|  does not exist in the model, so we have an intercept-only model.

Suppose that we know the distribution of Y .  We would like to predict Y .  If we require that the prediction is just a constant, denote as c. Now we ask the question “What is the optimal prediction constant c we can get?”  i.e.  to nd the optimal value of c (denoted by c# ) such that it minimizes the mean squared error

c#  = arg min 匝Y [(Y  c)2].

c

Prove that the optimal solution is

c#  = 匝(Y) = βà .

Q4.  Suppose that in the following intercept-only model,

Yi  = βà + ei ,   i = 1, . . . , n

where 匝(ei ) = 0 and Var(ei ) = σ 2 .

(a) Use the result from Question 1 to derive the plug-in estimate for βˆà .

(Hint: replace Y with y| , . . . , yn  and replace 匝(.) with      i兰(n)| (.))

(b) Find the least squares estimate βˆà . Is it the same as the plug-in estimate?

(c) Show that βˆà  is unbiased.

Q5.  Consider these data

X|

4

3

5

7

Y

6

2

4

11

(a) Fit the data in R and summarize the results.

(b) Compute XX and (XX)| and then compute βˆ (using formula βˆ = (XX)|XY) and confirm that you get the same answer as you got from R using function lm.

(c) Compute

SSRes

2 .

(d) Compute

.(、)  = 2 (XX)|

Q6. The following data gives data on average public teacher annual salary in dollars,

recorded in the data frame salary as the variable SALARY, and spending (SPEND- ING) per pupil (in thousands of dollars) on public schools in 1985 in the 50 US states and the District of Columbia. The objective of the analysis is to understand whether there is a relationship between teacher pay, y, and per-pupil spending, x.

 

An analysis in R is presented above:  some of the output has been deleted and replaced by XXXXX.

In answering the following questions, you may not use the lm function or its result on these data (or the functions coef(), residuals() etc.), but instead should use vector and matrix calculations.

(a) Write R code to verify the calculation of the entries in the Estimate column, and show that your code produces the correct results.

(b) Verify numerically the orthogonality results concerning the residuals, that is,

n                           n                                               n                      n

ei  = 0          ei (xi  x) = 0          eiyˆi  =       ei (βˆà + βˆ1xi ) = 0

i1                      i1                                        i1                 i1

(c) Compute the value of the entry in the Std.Error column on line 10 first using entries already given in the table, and then using the data directly.

(d) Write R code to compute the value of the omitted entry for the Residual standard error on line 15.

(e) Test whether or not there is a linear association between SALARY and                       ,

using α  = 0.05.   State the alternative hypothesis, decision rule, and conclusion.

What is the p-value of the test?

Q7. Use the informations from Question 6:

(a) A test on β|  using a confidence interval:  construct a 100(1 α)% confidence interval with α = 0.01 for β|  using R code.  How do you interpret the interval? Check whether the value 3500 is included by the interval. What is the corresponding hypothesis test (provide the null and alternative hypothesis, calculate the t-statistic and p-value, and significance level) and what is the conclusion?

(b) The F  statistic on line 17 is computed using the sums-of-squares decompo- sition

SST  = SSRes + SSR

and the formula

SSR /(p 1) 

F =

where here p = 2 for simple linear regression. Write R code to compute the omitted value for F (using the formulas provided). Verify the corresponding p-value. What is the significance level of this test? What is the corresponding null and alternative hypothesis of the test?

(c) In the notation from lectures, we have that the sums-of-squares decomposition can be written

SST  = SSRes + SSR

Verify this result numerically.

(d) Using the tted model, predict what the average public teacher annual salary would be in a state where the spending per pupil is $5000.

(e) The prediction at an arbitrary new x value, xew  can be written in terms of the estimates βˆ as

yˆnew  = [1  xew ]βˆ = βˆà + βˆ| xew

with βˆ the least squares estimate. Compute the estimated standard prediction error

for yˆnew   , that is, the square root of the estimated variance of the corresponding

random variable

new  = Xew βˆ = [1  xew ]βˆ

now βˆ with the least squares estimator, if xew  is $5000.

(f) Use the information of yˆnew  and estimated standard prediction error for yˆnew  ob- tained from the last question to construct the confidence interval for the conditional mean and the prediction interval for the future observation (using the formulas). Verify your computations using the R functions

predict(..., interval = “confidence”)

for the confidence interval and

predict(..., interval = “prediction)

for the prediction interval.

Q8. Assume the data are generated from the GN-SLR setting,

Yi  = β|Xi| + ei ,     i = 1, . . . , n

where ei  ~ N (0, σ2 ).

We only have the observed versions of (Yi , Xi|), which are (x|| , y| ), . . . , (xn|, yn ). We want to estimate β|  and σ 2  with these data using the Maximum Likelihood

Method.

(a) Show that the likelihood function is

i|

(b) Compute the negative log-likelihood function

l(βà , β| , σ 2 ) = log L(βà , β| , σ 2 )

(c) Show that the MLE estimator for β|  is

βˆMLE  =     | xiy2i

(d) Show that the MLE estimator for σ 2  is

n