comparison scripts/statistics/models/logistic_regression.m @ 3454:d8b731d3f7a3

[project @ 2000-01-18 10:13:31 by jwe]
author jwe
date Tue, 18 Jan 2000 10:13:39 +0000
parents f8dde1807dee
children 434790acb067
comparison
equal deleted inserted replaced
3453:71d2e09c15a2 3454:d8b731d3f7a3
12 ## 12 ##
13 ## You should have received a copy of the GNU General Public License 13 ## You should have received a copy of the GNU General Public License
14 ## along with this file. If not, write to the Free Software Foundation, 14 ## along with this file. If not, write to the Free Software Foundation,
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 16
17 ## Performs ordinal logistic regression. 17 ## -*- texinfo -*-
18 ## @deftypefn {Functio File} {[@var{theta}, @var{beta}, @var{dev}, @var{dl}, @var{d2l}, @var{p}] =} logistic_regression (@var{y}, @var{x}, @var{print}, @var{theta}, @var{beta})
19 ## Perform ordinal logistic regression.
18 ## 20 ##
19 ## Suppose Y takes values in k ordered categories, and let gamma_i (x) 21 ## Suppose @var{y} takes values in @var{k} ordered categories, and let
20 ## be the cumulative probability that Y falls in one of the first i 22 ## @code{gamma_i (@var{x})} be the cumulative probability that @var{y}
21 ## categories given the covariate x. Then 23 ## falls in one of the first @var{i} categories given the covariate
22 ## [theta, beta] = 24 ## @var{x}. Then
23 ## logistic_regression (y, x) 25 ##
26 ## @example
27 ## [theta, beta] = logistic_regression (y, x)
28 ## @end example
29 ##
30 ## @noindent
24 ## fits the model 31 ## fits the model
25 ## logit (gamma_i (x)) = theta_i - beta' * x, i = 1, ..., k-1.
26 ## The number of ordinal categories, k, is taken to be the number of
27 ## distinct values of round (y) . If k equals 2, y is binary and the
28 ## model is ordinary logistic regression. X is assumed to have full
29 ## column rank.
30 ## 32 ##
31 ## theta = logistic_regression (y) 33 ## @example
34 ## logit (gamma_i (x)) = theta_i - beta' * x, i = 1, ..., k-1
35 ## @end example
36 ##
37 ## The number of ordinal categories, @var{k}, is taken to be the number
38 ## of distinct values of @code{round (@var{y})}. If @var{k} equals 2,
39 ## @var{y} is binary and the model is ordinary logistic regression. The
40 ## matrix @var{x} is assumed to have full column rank.
41 ##
42 ## Given @var{y} only, @code{theta = logistic_regression (y)}
32 ## fits the model with baseline logit odds only. 43 ## fits the model with baseline logit odds only.
33 ## 44 ##
34 ## The full form is 45 ## The full form is
35 ## [theta, beta, dev, dl, d2l, gamma] =
36 ## logistic_regression (y, x, print, theta, beta)
37 ## in which all output arguments and all input arguments except y are
38 ## optional.
39 ## 46 ##
40 ## print = 1 requests summary information about the fitted model to be 47 ## @example
41 ## displayed; print = 2 requests information about convergence at each 48 ## [theta, beta, dev, dl, d2l, gamma]
42 ## iteration. Other values request no information to be displayed. The 49 ## = logistic_regression (y, x, print, theta, beta)
43 ## input arguments `theta' and `beta' give initial estimates for theta 50 ## @end example
44 ## and beta.
45 ## 51 ##
46 ## `dev' holds minus twice the log-likelihood. 52 ## @noindent
53 ## in which all output arguments and all input arguments except @var{y}
54 ## are optional.
47 ## 55 ##
48 ## `dl' and `d2l' are the vector of first and the matrix of second 56 ## Stting @var{print} to 1 requests summary information about the fitted
49 ## derivatives of the log-likelihood with respect to theta and beta. 57 ## model to be displayed. Setting @var{print} to 2 requests information
58 ## about convergence at each iteration. Other values request no
59 ## information to be displayed. The input arguments @var{theta} and
60 ## @var{beta} give initial estimates for @var{theta} and @var{beta}.
50 ## 61 ##
51 ## `p' holds estimates for the conditional distribution of Y given x. 62 ## The returned value @var{dev} holds minus twice the log-likelihood.
63 ##
64 ## The returned values @var{dl} and @var{d2l} are the vector of first
65 ## and the matrix of second derivatives of the log-likelihood with
66 ## respect to @var{theta} and @var{beta}.
67 ##
68 ## @var{p} holds estimates for the conditional distribution of @var{y}
69 ## given @var{x}.
70 ## @end deftypefn
52 71
53 ## Original for MATLAB written by Gordon K Smyth <gks@maths.uq.oz.au>, 72 ## Original for MATLAB written by Gordon K Smyth <gks@maths.uq.oz.au>,
54 ## U of Queensland, Australia, on Nov 19, 1990. Last revision Aug 3, 73 ## U of Queensland, Australia, on Nov 19, 1990. Last revision Aug 3,
55 ## 1992. 74 ## 1992.
56 75
60 79
61 ## Uses the auxiliary functions logistic_regression_derivatives and 80 ## Uses the auxiliary functions logistic_regression_derivatives and
62 ## logistic_regression_likelihood. 81 ## logistic_regression_likelihood.
63 82
64 function [theta, beta, dev, dl, d2l, p] ... 83 function [theta, beta, dev, dl, d2l, p] ...
65 = logistic_regression (y, x, print, theta, beta) 84 = logistic_regression (y, x, print, theta, beta)
66 85
67 ## check input 86 ## check input
68 y = round (vec (y)); 87 y = round (vec (y));
69 [my, ny] = size (y); 88 [my, ny] = size (y);
70 if (nargin < 2) 89 if (nargin < 2)