0
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?

Sven Hohenstein
  • 6,285
  • 25
  • 30
  • 39
  • 1
    Welcome to CV. Since you’re new here, you may want to take our [tour], which has information for new users. Questions focusing on *programming, debugging, or performing routine operations within a statistical computing platform* are [off-topic](http://stats.stackexchange.com/help/on-topic) here. Still, what you are doing is basically estimating the same model without the intercept (see yourself `lm(y~x -1)`). Use `model.matrix()` function before solving the equation. – T.E.G. Aug 18 '17 at 07:51

1 Answers1

2

The results differ because you didn't include the intercept:

lm(y ~ 0 + x)
## 
## Call:
## lm(formula = y ~ 0 + x)
## 
## Coefficients:
##      x  
## 0.4287 

or

X <- cbind(Intercept = 1, x)
solve(t(X) %*% X) %*% (t(X) %*% y)
##                  [,1]
## Intercept -38.4550871
## x           0.6746104 

This has nothing to do with econometrics and I doubt any econometrics handbook or course recommends not including intercept as it is a bad practice.

Tim
  • 108,699
  • 20
  • 212
  • 390