shapeConstr: Create shape constraints

View source: R/shapeConstr.R

shapeConstrR Documentation

Create shape constraints

Description

Creates a constraint matrix to shape-constrain a set of coefficients. Mainly intended for splines but can constrain various bases or set of variables. Will typically be called from within cirls.fit but can be used to generate constraint matrices.

Usage

shapeConstr(x, shape, ...)

## Default S3 method:
shapeConstr(x, shape, intercept = FALSE, ...)

## S3 method for class 'factor'
shapeConstr(x, shape, intercept = FALSE, ...)

Arguments

x

An object representing a design matrix of predictor variables, typically basis functions. See details for supported objects.

shape

A character vector indicating one or several shape-constraints. See details for supported shapes.

...

Additional parameters passed to or from other methods.

intercept

For the default method, a logical value indicating if the design matrix includes an intercept. In most cases will be automatically extracted from x.

Details

The recommended usage is to directly specify the shape constraint through the shape argument in the call to glm with cirls.fit. This method is then called internally to create the constraint matrix. However, shapeConstr can nonetheless be called directly to manually build or inspect the constraint matrix for a given shape and design matrix.

The parameters necessary to build the constraint matrix (e.g. knots and ord for splines) are typically extracted from the x object. This is also true for the intercept for most of the object, except for the default method for which it can be useful to explicitly provide it. In a typical usage in which shapeConstr would only be called within cirls.fit, intercept is automatically determined from the glm formula.

Allowed shapes

The shape argument allows to define a specific shape for the association between the expanded term in x and the response of the regression model. This shape can describe the relation between coefficients for the default method, or the shape of the smooth term for spline bases. At the moment, six different shapes are supported, with up to three allowed simultaneously (one from each category):

  • "pos" or "neg": Positive/Negative. Applies to the full association.

  • "inc" or "dec": Monotonically Increasing/Decreasing.

  • "cvx" or "ccv": Convex/Concave.

Available methods

In addition to the default method, shapeConstr currently supports several objects, creating an appropriate shape-constraint matrix depending on the object. The full list can be obtained by methods(shapeConstr).

General
  • factor(): for categorical variables. Extract the contrasts to define the constraint matrix. here the intercept argument has the same interpretation as in the default method, i.e. if set to TRUE it means the glm model doesn't include an intercept externally to the factor. Note that, in this case, a simple dummy coding is done in R.

From the splines package
  • bs: B-splines.

  • ns: Natural splines.

From the dlnm package
  • onebasis: General method for basis functions generated in the package.

  • ps: Penalised splines (P-Splines).

Value

A constraint matrix to be passed to Cmat in cirls.fit.

References

Zhou, S. & Wolfe, D. A., 2000, On derivative estimation in spline regression. Statistica Sinica 10, 93–108.

See Also

cirls.fit() which typically calls shapeConstr internally.

Examples

# example code



cirls documentation built on Sept. 13, 2025, 1:09 a.m.