glm.fit
Fit a GLM without Computing the Model Matrix
Description
Fits a glm model without computing the model matrix or the response vector.
Usage
glm.fit(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL,
mustart = NULL, offset = rep(0, nobs), family = gaussian(),
control = list(), intercept = TRUE)
Arguments
x |
a model matrix (design matrix).
|
y |
a response vector or object understood by family\$initialize.
|
weights |
optional prior weights. The default value is to set to a vector whose value is 1 and whose length is the row number of y(nobs).
|
start |
an optional vector. Used as the starting values for the parameters in the linear predictor.
Its length should equal the column number of x.
|
etastart |
an optional vector. Used as the starting values for the the linear predictor.
|
mustart |
optional. Used as the starting values for the vector of means.
|
offset |
optional offset added to the linear predictor. The default is a vector whose value is 0 and whose length is the row number of y(nobs).
|
family |
a family object, for example, as produced by binomial. (The default is gaussian.)
|
control |
a list. Used as the parameters in the control of the process of fitting.
|
intercept |
a logical flag. If TRUE (the default), an intercept is included.
|
Details
This function is useful for simulations or bootstrapping, where you use
the same data frame repeatedly.
Using glm.fit for bootstrapping
saves a large amount of computational time,
because it only fits a glm model and does not create the model matrix.
Thus, no formula needs to be specified as an argument.
The glm.fit function is called internally by glm
to do the actual model fitting.
The glm.fit function is the workhorse for glm, and it is named as
the default method in the definition of glm.
It receives x and y data rather than a formula, but it
still uses the family object to define the IRLS steps.
You can write your own version of glm.fit, and then pass the name of the
function via the method argument to glm.
Be careful to include as many of the arguments as feasible,
but definitely the ... argument, which absorbs any additional
arguments given in the call from glm.
Optionally, you can pass the name of the method as a "method"
attribute of the family argument.
For example, you can use this to define a cox family with the "method"
attribute "cox.fit", and glm automatically looks for a fitting
function cox.fit and uses it instead of glm.fit.
Value
returns a list object that is a subset of a glm object.
In particular, some of the extractor functions like summary.glm
produce appropriate output.
See Also
Examples
data(rock)
xrock <- cbind(1, rock[, c("peri", "shape", "perm")])
yrock <- rock[, "area"]
glmrock <- glm.fit(xrock, yrock, family=poisson())
coef(glmrock)
# Above result is the same as:
coef(glm(area ~ ., data=rock, family=poisson))