Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 Quantlet: linreg Description: Computes the Generalized Least Squares estimate for the coefficients of a linear model.

 Usage: {beta,bse,bstan,bpval} = linreg (x, y {,opt, 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 variables opt optional string vector, options are: "notext" - no text output is generated, "display" - a special display window is generated showing the results instead of the output window itself, "nointercept" - the intercept is not included in the estimation, "omega" - the covariance matrix "om" is specified. om optional n x n x d1 x ... x dn array, covariance matrix Output: beta p x 1 x d1 x ... x dn array, parameter estimates bse p x 1 x d1 x ... x dn array, standard errors of b bstan p x 1 x d1 x ... x dn array, standardized parameter estimates bpval p x 1 x d1 x ... x dn array, p-values corresponding to bstan

Note:
The estimate is given by b = INV(TRN(x) INV(om) x) TRN(x) INV(om) y, where the covariance matrix of the errors (sigma^2 * om) can be specified.

By default, an ANOVA table is shown in the output window. If it is not desired you can use the option "notext". In this case linreg only shows: the parameter estimates "b", the standard errors of the estimates "bse", the standardized estimate "bstan" and the respective p-values "bpval".

Example:
```library("stats")
setenv("outputstringformat", "%s")
randomize(1964)
n = 500
x = normal(n,3)
beta = #(10, 2, 3)
u = 0.5 * normal(n)
y = x*beta .+ u
{beta,se,betastan,p} = linreg(x,y)

```
Result:
```Contents of out
[ 1,]
[ 2,] A  N  O  V  A                   SS      df     MSS       F-test   P-value
[ 3,] _________________________________________________________________________
[ 4,] Regression                 61494.937     3 20498.312   80164.745   0.0000
[ 5,] Residuals                    126.828   496     0.256
[ 6,] Total Variation            61621.765   499   123.491
[ 7,]
[ 8,] Multiple R      = 0.99897
[ 9,] R^2             = 0.99794
[11,] Standard Error  = 0.50567
[12,]
[13,]
[14,] PARAMETERS         Beta         SE         StandB        t-test   P-value
[15,] ________________________________________________________________________
[16,] b[ 0,]=         -0.0058       0.0227       0.0000        -0.254   0.6001
[17,] b[ 1,]=         10.0019       0.0215       0.9501       465.977   0.0000
[18,] b[ 2,]=          1.9906       0.0221       0.1839        90.263   0.0000
[19,] b[ 3,]=          3.0249       0.0231       0.2667       130.817   0.0000
```
Example:
```library("stats")
randomize(1964)
n = 50
x = normal(n,3)
beta = #(10, 2, 3)
u = 0.5 * normal(n)
y = x*beta .+ u
covar =(0.5.*x[,2] .+ 0.3.*x[,3]+ 0.2*x[,1]).^2
y = x*beta .+ sqrt(covar).*u
{beta,se,betastan,p} = linreg(x, y,"nointercept"|"display"|"omega",diag(covar))

```
Result:
```You see the display:
A  N  O  V  A                   SS      df     MSS       F-test   P-value
_________________________________________________________________________
Regression                  4872.988     3  1624.329    8876.339   0.0000
Residuals                      8.601    47     0.183

R^2             = 0.98388
Standard Error  = 0.42778

PARAMETERS         Beta         SE
______________________________________
b[ 1,]=         10.0297       0.0637
b[ 2,]=          2.0544       0.0512
b[ 3,]=          2.9838       0.0698
```

Author: S. Hannappel, 20010721
(C) MD*TECH Method and Data Technologies, 05.02.2006