spaMM_glm.fit
is a stand-in replacement for glm.fit
, which can be called through glm
by using
glm(<>, method="spaMM_glm.fit")
. Input and output structure are exactly as for glm.fit
. It uses a Levenberg-Marquardt to prevent divergence of estimates. If the rcdd package is installed, the function can automatically find valid starting values or else indicate that no parameter value is feasible.
spaMM_glm
is a convenient wrapper, calling glm
with default method glm.fit
, then calling method spaMM_glm.fit
if glm.fit
failed.
spaMM_glm.fit(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL, mustart = NULL, offset = rep(0, nobs), family = gaussian(), control = list(maxit=200), intercept = TRUE)
spaMM_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, strict=FALSE, ...)
spaMM_glm
this can be a
character string naming a family function, a family function or the
result of a call to a family function. For spaMM_glm.fit
only the
third option is supported. (See family
for details of
family functions.)as.data.frame
to a data frame) containing
the variables in the model. If not found in data
, the
variables are taken from environment(formula)
,
typically the environment from which glm
is called.NULL
or a numeric vector.NA
s. The default is set by
the na.action
setting of options
, and is
na.fail
if that is unset. The factory-fresh
default is na.omit
. Another possible value is
NULL
, no action. Value na.exclude
can be useful.NULL
or a numeric vector of length equal to
the number of cases. One or more offset
terms can be
included in the formula instead or as well, and if more than one is
specified their sum is used. See model.offset
.glm.control
, as for glm.fit
.
Because one can assume that spaMM_glm.fit
will converge in many cases where glm.fit
does not, spaMM_glm.fit
allows more iterations (200) by default. However, if spaMM_glm.fit
is called through glm(. . ., method="spaMM_glm.fit")
, then the number of iterations is controlled by the glm.control
call within glm
, so that it is 25 by default, overriding the spaMM_glm.fit
default. spaMM_glm
in the firt attempt at fitting the model
(spaMM_glm.fit
being always used in a second attempt if the first failed).
The default method "glm.fit"
uses iteratively reweighted least squares
(IWLS): the alternative "model.frame"
returns the model frame
and does no fitting. User-supplied fitting functions can be supplied either as a function
or a character string naming a function, with a function which takes
the same arguments as glm.fit
. If specified as a character
string it is looked up from within the stats namespace.
spaMM_glm
: x
is a design matrix of dimension
n * p
, and y
is a vector of observations of length
n
.
For spaMM_glm.fit
: x
is a design matrix of dimension
n * p
, and y
is a vector of observations of length
n
.
contrasts.arg
of model.matrix.default
.spaMM_glm.fit
if glm.fit
returned the warning "glm.fit: algorithm did not converge"
.control
argument if it is not supplied directly.
glm
. See glm
for details.# glm() failures checked in R-devel version (2016-03-21 r70361)
x <- c(8.752,20.27,24.71,32.88,27.27,19.09)
y <- c(5254,35.92,84.14,641.8,1.21,47.2)
## Not run: # fails:
# glm(y~ x,data=data.frame(x,y),family=Gamma(log))
# ## End(Not run)
spaMM_glm(y~ x,data=data.frame(x,y),family=Gamma(log))
## Gamma(inverse) examples
x <- c(43.6,46.5,21.7,18.6,17.3,16.7)
y <- c(2420,708,39.6,16.7,46.7,10.8)
## Not run: # fails (can't find starting value)
# glm(y~ x,data=data.frame(x,y),family=Gamma())
# ## End(Not run)
if (require("rcdd",quietly=TRUE)) {
spaMM_glm(y~ x,data=data.frame(x,y),family=Gamma())
}
Run the code above in your browser using DataLab