Learn R Programming

soundcorrs (version 0.4.0)

multiFit: Fit multiple models to one dataset.

Description

Apply a fitting function, with multiple models and multiple starting estimates, to one dataset.

Usage

multiFit(models, data, fun = nls, ...)

Arguments

models

[list] A list of models to fit data to. Each element must be a list with at least two named fields: formula which contains the formula, and start which is a list of lists of starting estimates.

data

[numeric data.frame/list] A list of vectors to fit models to.

fun

[function] The function to use for fitting. Defaults to nls.

...

Additional arguments passed to fun.

Value

[list.multiFit] A list of results returned by fun or, if it ended with an error, NULL.

Details

Finding the right model and the right starting estimates for a model is often a time consuming process, very inconvenient to do manually. This function automates it as much as possible. It takes a list of models and starting estimates, and fits them to data not stopping whenever an error occurs or a warning is issued. Error and warning messages are saved and can be inspected in the output, they just do not halt the process. multiFit has an extension in the form of fitTable which applies multiple models to multiple datasets.

See Also

fitTable, summary.list.multiFit

Examples

Run this code
# NOT RUN {
set.seed (27)
dataset <- data.frame (X=1:10, Y=(1:10)^2+runif(10,-10,10))
models <- list (
"model A" = list (
	formula = "Y ~ X^a",
	start = list (list(a=100), list(a=1))),
"model B" = list (
	formula = "Y ~ a*(X+b)",
	start = list (list(a=1,b=1)))
)
multiFit (models, dataset)
# }

Run the code above in your browser using DataLab