Generalized linear model regression
b = glmfit(X,y,
distr
)
b = glmfit(X,y,distr
,param1
,val1
,param2
,val2
,...)
[b,dev] = glmfit(...)
[b,dev,stats] = glmfit(...)
b = glmfit(X,y,
returns
a (p + 1)-by-1 vector distr
)b
of coefficient
estimates for a generalized linear regression of the responses in y
on
the predictors in X
, using the distribution
. distr
X
is
an n-by-p matrix of p predictors
at each of n observations. distr
can
be any of the following: 'binomial'
, 'gamma'
, 'inverse
gaussian'
, 'normal'
(the default), and 'poisson'
.
In most cases, y
is an n-by-1
vector of observed responses. For the binomial distribution, y
can
be a binary vector indicating success or failure at each observation,
or a two column matrix with the first column indicating the number
of successes for each observation and the second column indicating
the number of trials for each observation.
This syntax uses the canonical link (see below) to relate the distribution to the predictors.
By default, glmfit
adds a first column of
1s to X
, corresponding to a constant term in the
model. Do not enter a column of 1s directly into X
.
You can change the default behavior of glmfit
using
the 'constant'
parameter, below.
glmfit
treats NaN
s in
either X
or y
as missing values,
and ignores them.
b = glmfit(X,y,
additionally
allows you to specify optional parameter name/value pairs to control
the model fit. Acceptable parameters are as follows.distr
,param1
,val1
,param2
,val2
,...)
Parameter | Value | Description |
---|---|---|
'link' |
| µ = Xb |
| log(µ) = Xb | |
| log(µ/(1 – µ)) = Xb | |
'probit' | norminv(µ) = Xb | |
'comploglog' | log( -log(1 – µ)) = Xb | |
'reciprocal' , default for the distribution 'gamma' | 1/µ = Xb | |
| log( -log(µ)) = Xb | |
| µ^{p} = Xb | |
cell array of the form | Custom-defined link function. You must provide
| |
structure array having these fields:
The value of each field is a character vector corresponding
to a function that is on the path or a function handle (created using | Custom-defined link function, its derivative, and its inverse. | |
'estdisp' | 'on' | Estimates a dispersion parameter for the binomial or Poisson distribution. |
| Uses the theoretical value of 1.0 for those distributions. | |
'offset' | Vector | Used as an additional predictor variable, but with a coefficient value fixed at 1.0. |
'weights' | Vector of prior weights, such as the inverses of the relative variance of each observation | |
'constant' |
| Includes a constant term in the model. The coefficient
of the constant term is the first element of |
'off' | Omit the constant term. |
[b,dev] = glmfit(...)
returns dev
,
the deviance of the fit at the solution vector. The deviance is a
generalization of the residual sum of squares. It is possible to perform
an analysis of deviance to compare several models, each a subset of
the other, and to test whether the model with more terms is significantly
better than the model with fewer terms.
[b,dev,stats] = glmfit(...)
returns dev
and stats
.
stats
is a structure with the following fields:
beta
— Coefficient estimates b
dfe
— Degrees of freedom
for error
sfit
— Estimated dispersion
parameter
s
— Theoretical or estimated
dispersion parameter
estdisp
— 0 when the 'estdisp'
name-value
pair argument value is 'off'
and 1 when the 'estdisp'
name-value
pair argument value is 'on'
.
covb
— Estimated covariance
matrix for B
se
— Vector of standard
errors of the coefficient estimates b
coeffcorr
— Correlation
matrix for b
t
— t statistics
for b
p
— p-values
for b
resid
— Vector of residuals
residp
— Vector of Pearson
residuals
residd
— Vector of deviance
residuals
resida
— Vector of Anscombe
residuals
If you estimate a dispersion parameter for the binomial or Poisson
distribution, then stats.s
is set equal to stats.sfit
.
Also, the elements of stats.se
differ by the factor stats.s
from
their theoretical values.
[1] Dobson, A. J. An Introduction to Generalized Linear Models. New York: Chapman & Hall, 1990.
[2] McCullagh, P., and J. A. Nelder. Generalized Linear Models. New York: Chapman & Hall, 1990.
[3] Collett, D. Modeling Binary Data. New York: Chapman & Hall, 2002.
GeneralizedLinearModel
| fitglm
| glmval
| regress
| regstats
| stepwiseglm