x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
relation <- lm(y~x)
print(relation)
beta=solve(t(x)%*%x)%*%(t(x)%*%y)
print(beta)
Result from lm
coeff = 0.6746
Result from beta econometrics = 0.4287
Why?
lm(y~x -1)
). Usemodel.matrix()
function before solving the equation. $\endgroup$