shapeselect: Shape selection for additive components with shape or order...

View source: R/shapeselect.R

shapeselectR Documentation

Shape selection for additive components with shape or order constraints

Description

Fits an additive model by selecting variables with shape or order constraints for each predictor using Cone Information Bayesian Criterion (CBIC). The function can perform forward selection or stepwise (forward/backward) updates over a set of candidate shapes appropriate to each predictor type.

Usage

shapeselect(
  xmat,
  y,
  types = NULL,
  direction = c("both", "forward"),
  type = "stepwise",
  infocrit = c("CBIC", "CAIC"),
  family = gaussian,
  control = list(),
  ...
)

Arguments

xmat

A data frame of predictors. Columns may be numeric or factors. Column names are used in output when available. If x is numeric, then the shape options are increasing, decreasing, convex, concave or combination of monotonicity and convexity; if x is a factor, then it can have monotonic or convex ordering options; if x is a factor, the option can also be "in" or "out-of" the model, or "in", "out-of" the model, or following a "tree" ordering, depending on the types parameter.

y

A response vector of length nrow(xmat). It can be either numeric or binary.

types

Optional character vector of length ncol(xmat) specifying the predictor type for each column of xmat. This is used to determine which shape set is eligible for each predictor. Values used for this parameter include "num"/"numeric" (continuous), "ord"/"ordinal" (ordinal/categorical), "tree" (categorical), and "nom"/"nominal" (categorical). Default is NULL, but the user must provide a value for each column of xmat; otherwise the function will throw an error message.

direction

Direction of the search. "forward" performs forward selection only. "both" allows backward revisions (stepwise) after additions.

type

Search strategy. "stepwise" adds predictors while allowing backward revisions. "classo" then applies shrinkage/selection (e.g., via cross-validated lasso). The available option is "stepwise" for now.

infocrit

Information criterion used to decide adding or removing a predictor, and shape updates. Currently supports "CBIC" and "CAIC".

family

A GLM family. May be a family function or a character string naming one. Available families are gaussian and binomial.

control

A list of control parameters. Any entries not supplied fall back to shapeselect_control(). Additional named arguments in ... override both defaults and control.

...

Additional control parameters (passed as overrides). These are merged into control after defaults, so they take highest priority.

Details

The algorithm begins with an intercept-only fit, then evaluates each inactive predictor under a set of allowable shapes (depending on types). At each step it selects the predictor/shape combination that improves the chosen information criterion. When direction = "both", it checks non-chosen shapes for already-selected predictors via backward steps.

Shape and order choices in this implementation include

  1. smooth effects: monotone increasing/decreasing, convex/concave when set4 = TRUE, and combinations set4 = FALSE, if the corresponding value in types is "num"/"numeric" (x is continuous).

  2. non-smooth effects: monotone increasing/decreasing and convex/concave (when set4 = TRUE), or their combinations (when set4 = FALSE), if the corresponding value in types is "ord"/"ordinal" (i.e., x is ordinal, categorical, or numeric but treated as discrete with an inherent ordering). in types is "ord"/"ordinal" (x is ordinal/categorical/having numeric values but treated as discrete values with ordering).

  3. in or out-of the model, if the corresponding value in types is "nom"/"nominal" (x is categorical)

  4. in, out-of the model or following a tree ordering, if the corresponding value in types is "tree" (i.e., x is categorical or numeric but treated as discrete with a tree ordering).

Value

An object of class c("shapeselect","cgam"), a list containing (among others):

mod_tried

A matrix recording the selection path (chosen shapes, criterion values, adding or removing a predictor).

shps

Numeric shape codes for each predictor (0 indicates excluded/flat).

shapes

Character labels for the selected shapes.

etahat

Fitted linear predictor values.

muhat

Fitted mean response on the data scale (family$linkinv(etahat)).

etacomps

Matrix of fitted component contributions by predictor (rows).

cic_vec

Criterion values along the path.

cvec

Shrinkage/selection vector (used when type = "classo").

ddkeep_x_lst, ddkeep_z_lst

Stored design/basis components for numeric and categorical predictors used for prediction and plotting.

Examples

library(MASS)
data("Rubber", package = "MASS")
y <- Rubber[, 1]
xmat <- Rubber[, -1]
ans <- shapeselect(xmat, y, types = c("num", "num"), pnt = FALSE)

print (ans$shapes)

plot(ans)

cgam documentation built on Oct. 20, 2026, 5:08 p.m.

Related to shapeselect in cgam...