Skip to content

swaprinc

Swap Principal Components into Regression Models

v1.0.1 · Apr 17, 2023 · MIT + file LICENSE

Description

Obtaining accurate and stable estimates of regression coefficients can be challenging when the suggested statistical model has issues related to multicollinearity, convergence, or overfitting. One solution is to use principal component analysis (PCA) results in the regression, as discussed in Chan and Park (2005) <doi:10.1080/01446190500039812>. The swaprinc() package streamlines comparisons between a raw regression model with the full set of raw independent variables and a principal component regression model where principal components are estimated on a subset of the independent variables, then swapped into the regression model in place of those variables. The swaprinc() function compares one raw regression model to one principal component regression model, while the compswap() function compares one raw regression model to many principal component regression models. Package functions include parameters to center, scale, and undo centering and scaling, as described by Harvey and Hansen (2022) <https://cran.r-project.org/package=LearnPCA/vignettes/Vig_03_Step_By_Step_PCA.pdf>. Additionally, the package supports using Gifi methods to extract principal components from categorical variables, as outlined by Rossiter (2021) <https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/NonlinearPCA.html#2_Package>.

Downloads

CRAN

283

Last 30 days

16853rd

676

Last 90 days

2.7K

Last year

Trend: +65.5% (30d vs prior 30d)

r2u CRAN

7

Last 30 days

31

Last 90 days

101

Last year

Trend: -30% (30d vs prior 30d)

autoCRAN

1

Last 7 days

8

Last 30 days

1

All-time

autoCRAN-only: this name is served only by autoCRAN, so the count is exact.

CRAN Check Status

13 OK
Show all 13 flavors
Flavor Status
r-devel-linux-x86_64-debian-clang OK
r-devel-linux-x86_64-debian-gcc OK
r-devel-linux-x86_64-fedora-clang OK
r-devel-linux-x86_64-fedora-gcc OK
r-devel-windows-x86_64 OK
r-oldrel-macos-arm64 OK
r-oldrel-macos-x86_64 OK
r-oldrel-windows-x86_64 OK
r-patched-linux-x86_64 OK
r-release-linux-x86_64 OK
r-release-macos-arm64 OK
r-release-macos-x86_64 OK
r-release-windows-x86_64 OK

Check History

OK 13 OK · 0 NOTE · 0 WARNING · 0 ERROR · 0 FAILURE Jun 9, 2026
ERROR 12 OK · 0 NOTE · 0 WARNING · 1 ERROR · 0 FAILURE Jun 8, 2026
ERROR r-devel-linux-x86_64-debian-gcc

package dependencies

Package required but not available: ‘broom.mixed’

See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
manual.
OK 14 OK · 0 NOTE · 0 WARNING · 0 ERROR · 0 FAILURE Mar 10, 2026

Code

Structure

Lines of code

1,805

Files

15

Compiled share

0%

Has compiled src

No

Language breakdown

R 734 (40.7%)Tests 748 (41.4%)Docs 323 (17.9%)

API

Exported functions

3

Internal functions

1

Recent export changes

v1.0.1+3 %>%, compswap, swaprinc

Testing & CI

Has tests

Yes

Test-to-code ratio

1.02

testthat edition

3

CI present

No

CI type

[]

PR gated

No

Docs

Return-value doc rate

100%

\dontrun example ratio

33.3%

Roxygen coverage

66.7%

Has pkgdown

No

NEWS present

No

Health & Security signals

Informational signals; not verdicts.

on.exit coverage

Unsafe pattern score

0

Dep constraint coverage

0%

Secret pattern count

0

Bundled 3rd-party code

2 items

Portability & License

Min R version

System requirements

C++ standard

License

MIT + file LICENSE

License flags

SPDX valid, OSI approved

History

Versions

1

First release

2023-04-17

Latest release

2023-04-17

Avg cadence

Cold removal rate

Dep drift

0

Per-file churn detail lives in the source pipeline: https://github.com/r-observatory/cran-code-metrics.

Dependency Network

Dependencies Reverse dependencies broom broom.mixed dplyr Gifi lme4 magrittr rlang tidyselect swaprinc

Version History

1 tracked
new 1.0.1 Mar 10, 2026

R Observatory began tracking this package on Mar 10, 2026; it first appeared on CRAN Apr 17, 2023. Releases before tracking aren’t shown.