part: Fits a linear model based on spline terms with additional...

Description Usage Arguments Value Author(s) Examples

View source: R/part.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## 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

Kpart documentation built on May 2, 2019, 1:45 p.m.