Question

In a small-scale regression study, we collected data on the
number of children in a family X_{i} and the number of
hours per week spent shopping Y_{i}. The following data
were obtained:

i | 1 | 2 | 3 | 4 | 5 | 6 |

X_{i} |
2 | 6 | 3 | 1 | 1 | 9 |

Y_{i} |
13 | 17 | 12 | 12 | 9 | 22 |

Assume we performed a simple linear regression of Y_{i}
on X_{i}, i.e. E(Y_{i}) = ?_{0} +
?_{1}X_{i}

(a) By hand compute X?X, X?Y, (X?X)^{-1}, b,
Y^{^}(means Y-hat), and e. What are the dimensions of each
matrix?

(b) Create a simple linear regression in
**R**(R-program) and write down the fitted equation
and the value of MSE. Interpret the coefficient b_{1}.

(c) Use the MSE value to compute (Var(b))^{^}(means
Var(b) with a hat over it). From this matrix find estimates for
Var(b_{0}), Var(b_{1}), and Cov(b_{0},
b1).

(d) Construct a 95% confidence interval for ?_{1}. Use
the matrix formula from Chapter 6. Interpret this interval.

(e) Construct a 95% confidence interval for E(Y_{h}) and
a 95% prediction interval for Y_{h(new)} at X_{h} =
4.

(f) In **R** reproduce parts (a), (c), (d), and
(e). When recreating the results from parts (d) and (e), compute
the confidence intervals and prediction intervals two ways:

•Using matrix notation

•Using either the confint or predict functions

Also compute the hat matrix H. What is the dimension of H? Also use H to compute Y and compare to the result in part (a).

*Template for R parts of problem
below.*

# Type in children (x) and hours (y) as vectors. Set n to be the length

children <-

hours <-

n <-

##############################

########## Part (b) ##########

##############################

# Create a simple linear regression Y ~ X

fit <-

# Circle the value used to find MSE

summary(fit)

MSE <- # Type a number or use sigma() function

##############################

########## Part (f) ##########

##############################

# Create X and Y matrices.

ones <-

X <-

X # Displays matrix X

Y <-

Y # Displays matrix Y

# Display the dimensions of each of the X and Y matrices. See Chapter 5 Notes

# Calculate X'X, X'Y, (X'X)^(-1), and b.

XX <-

XY <-

XXinv <-

b <-

Yhat <-

e <-

# Display matrices (don't change)

XX

XY

XXinv

b

Yhat

e

# Calculate the variance-covariance matrix Var(b) two different ways

# 1: using MSE and XXinv

# 2: using the vcov function

Var.b1 <- # Method 1

Var.b1 # Displays matrix

Var.b2 <- # Method 2

Var.b2 # Displays matrix

# Construct a 95% confidence interval for beta1 two different ways

# 1: using matrix notation

# 2: using the confint function

beta1.lower <- # Method 1 lower

beta1.upper <- # Method 1 upper

c(beta1.lower, beta1.upper) # Displays interval (don't change)

beta1.int <- # Method 2

beta1.int # Displays interval

# Construct a 95% confidence interval for E(Y) when children=4 two different ways

# 1: using matrix notation

# 2: using the predict function

Xh <- # Enter vector Xh

Yh <- # Compute vector Yh using matrices

EY.lower <- # Method 1 lower

EY.upper <- # Method 1 upper

c(EY.lower, EY.upper) # Displays interval (don't change)

EY.int <- # Method 2

EY.int # Displays interval

# Construct a 95% prediction interval for Y when children=4 two different ways

# 1: using matrix notation

# 2: using the predict function

Y.lower <- # Method 1 lower

Y.upper <- # Method 1 upper

c(Y.lower, Y.upper) # Displays interval (don't change)

Y.int <- # Method 2

EY.int # Displays interval

# Compute the Hat matrix, H and Yhat. Find the dimension of H

H <-

H # Displays matrix

Yhat <-

Yhat

Answer #1

x'x is (2x2), x'y is (2x1) and (x'x)^{-1} is 2x2
matrix

y | b | yhat | e | sse | sigma2 | varb | |
---|---|---|---|---|---|---|---|

13 | 9.0714286 | 11.850649 | 1.1493506 | 7.7077922 | 2.5692641 | 1.1011132 | -0.183519 |

17 | 1.3896104 | 17.409091 | -0.409091 | -0.183519 | 0.0500506 | ||

12 | 13.24026 | -1.24026 | |||||

12 | 10.461039 | 1.538961 | |||||

9 | 10.461039 | -1.461039 | |||||

22 | 21.577922 | 0.4220779 |

regression equation y=b0+b1*x=9.0714+1.3896x

SE(b1)=sqrt(0.05)= 0.2236

95% confidence interval for b1=1.3896t(0.05/2,errror df=4)*SE(b1)=1.38962.7764*0.2236=1.38960.6208=

(0.7688, 2.0104)

A researcher collected the following data on years of education
(X) and number of children (Y) for a sample of married adults:
X
Y
12
2
14
1
17
0
10
3
8
5
9
3
12
4
14
2
18
0
16
2
a. Draw a scatterplot of the data.
b. Calculate the correlation between education and number of
children for this sample of 10 married adults.
c. Interpret the correlation between education and number of
children.
d. Is...

*Answer all questions using R-Script*
Question 1
Using the built in CO2 data frame, which contains data from an
experiment on the cold tolerance of Echinochloa crus-galli; find
the following.
a) Assign the uptake column in the
dataframe to an object called "x"
b) Calculate the range of x
c) Calculate the 28th percentile of
x
d) Calculate the sample median of
x
e) Calculate the sample mean of x and
assign it to an object called "xbar"
f) Calculate...

I. Solve the following problem:
For the following data:
1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 n = 12
b) Calculate
1) the average or average
2) quartile-1
3) quartile-2 or medium
4) quartile-3
5) Draw box diagram (Box & Wisker)
II. PROBABILITY
1. Answer the questions using the following
contingency table, which collects the results of a study to 400
customers of a store where you want to analyze the payment
method.
_______B__________BC_____
A...

1. A city official claims that the proportion of all commuters
who are in favor of an expanded public transportation system is
50%. A newspaper conducts a survey to determine whether this
proportion is different from 50%. Out of 225 randomly chosen
commuters, the survey finds that 90 of them reply yes when asked if
they support an expanded public transportation system. Test the
official’s claim at α = 0.05.
2. A survey of 225 randomly chosen commuters are asked...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 2 minutes ago

asked 14 minutes ago

asked 29 minutes ago

asked 35 minutes ago

asked 35 minutes ago

asked 45 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago