Library: | xplore |
See also: | linreg glmest glmstat |
Quantlet: | gls | |
Description: | Computes the Generalized Least Squares estimate for the coefficients of a linear model when the errors have a positive definite covariance matrix om. |
Usage: | b = gls (x, y{, om}) | |
Input: | ||
x | n x p x d1 x ... x dn array, explanatory variables | |
y | n x 1 x d1 x ... x dn array, dependent variable | |
om | optional, n x n x d1 x ... x dn array, covariance matrix | |
Output: | ||
b | p x 1 x d1 x ... x dn array, GLS estimates |
library("plot") ; load libraries library("stats") x=read("nicfoo") ; read data xd = matrix(rows(x)) ~ x[,1] ~ x[,1]^2 yd = x[,2] b = gls(xd, yd) ; OLS eps = yd - xd * b ; calculate residuals sh = sknn(x[,1],eps^2,5) ; smooth the variance om = diag(sh) ; create covariance matrix bg = gls(xd, yd, om) ; GLS with om b ~ bg ; OLS vs. GLS
Contents of _tmp [1,] 0.11264 0.11975 [2,] 1.2295 1.2065 [3,] -0.25594 -0.24865