| format.earth {earth} | R Documentation |
Return a string representing an earth expression.
## S3 method for class 'earth':
format(x = stop("no 'x' arg"),
digits = getOption("digits"), use.names = TRUE,
decomp = "anova", style = "h", colon.char = ":", ...)
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].
|
decomp |
One of"anova" (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. |
style |
Formatting style. One of"h" (default) more compact"pmax" for those who prefer it and for compatibility with old versions of earth"max" is the same as "pmax" but prints max rather than pmax"bf" basis function format.
|
colon.char |
Change colons in the returned string to colon.char.
Default is ":", i.e., no change.
Specifying colon.char="*" can be useful in some contexts to change
names of the form x1:x2 to x1*x2.
|
... |
Unused, but provided for generic/method consistency. |
A character representation of the earth object.
If there are multiple responses, format.earth will return multiple strings.
If there are embedded GLM model(s), the strings for the GLM model(s)
come after the strings for the standard earth model(s).
The FAQ section for earth has some comments on the "anova" ordering.
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",
"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, style = "pmax", ...),
")\n",
"}\n", sep = "")))
a <- earth(Volume ~ ., data = trees)
my.func <- as.func(a, use.names = FALSE)
my.func(c(10,80)) # yields 17.769
predict(a, c(10,80)) # yields 17.769, but is slower
The earth package also provides a function format.lm.
It has arguments as followsformat.lm(x, digits=getOption("digits"), use.names=TRUE, colon.char=":")format.lm doesn't belong in the earth package.) Example:
a <- lm(Volume ~ Height*Girth, data = trees) cat(format(a, colon.char="*")) # yields: # 69.4 # - 1.30 * Height # - 5.86 * Girth # + 0.135 * Height*Girth
a <- earth(Volume ~ ., data = trees) cat(format(a)) # yields: # 23.2 # + 5.75 * h(Girth-12.9) # - 2.87 * h(12.9-Girth) # + 0.718 * h(Height-76) cat(format(a, style="pmax")) # default formatting style prior to earth version 1.4 # 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, style="bf")) # yields: # 23.2 # + 5.75 * bf1 # - 2.87 * bf2 # + 0.718 * bf3 # # bf1 h(Girth-12.9) # bf2 h(12.9-Girth) # bf3 h(Height-76)