earth (version 5.3.3)

format.earth: Format earth objects

Description

Return a string representing an earth expression (summary.earth calls this function internally to display the terms of the earth model).

Usage

# S3 method for earth
format(x = stop("no 'x' argument"),
       style = "h", decomp = "anova", digits = getOption("digits"),
       use.names = TRUE, colon.char = ":", ...)

Value

A character representation of the earth model.

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).

Arguments

x

An earth object. This is the only required argument.

style

Formatting style. One of
"h" (default) more compact
"pmax" for those who prefer it
"max" is the same as "pmax" but prints max rather than pmax
"C" C style expression with zero based indexing
"bf" basis function format

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.

digits

Number of significant digits. The default is getOption(digits).

use.names

One of
TRUE (default), use variable names if available.
FALSE use names of the form x[,1].

colon.char

Change colons in the returned string to colon.char. Default is ":" (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.

See Also

summary.earth, pmax,

Examples

Run this code
earth.mod <- earth(Volume ~ ., data = trees)
cat(format(earth.mod))

# yields:
#    29.0
#    -  3.42 * h(14.2-Girth)
#    +  6.23 * h(Girth-14.2)
#    + 0.581 * h(Height-75)

cat(format(earth.mod, style="pmax"))

# yields:
#    29.0
#    -  3.42 * pmax(0,   14.2 -  Girth)
#    +  6.23 * pmax(0,  Girth -  14.2)
#    + 0.581 * pmax(0, Height -  75)

cat(format(earth.mod, style="C"))

# yields (note zero based indexing):
#    29.0
#    -  3.42 * max(0, 14.2 - x[0])
#    +  6.23 * max(0, x[0] - 14.2)
#    + 0.581 * max(0, x[1] - 75)

cat(format(earth.mod, style="bf"))

# yields:
#    29.0
#    -  3.42 * bf1
#    +  6.23 * bf2
#    + 0.581 * bf3
#
#     bf1  h(14.2-Girth)
#     bf2  h(Girth-14.2)
#     bf3  h(Height-75)

Run the code above in your browser using DataCamp Workspace