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, ...)
formula | a formula expression as for other regression models, of the form response ~ predictors. For details, see the documentation for lm and formula. See the DETAILS section for special forms the response variable can take in logistic regression. |
family |
a family object. This is a list of expressions for defining the link,
variance function, initialization values,
and iterative weights for the generalized linear model.
Supported families are
|
data | an environment, data.frame, or list in which to look up the names occurring in the formula. The default value is the environment in which the formula was constructed, environment(formula). If names of variables or functions in the formula cannot be found in data, then we look for them in the environment from which glm was called. |
weights | the weights for the fitting criterion. By default, all observations are weighted equally. |
subset | an expression defining which subset of the rows in the data to use in the fit. This can be a logical vector, which is replicated to have a length equal to the number of observations, a numeric vector indicating which observation numbers to include, or a character vector of the row names to include. By default, all observations are included. |
na.action | a function or the name of a function to handle missing values in the data. This is applied to the model.frame of variables used in the model after any subset argument is used. The default value is taken from the global options vector, getOption("na.action"). na.action="na.exclude" deletes observations that contain one or more missing values. (Note that it attaches information about where the missing values were so predict and residuals can return results that line up with the original data.) A possible alternative is "na.fail", which creates an error if any missing values are found. |
start | a vector of initial values on the scale of the linear predictor. This vector is passed to glm.fit as an argument. This argument is useful in rare cases where the default starting values pose convergence problems to the underlying algorithm. For more information, see Chambers and Hastie (1993). |
etastart | an optional vector passed to glm.fit. It is used as the starting values for the the linear predictor. |
mustart | an optional vector passed to glm.fit. It is used as the starting values for the vector of means. |
offset | an optional offset passed to glm.fit. It is added to the linear predictor. |
control | a list of iteration and algorithmic constants. See glm.control for their names and default values. These can also be given directly as arguments to glm itself, instead of through control. |
model | a logical flag. If TRUE (the default), indicates that the model.frame is returned as a component of the glm object list(names as model). |
method | the method to use in fitting the model. By default, the function glm.fit is used and the model is fit via iteratively reweighted least squares. An alternative fitting method can be model.frame; however, other fitting methods can be defined by the user. See Chambers and Hastie (1993), pages 245 to 246 for more information. |
x | a logical flag. If TRUE, the model.matrix is returned as a component of glm object list(names as x). By default, it is FALSE. |
y | a logical flag. If TRUE (the default), the response variable is returned as a component of glm object list(names as y). |
contrasts |
a list of contrasts to use for some or all of the factors
appearing as variables in the model formula.
|
... | additional arguments are passed to generate list for control argument if it is given with list(...). |
Note | The weights are not interpreted as counts. This does not affect predictions or coefficients estimated by the model, but degrees of freedom and standard errors are calculated as if the number of observations is length(weights) rather than sum(weights). | |
fit1 <- glm(ozone ~ radiation + poly(wind, temperature, degree = 2), data = Sdatasets::air)# Poisson regression. glm(skips ~ ., family=poisson, data=Sdatasets::solder.balance)
# Binomial. ldose <- rep(0:5, 2) numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) sex <- factor(rep(c("M", "F"), c(6, 6))) SF <- cbind(numdead, numalive = 20 - numdead) budworm.lg <- glm(SF ~ sex*ldose, family=binomial) summary(budworm.lg, correlation=FALSE)