| glm {stats} | R Documentation |
glm is used to fit generalized linear models, specified by
giving a symbolic description of the linear predictor and a
description of the error distribution.
glm(formula, family = gaussian, data, weights, subset,
na.action, start = NULL, etastart, mustart, offset,
control = list(...), model = TRUE, method = "glm.fit",
x = FALSE, y = TRUE, contrasts = NULL, ...)
glm.fit(x, y, weights = rep(1, nobs),
start = NULL, etastart = NULL, mustart = NULL,
offset = rep(0, nobs), family = gaussian(),
control = list(), intercept = TRUE)
## S3 method for class 'glm'
weights(object, type = c("prior", "working"), ...)
formula |
an object of class |
family |
a description of the error distribution and link
function to be used in the model. This can be a character string
naming a family function, a family function or the result of a call
to a family function. (See |
data |
an optional data frame, list or environment (or object
coercible by |
weights |
an optional vector of ‘prior weights’ to be used
in the fitting process. Should be |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen
when the data contain |
start |
starting values for the parameters in the linear predictor. |
etastart |
starting values for the linear predictor. |
mustart |
starting values for the vector of means. |
offset |
this can be used to specify an a priori known
component to be included in the linear predictor during fitting.
This should be |
control |
a list of parameters for controlling the fitting
process. For |
model |
a logical value indicating whether model frame should be included as a component of the returned value. |
method |
the method to be used in fitting the model. The default
method User-supplied fitting functions can be supplied either as a function
or a character string naming a function, with a function which takes
the same arguments as |
x, y |
For For |
contrasts |
an optional list. See the |
intercept |
logical. Should an intercept be included in the null model? |
object |
an object inheriting from class |
type |
character, partial matching allowed. Type of weights to extract from the fitted model object. |
... |
For For |
A typical predictor has the form response ~ terms where
response is the (numeric) response vector and terms is a
series of terms which specifies a linear predictor for
response. For binomial and quasibinomial
families the response can also be specified as a factor
(when the first level denotes failure and all others success) or as a
two-column matrix with the columns giving the numbers of successes and
failures. A terms specification of the form first + second
indicates all the terms in first together with all the terms in
second with any duplicates removed.
A specification of the form first:second indicates the the set
of terms obtained by taking the interactions of all terms in
first with all terms in second. The specification
first*second indicates the cross of first and
second. This is the same as first + second +
first:second.
The terms in the formula will be re-ordered so that main effects come
first, followed by the interactions, all second-order, all third-order
and so on: to avoid this pass a terms object as the formula.
Non-NULL weights can be used to indicate that different
observations have different dispersions (with the values in
weights being inversely proportional to the dispersions); or
equivalently, when the elements of weights are positive
integers w_i, that each response y_i is the mean of
w_i unit-weight observations. For a binomial GLM prior weights
are used to give the number of trials when the response is the
proportion of successes: they would rarely be used for a Poisson GLM.
glm.fit is the workhorse function: it is not normally called
directly but can be more efficient where the response vector and
design matrix have already been calculated.
If more than one of etastart, start and mustart
is specified, the first in the list will be used. It is often
advisable to supply starting values for a quasi family,
and also for families with unusual links such as gaussian("log").
All of weights, subset, offset, etastart
and mustart are evaluated in the same way as variables in
formula, that is first in data and then in the
environment of formula.
For the background to warning messages about ‘fitted probabilities numerically 0 or 1 occurred’ for binomial GLMs, see Venables & Ripley (2002, pp. 197–8).
glm returns an object of class inheriting from "glm"
which inherits from the class "lm". See later in this section.
If a non-standard method is used, the object will also inherit
from the class (if any) returned by that function.