I'm getting wildly different answers when I calculate the t-statistic manually vs the t-stat shown in the regression summary. Any ideas how to fix it?
x1 = runif(4000, min = 0, max = 1)
x2 = runif(4000, min = 0, max = 1)
y <- 1x1 - 2x2 + rnorm(4000)
X = cbind(x1,x2)
Manually find OLS estimators
estimators <- solve(t(X)%%X)%%t(X)%*%y
> estimators
[,1]
x1 1.020039
x2 -2.012627
Manually find tstat for x2
> -2.012627 / (sd(x2)/sqrt(length(x2)))
[1] -441.7463
tstat from regression
reg1 = lm(y ~ ., data = yx)
summary(reg1)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.01027 0.04225 -0.243 0.808
x1 1.02882 0.05516 18.653 <2e-16 ***
x2 -2.00394 0.05523 -36.284 <2e-16 ***
(sd(x2)/sqrt(length(x2)))? – Henry Sep 03 '22 at 23:16x2but that may not be what you want here – Henry Sep 04 '22 at 00:53lm()will include an intercept unless you tell it not to, for instance like this:lm(y ~ 0 + x1 + x2)– civilstat Sep 06 '22 at 01:16