Learn R Programming

splinetree

This package allows users to create, visualize, and evaluate regression trees and random forests for longitudinal or functional data through a spline projection method first suggested by Yu and Lambert (1999).

Installation

You can install splinetree from CRAN or from github with:

# install.packages("devtools")
devtools::install_github("anna-neufeld/splinetree")

Usage

Detailed information on using this package can be found in the package vignettes. The package vignettes can be accessed with:

browseVignettes(package='splinetree')

The vignettes are also available on the package website, https://anna-neufeld.github.io/splinetree/reference/index.html.

Example Tree

library(splinetree)
#> Loading required package: rpart
#> Loading required package: nlme
#> Loading required package: splines
tree1 <- splineTree(~HISP+WHITE+BLACK+HGC_MOTHER+HGC_FATHER+SEX+Num_sibs, 
        BMI ~ AGE, "ID", nlsySample, degree = 1, df=2, intercept = FALSE, cp = 0.005)
stPrint(tree1)
#> n= 1000,  
#> 
#> node), split, n , coefficients 
#>       * denotes terminal node
#> 
#> 1) root, 1000,  (4.961796, 8.091247) 
#>   2) WHITE< 0.5, 505,  (5.882807, 9.006190)*
#>   3) WHITE>=0.5, 495,  (4.022179, 7.157821) 
#>     6) HGC_FATHER< 8.5, 78,  (5.198284, 8.642817)*
#>     7) HGC_FATHER>=8.5, 417,  (3.802188, 6.880053)*
stPlot(tree)

Example Forest

set.seed(1234)
forest1 <- splineForest(~HISP+WHITE+BLACK+HGC_MOTHER+HGC_FATHER+SEX+Num_sibs, 
        BMI ~ AGE, "ID", nlsySample, degree = 1, df=2, intercept = FALSE, ntree=50, prob=1/2)
varImps <- varImpCoeff(forest1)
plotImp(varImps[,3])

Copy Link

Version

Install

install.packages('splinetree')

Monthly Downloads

159

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Anna Neufeld

Last Published

July 18th, 2019

Functions in splinetree (0.2.0)

plotNode

Plot the predicted trajectory for a single node
pruneForest

Prune each tree in forest using a given complexity parameter.
rpartco

Calculates coordinates for tree plot
flatten_predictors

Flattens predictor variable data into one row per person
spline_init

Custom rpart init function
predictYForest

Predict responses for a testset using a splineforest.
predict_y_training

Predict responses for the training data
spline_eval

Custom rpart eval function.
splineTreePlot

Creates a tree plot of a spline tree.
predictCoeffs

Predict spline coefficients for a testset using a spline tree
splineTree

Build a splinetree model.
projectedR2

Computes percent of variation in projected response explained by a splinetree.
treeSize

Returns number of terminal nodes in a tree.
terminalNodeSummary

Prints a summary of a terminal node in a tree
predictY

Predictions from a spline tree
stPlot

Plots a splinetree.
predictCoeffsForest

Predict spline coefficients for a testset using a splineforest.
spaghettiPlot

Create a faceted spaghetti plot of a splinetree model
yR2

Computes percent of variation in response explained by spline tree.
splineForest

Build a spline random forest.
projectedR2Forest

Computes a level-based or shape-based evaluation metric for a splineforest.
treeSummary

Returns the tree frame.
varImpY

Random Forest Variable Importance based on Y
splineforest_split

Custom rpart split function for spline random forests
spline_split

Custom rpart split function.
varImpCoeff

Random Forest Variable Importance based on spline coefficients
tree

Sample tree used in examples
stPrint

Print a spline tree in the style of print.rpart
tree.depth

Given a list of node numbers, returns the depth at which these appear in the tree.
treeSimilarity

Returns a measure of how similar the two trees are.
yR2Forest

Computes a level-based evaluation metric for a splineforest that was built WITH an intercept.
getBasisMat

Get the basis matrix to be used for this spline tree
importance

Sample importance used in vignettes
nlsySample

Baseline socioeconomic information and BMI of 100 individuals.
individual_spline

Get spline coefficients for a single person
forest

Sample forest used in vignettes
nodePlot

Plots the trajectories of each terminal node side by side.
getNodeData

Retrieve the subset of the data found at a given terminal node
avSize

Compute the average tree size in a forest
plotImp

Create a barplot of relative variable importance scores.