\Header{glm}{Fitting Generalized Linear Models}
\alias{glm.control}{glm}
\alias{glm.fit}{glm}
\alias{glm.fit.null}{glm}
\keyword{models}{glm}
\keyword{regression}{glm}
\begin{Usage}
\begin{verbatim}
glm(formula, family=gaussian, data, weights=NULL, subset=NULL,
        na.action=na.fail, start=NULL, offset=NULL,
        control=glm.control(epsilon=0.0001, maxit=10, trace=FALSE),
        model = TRUE, method = "glm.fit", x = FALSE, y = TRUE)
glm.control(epsilon=0.0001, maxit=10, trace=FALSE)
glm.fit(x, y, weights=rep(1, nrow(x)),
        start=NULL, etastart = NULL, offset=rep(0, nrow(x)),
        family=gaussian(), control=glm.control(),
        intercept=TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{formula}] a symbolic description of the model to be fit.
The details of model specification are given below.
\item[\texttt{family}] a description of the error distribution and link
function to be used in the model.
See \texttt{\Link{family}} for details.
\item[\texttt{data}] an optional data frame containing the variables
in the model.  By default the variables are taken from
the environment which \texttt{lm} is called from.
\item[\texttt{weights}] an optional vector of weights to be used
in the fitting process.
\item[\texttt{subset}] an optional vector specifying a subset of observations
to be used in the fitting process.
\item[\texttt{na.action}] a function which indicates what should happen
when the data contain \texttt{NA}s.  The default action (\texttt{na.omit})
is to omit any incomplete observations.
The alternative action \texttt{na.fail} causes \texttt{lm} to
print an error message and terminate if there are any incomplete
observations.
\item[\texttt{start}] starting values for the parameters in the
linear predictor.
\item[\texttt{etastart}] starting values for the linear predictor.
\item[\texttt{offset}] this can be used to specify an a-priori
known component to be included in the linear predictor
during fitting.
\item[\texttt{control}] a list of parameters for controlling the fitting
process.  See the documentation for \texttt{\Link{glm.control}} for details.
\item[\texttt{model}] a logical value indicating whether \emph{model frame}
should be included as a component of the returned value.
\item[\texttt{method}] the method to be used in fitting the model.
The default (and presently only) method \texttt{glm.fit}
uses iteratively reweighted least squares.
\item[\texttt{x,y}] logical values indicating whether the response
vector and design matrix used in the fitting process
should be returned as components of the returned value.
\end{ldescription}
\end{Arguments}
\begin{Description}
\texttt{glm} is used to fit generalized linear models.

Models for \texttt{glm} are specified by giving
a symbolic description of the linear predictor and
a description of the error distribution.\end{Description}
\begin{Details}
A typical predictor has the form \texttt{response $\,\tilde{\,}$ terms} where
\texttt{response} is the (numeric) response vector and \texttt{terms} is a
series of terms which specifies a linear predictor for \texttt{response}.
For \texttt{binomial} models the response can also be specified as a
\texttt{\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
\texttt{first+second} indicates all the terms in \texttt{first} together
with all the terms in \texttt{second} with duplicates removed.

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

The generic accessor functions \texttt{\Link{coefficients}},
\texttt{effects}, \texttt{fitted.values} and \texttt{residuals} can be used to
extract various useful features of the value returned by \texttt{glm}.\end{Value}
\begin{SeeAlso}
\texttt{\Link{anova.glm}}, \texttt{\Link{summary.glm}}, etc. for
\texttt{glm} methods,
and the generic functions \texttt{\Link{anova}}, \texttt{\Link{summary}},
\texttt{\Link{effects}}, \texttt{\Link{fitted.values}},
and \texttt{\Link{residuals}}. Further, \texttt{\Link{lm}} for
non-generalized \emph{linear} models.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## Annette Dobson (1990) "An Introduction to Statistical Modelling".
## 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)

## Annette Dobson (1990) "An Introduction to Statistical Modelling".
## 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)

## Annette Dobson (1990) "An Introduction to Statistical Modelling".
## 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)

## Annette Dobson (1990) "An Introduction to Statistical Modelling".
## 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}

