Learn R Programming

sfsmisc (version 0.95-1)

wrapFormula: Enhance Formula by Wrapping each Term, e.g., by "s(.)"

Description

The main motivation for this function has been the easy construction of a full GAM formula from something as simple as Y ~ .. The potential use is slightly more general.

Usage

wrapFormula(f, data, wrapString = "s(*)")

Arguments

f
the initial formula; typically something like Y ~ ..
data
data.frame to which the formula applies; see, formula or also gam or
wrapString
character string, containing "*", specifying the wrapping expression to use.

Value

  • a formula very similar to f; just replacing each additive term by its wrapped version.

See Also

formula; gam from package mgcv (or also from package gam).

Examples

Run this code
myF <- wrapFormula(Fertility ~ . , data = swiss)
myF # Fertility ~ s(Agriculture) + s(....) + ...

if(require("mgcv")) {
   m1 <- gam(myF, data = swiss)
   summary(m1)
   plot(m1, pages = 1) ; title(format(m1$call), line= 2.5)
}

Run the code above in your browser using DataLab