1.
x <- c(0.18, -1.54, 0.42, 0.95)
w <- c(2, 1, 3, 1)
sum(w*x)/sum(w)
## [1] 0.1471429
2.
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)
lm(y~x+0)
##
## Call:
## lm(formula = y ~ x + 0)
##
## Coefficients:
## x
## 0.8263
coef(lm(y ~ x - 1))
## x
## 0.8262517
3.
data(mtcars)
lm(mpg~wt, mtcars)
##
## Call:
## lm(formula = mpg ~ wt, data = mtcars)
##
## Coefficients:
## (Intercept) wt
## 37.285 -5.344
4. \(2sd(X)=sd(Y),slope=cor(Y,X)\frac{sd(Y)}{sd(X)}=0.5\cdot 2=1\)
5. \(\beta=cor(Y,X)=0.4\)
Y <- 0.4*1.5
Y
## [1] 0.6
6.
x <- c(8.58, 10.46, 9.01, 9.64, 8.86)
(x[1]-mean(x))/sd(x)
## [1] -0.9718658
7.
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)
lm(y~x)[1]
## $coefficients
## (Intercept) x
## 1.567461 -1.712846
9.
x <- c(0.8, 0.47, 0.51, 0.73, 0.36, 0.58, 0.57, 0.85, 0.44, 0.42)
mean(x)
## [1] 0.573