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.10087601 0.08879798 0.08032575 0.07587374 0.07218578
#> 2 0.10033966 0.09083708 0.08173040 0.07139712 0.06669756
#> 3 0.08842098 0.07999117 0.07854846 0.07381645 0.07092127
#> 4 0.10318165 0.08848091 0.07999481 0.07450134 0.06900145
#> 5 0.09295884 0.08456273 0.08102493 0.07494879 0.07029683
#> 6 0.09180853 0.08459227 0.07765252 0.07313609 0.07019674
#> 7 0.09942178 0.08360813 0.07871929 0.07291580 0.06770617
#> 8 0.09378021 0.08558982 0.07711176 0.06803352 0.06344125
#> 9 0.09087670 0.08223823 0.07581839 0.07071398 0.06941024
#> 10 0.09174463 0.08944009 0.08107437 0.07628478 0.06726242
#>
#> $permuted_correlations
#> [1] 11 12 9 13 8 6 11 7 5 9
#>
#> $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"