Applies a Principal Component Analysis (PCA) to the covariates matrix V and
replaces it with a lower dimensional representation. This function is intended
for parametric workflows and requires a valid V matrix.
PCA(
object = NULL,
X = NULL,
W = NULL,
V = NULL,
json_path = NULL,
components = NULL,
sd_threshold = NULL,
center = TRUE,
scale = TRUE
)An object of class eim, which can be created using the eim function.
A (b x c) matrix representing candidate votes per ballot box.
A (b x g) matrix representing group votes per ballot box.
A (b x a) matrix with parametric covariates.
A path to a JSON file containing X, W, and V fields.
Integer specifying the number of principal components to keep.
Numeric in (0, 1] indicating the minimum cumulative proportion
of variance explained by the retained components.
Logical indicating whether to center the columns of V before PCA.
Logical indicating whether to scale the columns of V before PCA.
Returns an eim object with the V matrix replaced by its PCA scores. The
columns of V are renamed as PCA 1, PCA 2, ..., up to the chosen number
of components.
sim <- simulate_election(
num_ballots = 50,
num_candidates = 3,
num_groups = 2,
ballot_voters = 40,
num_covariates = 10,
num_districts = 2,
seed = 1
)
sim_pca <- PCA(sim, components = 2)
sim_pca$V
#> PCA 1 PCA 2
#> [1,] -3.531675 9.389463e-16
#> [2,] 2.774887 8.533705e-16
#> [3,] 2.774887 8.533705e-16
#> [4,] -3.531675 9.389463e-16
#> [5,] 2.774887 8.533705e-16
#> [6,] 2.774887 8.533705e-16
#> [7,] -3.531675 9.389463e-16
#> [8,] -3.531675 9.389463e-16
#> [9,] 2.774887 8.533705e-16
#> [10,] 2.774887 8.533705e-16
#> [11,] 2.774887 8.533705e-16
#> [12,] -3.531675 9.389463e-16
#> [13,] -3.531675 9.389463e-16
#> [14,] 2.774887 8.533705e-16
#> [15,] 2.774887 8.533705e-16
#> [16,] 2.774887 8.533705e-16
#> [17,] 2.774887 8.533705e-16
#> [18,] 2.774887 8.533705e-16
#> [19,] 2.774887 8.533705e-16
#> [20,] -3.531675 9.389463e-16
#> [21,] 2.774887 8.533705e-16
#> [22,] 2.774887 8.533705e-16
#> [23,] 2.774887 8.533705e-16
#> [24,] 2.774887 8.533705e-16
#> [25,] -3.531675 9.389463e-16
#> [26,] -3.531675 9.389463e-16
#> [27,] -3.531675 9.389463e-16
#> [28,] 2.774887 8.533705e-16
#> [29,] 2.774887 8.533705e-16
#> [30,] -3.531675 9.389463e-16
#> [31,] -3.531675 9.389463e-16
#> [32,] 2.774887 8.533705e-16
#> [33,] 2.774887 8.533705e-16
#> [34,] 2.774887 8.533705e-16
#> [35,] -3.531675 9.389463e-16
#> [36,] -3.531675 9.389463e-16
#> [37,] -3.531675 9.389463e-16
#> [38,] 2.774887 8.533705e-16
#> [39,] -3.531675 9.389463e-16
#> [40,] 2.774887 8.533705e-16
#> [41,] -3.531675 9.389463e-16
#> [42,] 2.774887 8.533705e-16
#> [43,] -3.531675 9.389463e-16
#> [44,] -3.531675 9.389463e-16
#> [45,] 2.774887 8.533705e-16
#> [46,] 2.774887 8.533705e-16
#> [47,] -3.531675 9.389463e-16
#> [48,] -3.531675 9.389463e-16
#> [49,] -3.531675 9.389463e-16
#> [50,] 2.774887 8.533705e-16