Learn R Programming

colf (version 0.1.3)

construct_formula: Construct an nls-compatible formula from an lm style formula

Description

Construct an nls-compatible formula from an lm style formula

Usage

construct_formula(formula, data)

Arguments

formula

The formula. This has the same syntax and supports the same features as the formula in lm. See examples.

data

A data frame containing the data of the variables in the formula.

Value

A list of three elements:

  • model_formula - An nls compatible formula

  • model_data - The modelling set created (inlcuding dummy variables, if any)

  • x_param_names - The names of the parameters

Details

construct_formula creates the parameters needed for the formula to be compatible with nls style functions. It also creates and returns the modelling set.

construct_formula will make syntactically valid names (if applicable) otherwise the optimizers will fail. To make these names make.names is used. Check examples.

See Also

nls, make.names

Examples

Run this code
# NOT RUN {
#simple syntax
construct_formula(mpg ~ hp + cyl, mtcars)

#example of make.names to create syntactically valid names
make.names('(foo/^@bar)')

#function will create syntactically valid names (if applicable) 
#otherwise the optimizers will fail
construct_formula(mpg ~ I(hp + cyl), mtcars)
construct_formula(mpg ~ (hp + cyl + disp)^3, mtcars)

# }

Run the code above in your browser using DataLab