Permute data fed to PCA a given number of times, collecting the number of significant pairwise correlations in the permuted data and the variances explained for a given number of PCs.
Arguments
- pca_data
data fed to the
prcomp
function. Remove non-continuous variables.- pc_n
the number of PCs to collect variance explained from.
- n
the number of times to permute that data. Warning: high values will take a long time to compute.
- scale
whether the PCA variables should be scaled (default = TRUE).
- cor.method
method to use for correlations (default = "pearson"). Alternative is "spearman".
Value
object of class permutation_test
$permuted_variances
n x pc_no matrix of variances explained by first pc_no PCs in n permutations of original data.$permuted_correlations
list of length n of significant pairwise correlations in n permutations of the data (<= 0.05).$actual_variances
pc_n x 2 tibble of variances explained by first pc_n PCs with original data.$actual_correlations
the number of significant pairwise correlations (<= 0.05) in the original data.
Details
This function is now superseded. Use correlation_test()
for pairwise
correlations and pca_test()
for variance explained and loadings.
Examples
permutation_test(
onze_intercepts |> dplyr::select(-speaker),
pc_n = 5,
n = 10,
scale = TRUE,
cor.method = 'pearson'
)
#> $permuted_variances
#> PC1 PC2 PC3 PC4 PC5
#> 1 0.09801421 0.08056611 0.07383211 0.07122915 0.06337760
#> 2 0.09673745 0.08748429 0.08218244 0.07273270 0.06843527
#> 3 0.08415248 0.08005626 0.07689180 0.07425076 0.06783985
#> 4 0.09621459 0.08328628 0.07413359 0.06964632 0.06780199
#> 5 0.09871256 0.09141129 0.08090679 0.06925790 0.06825858
#> 6 0.08788232 0.08679001 0.07776683 0.07676907 0.06630793
#> 7 0.08640135 0.08213955 0.08045114 0.07182490 0.06707714
#> 8 0.09262402 0.08927014 0.08010901 0.07848387 0.06908269
#> 9 0.10197223 0.08434247 0.07607760 0.07194075 0.06899879
#> 10 0.09522405 0.08906267 0.07596028 0.07020678 0.06643209
#>
#> $permuted_correlations
#> [1] 8 7 5 8 10 6 8 9 9 12
#>
#> $actual_variances
#> # A tibble: 5 × 2
#> PC variance_explained
#> <chr> <dbl>
#> 1 PC1 0.183
#> 2 PC2 0.143
#> 3 PC3 0.0989
#> 4 PC4 0.0835
#> 5 PC5 0.0774
#>
#> $actual_correlations
#> [1] 69
#>
#> attr(,"class")
#> [1] "permutation_results"