Learn R Programming

cpr: Control Polygon Reduction

An R package for implementing the Control Polygon Reduction model selection method. When we are tasked with modeling the functional relationship between a response and a continuous predictor, i.e., y = f(x), CPR allows for quick and efficient searching of a large model space to find B-spline estimates of the function f(x).

CPR extends to multiple dimensions and allows one to find good locations for knots in a tensor product of B-splines.

Learn More About CPR.

This model selection method was developed as part of Peter DeWitt's PhD dissertation work. It has since been extended.

Vignettes

There are two vignettes within the package:

vignettes(topic = 'cpr', package = 'cpr')
vignettes(topic = 'cnr', package = 'cpr')

You can also read these on the package website

Related Publications:

  • The CPR method was presented at the 28th International Biometric Conference held in July 2016 in Victoria, British Columbia, Canada. The abstract, paper, and talk had the title: "Parsimonious B-splines Regression Models via Control Polygon Reduction." A BibTeX entry for the abstract:
@inproceedings{,
  author       = {DeWitt, Peter E. and Carlson, Nichole E. and Samantha MaWhinney},
  title        = {Parsimonious B-spline Regression Models via Control Polygon Reduction},
  booktitle    = {Abstracts for the XXVIIIth International Biometric Conference},
  month        = {July},
  year         = {2016},
  organization = {International Biometric Society},
  address      = {Victoria, British Columbia},
  isbn         = {978-0-9821919-4-1}
}

Awards: The presentation of the work earned Peter DeWitt two awards:

  1. "Best Student Oral Presentation" from the International Biometric Society (IBS).
  2. "Distinguished Oral Presentation" as part of the student paper competition hosted by the Western North American Region (WNAR) of the IBS.

Installing CPR

Released Version

Install from the Comprehensive R Archive Network (CRAN)

# within R
install.packages("cpr", repos = "https://cran.rstudio.com")

Developmental Version

If you are working on a Windows machine you will need to have Rtools installed.

From GitHub

This will require you to have remotes package installed.

# Just the package without the manual and without vignettes
remotes::install_github(repo = "dewittpe/cpr")

# Install with vignettes
remotes::install_github(
    repo = "dewittpe/cpr"
  , dependbuild_vignettes = TRUE
  , dependencies = TRUE
)

From a cloned repository

You'll need to have the R package devtools installed on your machine.

To check R dependencies before building, or after you get errors due to missing R packages run:

devtools::install_dev_deps()

To build the R package and install the dev version on your machine:

make install

Alternatively, you should be able to build and install without make

R CMD build <path to cloned repo>
R CMD INSTALL cpr_<version>.tar.gz

Other Notes:

The cpr package provides 3D graphics via the rgl package. If you get an error (or message) of the form:

  font family "sans" not found, using "bitmap"

Then there is an easy fix. You need to get the FreeType 2 font engine.

On Debian, you can get the library via:

apt-get install libfreetype6-dev

Once the FreeType 2 font engine has been installed on your computer you must reinstall the rgl package.

Copy Link

Version

Install

install.packages('cpr')

Monthly Downloads

332

Version

0.4.1

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Peter DeWitt

Last Published

January 8th, 2026

Functions in cpr (0.4.1)

generate_cp_formula_data

Generate Control Polygon Formula and Data
cpr-package

cpr: Control Polygon Reduction
cpr-defunct

Defunct Functions
cpr

Control Polygon Reduction
influence_of_iknots

Determine the influence of the internal knots of a control polygon
newknots

New Knots for CPs and CNs in CPR and CNR
plot.cpr_bs

Plot B-spline Basis
plot.cpr_summary_cpr_cpr

Plotting Summaries of Control Polygon Reductions
plot.cpr_cnr

Control Net Reduction Plots
plot.cpr_cpr

Control Polygon Reduction Plots
loglikelihood

Determine the (quasi) Log Likelihood for a regression object.
matrix_rank

Rank of a Matrix
plot.cpr_cn

Plotting Control Nets
plot.cpr_cp

Plotting Control Polygons
order_statistics

Distribution of Order Statistics
sign_changes

Sign Changes
update_bsplines

Update bsplines or btensor calls
summary.cpr_cnr

Summarize Control Net Reduction Objects
summary.cpr_cpr

Summarize a Control Polygon Reduction Object
summary.cpr_cn

Summary of Control Net
predict.cpr_cp

Model Prediction
trimmed_quantile

Trimmed Quantiles
summary.cpr_cp

Summarize a Control Polygon Object
spdg

Simulated Pregnanediol glucuronide (PDG) Data
print.cpr_bs

Print bsplines
wiggle

Wiggliness of a Spline function
us_covid_cases

United States Laboratory Confirmed COVID-19 Cases
cn

Control Nets
cnr

Control Net Reduction
coef_vcov

Extract Regression Coefficients for B-Splines and Tensor Products of B-splines
cp

Control Polygons
cp_value

Control Polygon Value
cp_diff

Vertical Difference between two Control Polygons
bsplineD

B-spline Derivatives
bsplines

B-Splines
get_spline

Get the Control Polygon and the Spline Function
get_surface

Get Surface
insert_a_knot

Insert a Knot into a Control Polygon
knot_expr

Knot Expressions
iknots_or_df

Internal Knots or Degrees of Freedom
btensor

btensor
build_tensor

Build Tensor