Mercurial > hg > octave-nkf
annotate scripts/statistics/base/gls.m @ 9211:f0c3d3fc4903
Simplify Texinfo documentation in .m scripts by removing redundant @iftex calls
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 17 May 2009 14:39:39 -0700 |
parents | eb63fbe60fab |
children | e151e23f73bc |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 1997, 1998, 1999, 2000, 2005, 2006, 2007, 2009 |
7017 | 2 ## John W. Eaton |
3200 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3200 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3381 | 20 ## -*- texinfo -*- |
3368 | 21 ## @deftypefn {Function File} {[@var{beta}, @var{v}, @var{r}] =} gls (@var{y}, @var{x}, @var{o}) |
22 ## Generalized least squares estimation for the multivariate model | |
23 ## @tex | |
24 ## $y = x b + e$ | |
25 ## with $\bar{e} = 0$ and cov(vec($e$)) = $(s^2)o$, | |
26 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
27 ## @ifnottex |
3499 | 28 ## @math{y = x b + e} with @math{mean (e) = 0} and |
29 ## @math{cov (vec (e)) = (s^2) o}, | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
30 ## @end ifnottex |
3368 | 31 ## where |
3426 | 32 ## @tex |
3368 | 33 ## $y$ is a $t \times p$ matrix, $x$ is a $t \times k$ matrix, $b$ is a $k |
34 ## \times p$ matrix, $e$ is a $t \times p$ matrix, and $o$ is a $tp \times | |
35 ## tp$ matrix. | |
36 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
37 ## @ifnottex |
3499 | 38 ## @math{y} is a @math{t} by @math{p} matrix, @math{x} is a @math{t} by |
39 ## @math{k} matrix, @math{b} is a @math{k} by @math{p} matrix, @math{e} | |
40 ## is a @math{t} by @math{p} matrix, and @math{o} is a @math{t p} by | |
41 ## @math{t p} matrix. | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
42 ## @end ifnottex |
3426 | 43 ## |
3368 | 44 ## @noindent |
3499 | 45 ## Each row of @var{y} and @var{x} is an observation and each column a |
46 ## variable. The return values @var{beta}, @var{v}, and @var{r} are | |
47 ## defined as follows. | |
3426 | 48 ## |
3368 | 49 ## @table @var |
50 ## @item beta | |
3499 | 51 ## The GLS estimator for @math{b}. |
3426 | 52 ## |
3368 | 53 ## @item v |
3499 | 54 ## The GLS estimator for @math{s^2}. |
3426 | 55 ## |
3368 | 56 ## @item r |
3499 | 57 ## The matrix of GLS residuals, @math{r = y - x beta}. |
3368 | 58 ## @end table |
59 ## @end deftypefn | |
3200 | 60 |
61 ## Author: Teresa Twaroch <twaroch@ci.tuwien.ac.at> | |
62 ## Created: May 1993 | |
63 ## Adapted-By: jwe | |
64 | |
65 function [BETA, v, R] = gls (Y, X, O) | |
66 | |
67 if (nargin != 3) | |
6046 | 68 print_usage (); |
3200 | 69 endif |
70 | |
71 [rx, cx] = size (X); | |
72 [ry, cy] = size (Y); | |
73 if (rx != ry) | |
74 error ("gls: incorrect matrix dimensions"); | |
75 endif | |
76 | |
77 O = O^(-1/2); | |
78 Z = kron (eye (cy), X); | |
79 Z = O * Z; | |
80 Y1 = O * reshape (Y, ry*cy, 1); | |
81 U = Z' * Z; | |
82 r = rank (U); | |
83 | |
84 if (r == cx*cy) | |
85 B = inv (U) * Z' * Y1; | |
86 else | |
87 B = pinv (Z) * Y1; | |
88 endif | |
89 | |
90 BETA = reshape (B, cx, cy); | |
91 R = Y - X * BETA; | |
92 v = (reshape (R, ry*cy, 1))' * (O^2) * reshape (R, ry*cy, 1) / (rx*cy - r); | |
93 | |
94 endfunction |