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)
formula
| a symbolic description of the model to be fit. The details of model specification are given below. |
family
|
a description of the error distribution and link
function to be used in the model.
See family for details.
|
data
|
an optional data frame containing the variables
in the model. By default the variables are taken from
the environment which lm is called from.
|
weights
| an optional vector of weights to be used in the fitting process. |
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 NAs. The default action (na.omit)
is to omit any incomplete observations.
The alternative action na.fail causes lm to
print an error message and terminate if there are any incomplete
observations.
|
start
| starting values for the parameters in the linear predictor. |
etastart
| starting values for the linear predictor. |
offset
| this can be used to specify an a-priori known component to be included in the linear predictor during fitting. |
control
|
a list of parameters for controlling the fitting
process. See the documentation for glm.control for details.
|
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 (and presently only) method glm.fit
uses iteratively reweighted least squares.
|
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. |
glm is used to fit generalized linear models.
Models for glm are specified by giving
a symbolic description of the linear predictor and
a description of the error distribution.
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 models 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 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.
glm returns an object of class glm
which inherits from the class lm.
The function summary (i.e., summary.glm) can
be used to obtain or print a summary of the results and the function
anova (i.e., anova.glm)
to produce an analysis of variance table.
The generic accessor functions coefficients,
effects, fitted.values and residuals can be used to
extract various useful features of the value returned by glm.
anova.glm, summary.glm, etc. for
glm methods,
and the generic functions anova, summary,
effects, fitted.values,
and residuals. Further, lm for
non-generalized linear models.
## 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)