format.earth {earth} | R Documentation |
Return a string representing the ‘earth’ expression.
## S3 method for class 'earth': format(x = stop("no 'x' arg"), digits = getOption("digits"), use.names = TRUE, add.labels = FALSE, decomp = "anova", ...)
x |
An earth object.
This is the only required argument.
|
digits |
Number of significant digits.
The default is getOption(digits) .
|
use.names |
If TRUE (default), use variable names. Else use names of the form x[,1] .
|
add.labels |
If TRUE add comments numbering each term. The default is FALSE .
|
decomp |
One of"anova" (the default) order the terms using the ‘anova decomposition’
i.e. in increasing order of interaction"none" order the terms as created during the earth forward pass.The FAQ section for earth has more details.
|
... |
Unused, but provided for generic/method consistency. |
A character representation of the earth object.
The FAQ section for earth
has some comments
about the "anova" decompostion.
Using format.earth
, perhaps after hand editing the returned string,
you can create an alternative to predict.earth
.
For example:
as.func <- function( object, digits = 8, use.names = FALSE, ...) eval(parse(text=paste( "function(x)\n", "{\n", "if(is.vector(x))\n", " x <- matrix(x, nrow = 1, ncol = length(x))\n", "with(as.data.frame(x),\n", format(object, digits = digits, use.names = use.names, ...), ")\n", "}\n", sep = ""))) a <- earth(Volume ~ ., data = trees) my.func <- as.func(a, use.names = FALSE) my.func(c(10,80)) # yields 17.82973 predict(a, c(10,80)) # yields 17.82973, but is slower
a <- earth(Volume ~ ., data = trees) cat(format(a)) # yields: # 23.2 # + 5.75 * pmax(0, Girth - 12.9) # - 2.87 * pmax(0, 12.9 - Girth) # + 0.718 * pmax(0, Height - 76) cat(format(a, use.names = FALSE, add.labels = TRUE)) # yields: # 23.2 # 1 # + 5.75 * pmax(0, x[,1] - 12.9) # 2 # - 2.87 * pmax(0, 12.9 - x[,1]) # 3 # + 0.718 * pmax(0, x[,2] - 76) # 4