Learn R Programming

lgspline (version 0.2.0)

coef.lgspline: Extract model coefficients

Description

Extracts polynomial coefficients for each partition from a fitted lgspline model.

Usage

# S3 method for lgspline
coef(object, ...)

Value

A list where each element corresponds to a partition and contains a single-column matrix of coefficient values for that partition. Row names indicate the term type. Returns NULL if coefficients are not found in the object.

partition1, partition2, ...

Matrices containing coefficients for each partition.

Arguments

object

A fitted lgspline model object containing coefficient vectors.

...

Not used.

Details

For each partition, coefficients represent a polynomial expansion of the predictor(s) by column index, for example:

  • intercept: Constant term

  • v: Linear term

  • v_^2: Quadratic term

  • v^3: Cubic term

  • _v_x_w_: Interaction between v and w

If column/variable names are present, indices will be replaced with column/variable names.

Coefficients can be accessed either as separate vectors per partition or combined into a single matrix using Reduce('cbind', coef(model_fit)).

See Also

lgspline

Examples

Run this code

## Simulate some data and fit using default settings
set.seed(1234)
t <- runif(1000, -10, 10)
y <- 2*sin(t) + -0.06*t^2 + rnorm(length(t))
model_fit <- lgspline(t, y)

## Extract coefficients
coefficients <- coef(model_fit)

## Print coefficients for first partition
print(coefficients[[1]])

## Compare coefficients across all partitions
print(Reduce('cbind', coefficients))

Run the code above in your browser using DataLab