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 algorithm 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
, with possibly different initial values, 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, singular.ok = TRUE)
spaMM_glm(formula, family = gaussian, data, weights, subset,
na.action, start = NULL, etastart, mustart, offset,
control = list(...), model = TRUE, method = c("glm.fit","spaMM_glm.fit"),
x = FALSE, y = TRUE, singular.ok = TRUE, contrasts = NULL, strict=FALSE, ...)
a description of the error distribution and link
function to be used in the model. For 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.)
an optional data frame, list or environment (or object
coercible by 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.
an optional vector of ‘prior weights’ to be used
in the fitting process. Should be NULL
or a numeric vector.
an optional vector specifying a subset of observations to be used in the fitting process.
a function which indicates what should happen
when the data contain 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.
starting values for the parameters in the linear predictor.
starting values for the linear predictor.
starting values for the vector of means.
this can be used to specify an a priori known
component to be included in the linear predictor during fitting.
This should be 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
.
a list of parameters for controlling the fitting
process. This is passed to 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.
a logical value indicating whether model frame should be included as a component of the returned value.
A 2-elements vector specifying first the method to be used by spaMM_glm
in the firt attempt at fitting the model, second the method to be used in a second attempt if the first failed. Possible methods include those shown in the default, "model.frame"
, which returns the model frame and does no fitting, or user-supplied fitting functions. These 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
.
For 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
.
logical; if FALSE
a singular fit is an error.
an optional list. See the contrasts.arg
of model.matrix.default
.
logical. Should an intercept be included in the null model?
logical. Whether to perform a fit by spaMM_glm.fit
if glm.fit
returned the warning "glm.fit: algorithm did not converge"
.
arguments to be used to form the default
control
argument if it is not supplied directly.
An object inheriting from class glm
. See glm
for details.
# NOT RUN {
# glm() failures last checked in R-devel version (2018-01-06 r74073)
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))
# }
# 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())
# }
# NOT RUN {
if (requireNamespace("rcdd",quietly=TRUE)) {
spaMM_glm(y~ x,data=data.frame(x,y),family=Gamma())
}
# }
Run the code above in your browser using DataLab