part {Kpart}R Documentation

Fits a linear model based on spline terms with additional support for other independent variables.

Description

The user will input a data frame, then designate the variable that is the outcome. Then the spline term is selected along with any other independent variables. Finally, a number K partitions is chosen for the algorithm to search for potential cubic spline knots based on the spline term and partition.

Usage

part(d, outcomeVariable, splineTerm, additionalVars = NULL, K)

Arguments

d

A data frame data set with column names.

outcomeVariable

The variable from 'd' that is the outcome.

splineTerm

The spline term, inherited from 'd'.

additionalVars

A vector of additional variables to be included in the model.

K

The number of evenly spaced partitions to be searched.

Value

fits

The fitted values of the linear model.

xhat

The entire feature matrix.

coefs

The significant coefficients of the model.

adjr2

The adjusted R^2 value.

Author(s)

Eric Golinko

Examples


## for simple spline model.
data(LakeHuron)
d <- data.frame(seq(1875, 1972, 1), LakeHuron)
names(d) <- c('date', 'lh')
fit <- part(d = d, outcomeVariable = 'lh', splineTerm = 'date', K = 20)
fit
plot(d$date, d$lh)
lines(d$date, fit$fits, col = 'red')


## multivariate
data(freeny)
freeny$time <- as.numeric(rownames(freeny))
fit <- part(d = freeny, outcomeVariable = 'y',
    splineTerm = 'time', additionalVars = c('market.potential', 'income.level'), K =2)
fit$coefs

[Package Kpart version 1.2.2 Index]