Construct Self-starting Nonlinear Models
Usage
selfStart(model, initial, parameters, template)
Arguments
model
|
a nonlinear formula object of the form ~expression .
|
initial
|
a function object, with three arguments: mCall ,
data , and LHS , representing, respectively, the
expression on the right hand side of model , a data frame in
which to interpret the variables in mCall and LHS , and
a name, or expression, representing the variable to be used as the
"response" in the initial values calculations. It should return
initial values for the parameters on the right hand side of
model .
|
parameters
|
a character vector specifying the terms on the right
hand side of model for which initial estimates should be
calculated. Passed as the namevec argument to the deriv
function.
|
template
|
an optional prototype for the calling sequence of the
returned object, passed as the function.arg argument to the
deriv function. By default, a template is generated with the
covariates in model coming first and the parameters in
model coming last in the calling sequence.
|
Description
A method for the generic function `selfStart' for formula objects.Value
a function object of class selfStart
, obtained by applying
deriv
to the right hand side of the model
formula. An
initial
attribute (defined by the initial
argument) is
added to the function to calculate starting estimates for the
parameters in the model automatically.Author(s)
Jose Pinheiro and Douglas BatesSee Also
selfStart.default
, deriv
Examples
## self-starting logistic model
SSlogis <- selfStart(~ Asym/(1 + exp((xmid - x)/scal)),
function(mCall, data, LHS)
{
xy <- sortedXyData(mCall[["x"]], LHS, data)
if(nrow(xy) < 4) {
stop("Too few distinct x values to fit a logistic")
}
z <- xy[["y"]]
if (min(z) <= 0) { z <- z + 0.05 * max(z) } # avoid zeroes
z <- z/(1.05 * max(z)) # scale to within unit height
xy[["z"]] <- log(z/(1 - z)) # logit transformation
aux <- coef(lm(x ~ z, xy))
parameters(xy) <- list(xmid = aux[1], scal = aux[2])
pars <- as.vector(coef(nls(y ~ 1/(1 + exp((xmid - x)/scal)),
data = xy, algorithm = "plinear")))
value <- c(pars[3], pars[1], pars[2])
names(value) <- mCall[c("Asym", "xmid", "scal")]
value
}, c("Asym", "xmid", "scal"))