\Header{glm}{Fitting Generalized Linear Models}
\methalias{glm.control}{glm}
\methalias{glm.fit}{glm}
\alias{glm.fit.null}{glm}
\keyword{models}{glm}
\keyword{regression}{glm}
\begin{Description}\relax
\code{glm} is used to fit generalized linear models.

Models for \code{glm} are specified by giving
a symbolic description of the linear predictor and
a description of the error distribution.\end{Description}
\begin{Usage}
\begin{verbatim}
glm(formula, family = gaussian, data, weights = NULL, subset = NULL,
    na.action, start = NULL, offset = NULL,
    control = glm.control(epsilon=0.0001, maxit=10, trace=FALSE),
    model = TRUE, method = "glm.fit", x = FALSE, y = TRUE,
    contrasts = NULL, ...)
glm.control(epsilon = 0.0001, maxit = 10, trace = FALSE)
glm.fit(x, y, weights = rep(1, nrow(x)),
        start = NULL, etastart  =  NULL, mustart = NULL,
        offset = rep(0, nrow(x)),
        family = gaussian(), control = glm.control(),
        intercept = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{formula}] a symbolic description of the model to be fit.
The details of model specification are given below.
\item[\code{family}] a description of the error distribution and link
function to be used in the model.
See \code{\Link{family}} for details.
\item[\code{data}] an optional data frame containing the variables
in the model.  By default the variables are taken from
the environment ffrom which \code{glm} is called.
\item[\code{weights}] an optional vector of weights to be used
in the fitting process.
\item[\code{subset}] an optional vector specifying a subset of observations
to be used in the fitting process.
\item[\code{na.action}] a function which indicates what should happen
when the data contain \code{NA}s.  The default is set by
the \code{na.action} setting of \code{\Link{options}}, and is
\code{\Link{na.fail}} if that is unset.  The ``factory-fresh''
default is \code{\Link{na.omit}}.
\item[\code{start}] starting values for the parameters in the linear predictor.
\item[\code{etastart}] starting values for the linear predictor.
\item[\code{mustart}] starting values for the vector of means.
\item[\code{offset}] this can be used to specify an \emph{a priori}
known component to be included in the linear predictor
during fitting.
\item[\code{control}] a list of parameters for controlling the fitting
process.  See the documentation for \code{\Link{glm.control}} for details.
\item[\code{model}] a logical value indicating whether \emph{model frame}
should be included as a component of the returned value.
\item[\code{method}] the method to be used in fitting the model.
The default (and presently only) method \code{glm.fit}
uses iteratively reweighted least squares.
\item[\code{x, y}] logical values indicating whether the response
vector and model matrix used in the fitting process
should be returned as components of the returned value.
\item[\code{contrasts}] an optional list. See the \code{contrasts.arg}
of \code{model.matrix.default}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
A typical predictor has the form \code{response $\,\tilde{\,}$ terms} where
\code{response} is the (numeric) response vector and \code{terms} is a
series of terms which specifies a linear predictor for \code{response}.
For \code{binomial} models the response can also be specified as a
\code{\Link{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
\code{first+second} indicates all the terms in \code{first} together
with all the terms in \code{second} with duplicates removed.

A specification of the form \code{first:second} indicates the
the set of terms obtained by taking the interactions of
all terms in \code{first} with all terms in \code{second}.
The specification \code{first*second} indicates the \emph{cross}
of \code{first} and \code{second}.
This is the same as \code{first+second+first:second}.\end{Details}
\begin{Value}
\code{glm} returns an object of class \code{glm}
which inherits from the class \code{lm}.
The function \code{\Link{summary}} (i.e., \code{\Link{summary.glm}}) can
be used to obtain or print a summary of the results and the function
\code{\Link{anova}} (i.e., \code{\Link{anova.glm}})
to produce an analysis of variance table.

The generic accessor functions \code{\Link{coefficients}},
\code{effects}, \code{fitted.values} and \code{residuals} can be used to
extract various useful features of the value returned by \code{glm}.\end{Value}
\begin{Note}\relax
Offsets specified by \code{offset} will not be included in predictions
by \code{\Link{predict.glm}}, whereas those specified by an offset term
in the formula will be.\end{Note}
\begin{SeeAlso}\relax
\code{\Link{anova.glm}}, \code{\Link{summary.glm}}, etc. for
\code{glm} methods,
and the generic functions \code{\Link{anova}}, \code{\Link{summary}},
\code{\Link{effects}}, \code{\Link{fitted.values}},
and \code{\Link{residuals}}. Further, \code{\Link{lm}} for
non-generalized \emph{linear} models.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
print(d.AD <- data.frame(treatment, outcome, counts))
glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
anova(glm.D93)
summary(glm.D93)

## an example with offsets from Venables & Ripley (1999, pp.217-8)


 ## Need the anorexia data from a 1999 version of the package MASS:
 library(MASS)
 data(anorexia)

anorex.1 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
            family = gaussian, data = anorexia)
summary(anorex.1)

\end{ExampleCode}
\end{Examples}

