build_allowed_function: Build an allowed function for earth()

View source: R/build_allowed.R

build_allowed_functionR Documentation

Build an allowed function for earth()

Description

Converts an allowed interaction matrix into a function compatible with the allowed parameter of earth::earth(). The function checks that ALL pairwise combinations among the predictors in a proposed interaction term are TRUE in the matrix.

Usage

build_allowed_function(allowed_matrix)

Arguments

allowed_matrix

A symmetric logical matrix as returned by build_allowed_matrix().

Details

The returned function implements the standard earth() allowed function contract. When earth proposes a new hinge function involving predictor pred with existing parent predictors indicated by the parents logical vector, the function checks that every pair of involved predictors is allowed in the matrix.

For a 3-way interaction between X, Y, Z, the function verifies that (X,Y), (Y,Z), and (X,Z) are all TRUE in the matrix.

Value

A function with signature ⁠function(degree, pred, parents, namesx, first)⁠ suitable for the allowed parameter of earth::earth().

Examples

mat <- build_allowed_matrix(c("sqft", "bedrooms", "pool"))
mat["sqft", "pool"] <- FALSE
mat["pool", "sqft"] <- FALSE
func <- build_allowed_function(mat)

earthUI documentation built on March 26, 2026, 1:07 a.m.