swaprinc {swaprinc} | R Documentation |
Swap in Principal Components
Description
Compare a regression model using raw variables with another model where principal components are extracted from a subset of the raw independent variables, and a user-defined number of these principal components are then used to replace the original subset of variables in the regression model.
Usage
swaprinc(
data,
formula,
engine = "stats",
prc_eng = "stats",
pca_vars,
n_pca_components,
norun_raw = FALSE,
lpca_center = "none",
lpca_scale = "none",
lpca_undo = FALSE,
gifi_transform = "none",
gifi_trans_vars,
gifi_trans_dims,
no_tresp = FALSE,
miss_handler = "none",
model_options = "noaddpars",
prcomp_options = "noaddpars",
gifi_princals_options = "noaddpars",
gifi_trans_options = "noaddpars"
)
Arguments
data |
A dataframe |
formula |
A quoted model formula |
engine |
The engine for fitting the model. Options are 'stats' or 'lme4'. |
prc_eng |
Then engine or extracting principal components. Options are
'stats', 'Gifi', and 'stats_Gifi'. The stats_Gifi engine uses
|
pca_vars |
Variables to include in the principal component analysis. These variables will be swapped out for principal components |
n_pca_components |
The number of principal components to include in the model. If using a complex prc_eng (i.e., stats_Gifi) then provide a named vector (i.e., n_pca_components = c("stats" = 2, "Gifi" = 3)). |
norun_raw |
Include regression on raw variables if TRUE, exclude if FALSE. |
lpca_center |
Center data as in the Step-by-Step PCA vignette (Harvey & Hanson, 2022). Only numeric variables will be included in the centering. Parameter takes values 'all' to center raw and pca variables, 'raw' to only center variables for the raw variable model fitting, 'pca' to only center pca_vars before pca regression model fitting, and 'none' to skip lpca centering. |
lpca_scale |
Scale data as in the Step-by-Step PCA vignette. Only numeric variables will be included in the scaling. Parameter takes values 'all' to scale raw and pca variables, 'raw' to only scale variables for the raw variable model fitting, 'pca' to only scale pca_vars before pca regression model fitting, and 'none' to skip lpca scaling. |
lpca_undo |
Undo centering and scaling of pca_vars as in the Step-by-Step PCA vignette. |
gifi_transform |
Use Gifi optimal scaling to transform a set of variables. Parameter takes values 'none', 'all', 'raw', and 'pca' |
gifi_trans_vars |
A vector of variables to include in the Gifi optimal scaling transformation |
gifi_trans_dims |
Number of dimensions to extract in the Gifi optimal scaling transformation algorithm |
no_tresp |
When set to |
miss_handler |
Choose how |
model_options |
Pass additional arguments to statistical modeling functions
(i.e., |
prcomp_options |
Pass additional arguments to |
gifi_princals_options |
Pass additional arguments to |
gifi_trans_options |
Pass additional arguments to |
Value
A list with fitted models
References
Rossiter, D. G. Nonlinear Principal Components Analysis: Multivariate Analysis with Optimal Scaling (MVAOS). (2021) https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/NonlinearPCA.html
Harvey, D. T., & Hanson, B. A. Step-by-Step PCA. (2022) https://cran.r-project.org/package=LearnPCA/vignettes/Vig_03_Step_By_Step_PCA.pdf
Examples
data(iris)
res <- swaprinc(iris,
"Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width",
pca_vars = c("Sepal.Width", "Petal.Length", "Petal.Width"),
n_pca_components = 2)