Learn R Programming

mosaic (version 1.9.1)

fitModel: Fit a nonlinear least squares model

Description

Allows you to specify a formula with parameters, along with starting guesses for the parameters. Refines those guesses to find the least-squares fit.

Usage

fitModel(formula, data = parent.frame(), start = list(), ...)

model(object, ...)

# S3 method for nlsfunction model(object, ...)

# S3 method for nlsfunction summary(object, ...)

# S3 method for nlsfunction coef(object, ...)

Value

a function

Arguments

formula

formula specifying the model

data

dataframe containing the data to be used

start

passed as start to nls(). If and empty list, a simple starting point is used (thus avoiding the usual warning message).

...

additional arguments passed to nls()

object

an R object (typically a the result of fitModel)

Details

Fits a nonlinear least squares model to data. In contrast to linear models, all the parameters (including linear ones) need to be named in the formula. The function returned simply contains the formula together with pre-assigned arguments setting the parameter value. Variables used in the fitting (as opposed to parameters) are unassigned arguments to the returned function.

See Also

linearModel(), nls()

Examples

Run this code
if (require(mosaicData)) {
f <- fitModel(temp ~ A+B*exp(-k*time), data=CoolingWater, start=list(A=50,B=50,k=1/20))
f(time=50)
coef(f)
summary(f)
model(f)
}

Run the code above in your browser using DataLab