Generate a scope for step.Gam
gam.scope.RdGiven a data.frame as an argument, generate a scope list for use in step.Gam, each element of which gives the candidates for that term.
Arguments
- frame
a data.frame to be used in
step.Gam. Apart from the response column, all other columns will be used.- response
The column in
frameused as the response. Default is 1.- smoother
which smoother to use for the nonlinear terms; i.e. "s" or "lo", or any other supplied smoother. Default is "s".
- arg
a character (vector), which is the argument to
smoother. For example,arg="df=6"would result in the expressions(x,df=6)for a column named "x". This can be a vector, for examplearg=c("df=4","df=6"), which would result two smooth terms.- form
if
TRUE, each term is a formula, else a character vector.
Value
a scope list is returned, with either a formula or a character vector for each term, which describes the candidates for that term in the Gam.
Details
This function creates a similar scope formula for each variable in the
frame. A column named "x" by default will generate a scope term
~1+x+s(x). With arg=c("df=4","df=6") we get
~1+x+s(x,df=4)+s(x,df=6). With form=FALSE, we would get the character
vector c("1","x","s(x,df=4)","s(x,df=6").
References
Hastie, T. J. (1991) Generalized additive models. Chapter 7 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
Author
Written by Trevor Hastie, following closely the design in the
"Generalized Additive Models" chapter (Hastie, 1992) in Chambers and Hastie
(1992). This version of gam.scope is adapted from the S version.
Examples
data(gam.data)
gdata=gam.data[,1:3]
gam.scope(gdata,2)
#> $x
#> ~1 + x + s(x)
#> <environment: 0x590fc81c1e70>
#>
#> $z
#> ~1 + z + s(z)
#> <environment: 0x590fc81c1e70>
#>
gam.scope(gdata,2,arg="df=5")
#> $x
#> ~1 + x + s(x, df = 5)
#> <environment: 0x590fc8229620>
#>
#> $z
#> ~1 + z + s(z, df = 5)
#> <environment: 0x590fc8229620>
#>
gam.scope(gdata,2,arg="df=5",form=FALSE)
#> $x
#> [1] "1" "x" "s(x,df=5)"
#>
#> $z
#> [1] "1" "z" "s(z,df=5)"
#>
gam.scope(gdata,2,arg=c("df=4","df=6"))
#> $x
#> ~1 + x + s(x, df = 4) + s(x, df = 6)
#> <environment: 0x590fc83214e8>
#>
#> $z
#> ~1 + z + s(z, df = 4) + s(z, df = 6)
#> <environment: 0x590fc83214e8>
#>