When I run this code:
require(nlme)
a <- matrix(c(1,3,5,7,4,5,6,4,7,8,9))
b <- matrix(c(3,5,6,2,4,6,7,8,7,8,9))
res <- lm(a ~ b)
print(summary(res))
res_gls <- gls(a ~ b)
print(summary(res_gls))
I get the same coefficients and the same statistical significance on the coefficients:
Loading required package: nlme
Call:
lm(formula = a ~ b)
Residuals:
Min 1Q Median 3Q Max
-2.7361 -1.1348 -0.2955 1.2463 3.8234
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.0576 1.8732 1.098 0.3005
b 0.5595 0.2986 1.874 0.0937 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.088 on 9 degrees of freedom
Multiple R-squared: 0.2807, Adjusted R-squared: 0.2007
F-statistic: 3.512 on 1 and 9 DF, p-value: 0.09371
Generalized least squares fit by REML
Model: a ~ b
Data: NULL
AIC BIC logLik
51.0801 51.67177 -22.54005
Coefficients:
Value Std.Error t-value p-value
(Intercept) 2.0576208 1.8731573 1.098477 0.3005
b 0.5594796 0.2985566 1.873948 0.0937
Correlation:
(Intr)
b -0.942
Standardized residuals:
Min Q1 Med Q3 Max
-1.3104006 -0.5434780 -0.1415446 0.5968911 1.8311781
Residual standard error: 2.087956
Degrees of freedom: 11 total; 9 residual
Why is this happening? In what cases do OLS estimates are the same as GLS estimates?
correlation
orweights
within thegls
function, the results from GLS are equal to those fromlm
. $\endgroup$gls
to act likelm
. Another question is what I should put forcorrelation
andweights
. $\endgroup$