19 Quiz 1:
1. Give the value of \(\mu\) that minimizes the least squares equation given the data and weights below:
## [1] 3.716543
The value 0.1471
has the lowest value.
2. Fit the regression through the origin and get the slope treating y as the outcome and x as the regressor. (Hint, do not center the data since we want regression through the origin, not through the means of the data.)
x <- c(0.8, 0.47, 0.51, 0.73, 0.36, 0.58, 0.57, 0.85, 0.44, 0.42)
y <- c(1.39, 0.72, 1.55, 0.48, 1.19, -1.59, 1.23, -0.65, 1.49, 0.05)
# Here we have to add the x-1 term, so as to plot regression through the origin.
model <- lm(y~x-1)
coef(model)
## x
## 0.8262517
3.Do data(mtcars) from the datasets package and fit the regression model with mpg as the outcome and weight as the predictor. Give the slope coefficient.
## (Intercept) mtcars$wt
## 37.285126 -5.344472
4. Consider data with an outcome (Y) and a predictor (X). The standard deviation of the predictor is one half that of the outcome. The correlation between the two variables is 0.5. What value would the slope coefficient for the regression model with Y as the outcome and X as the predictor?
\[\hat{\beta_1} = Cor(Y,X){Sd(Y) \over Sd(X)}\]
## [1] 1
5. Students were given two hard tests and scores were normalized to have empirical mean 0 and variance 1. The correlation between the scores on the two tests was 0.4. What would be the expected score on Quiz 2 for a student who had a normalized score of 1.5 on Quiz 1? \[\hat{\beta_1} = Cor(Y,X){Sd(Y) \over Sd(X)}\] \[q_1 = q_2 \beta\]
## [1] 0.6
6. What is the value of the first measurement if x were normalized (to have mean 0 and variance 1)?
## [1] -0.9718658
7. Consider the following data set (used above as well). What is the intercept for fitting the model with x as the predictor and y as the outcome?
x <- c(0.8, 0.47, 0.51, 0.73, 0.36, 0.58, 0.57, 0.85, 0.44, 0.42)
y <- c(1.39, 0.72, 1.55, 0.48, 1.19, -1.59, 1.23, -0.65, 1.49, 0.05)
model <- lm(y ~ x)
coef(model)
## (Intercept) x
## 1.567461 -1.712846
8. You know that both the predictor and response have mean 0. Whatcan be said about the intercept when you fit a linear regression?
It’s gonna be zero too!
9. What value minimizes the sum of the squared distances between these points and itself?
## [1] 0.573