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. |
... |
Unused, but provided for generic/method consistency. |
A character representation of the earth object.
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 = TRUE, ...) 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: # 26.6 # + 6.05 * pmax(0, Girth - 13.7) # - 3.2 * pmax(0, 13.7 - Girth) # + 0.608 * pmax(0, Height - 75) cat(format(a, use.names = FALSE, add.labels = TRUE)) # yields: # 26.6 # 1 # + 6.05 * pmax(0, x[,1] - 13.7) # 2 # - 3.2 * pmax(0, 13.7 - x[,1]) # 3 # + 0.608 * pmax(0, x[,2] - 75) # 4