Compute a permutation matrix used as argument in aovperm, lmperm, clusterlm functions. The first column represents the identity permutation. Generally not suited for the "huh_jhun" method, as the dimension of this matrix does not correspond to the number of observations and may vary for different factors.

Pmat(np = 5000, n, type = "permutation", counting = "random")

Arguments

np

A numeric value for the number of permutations. Default is 5000.

n

A numeric value for the number of observations.

type

A character string to specify the type of transformations: "permutation" and "signflip" are available. See details.

counting

A character string to specify the selection of the transformations. "all" and "random" are available. See details.

Value

A matrix n x np containing the permutations/signflips. First permutation is the identity.

Details

couting can set to :
"random" : np random with replacement permutations/signflips among the n!/2^n permutations/signflips.
"all" : all n!/2^n possible permutations/signflips.

See also

Other pmat: Pmat_product(), as.Pmat()

Examples

## data
data("emergencycost")

## Create a set of 2000 permutations
set.seed(42)
pmat = Pmat(np = 2000, n = nrow(emergencycost))
sfmat = Pmat(np = 2000, n = nrow(emergencycost), type = "signflip")

## centrering the covariate to the mean
emergencycost$LOSc <- scale(emergencycost$LOS, scale = FALSE)

## ANCOVA
mod_cost_0 <- aovperm(cost ~ LOSc*sex*insurance, data = emergencycost, np = 2000)
mod_cost_1 <- aovperm(cost ~ LOSc*sex*insurance, data = emergencycost, P = pmat)
mod_cost_2 <- aovperm(cost ~ LOSc*sex*insurance, data = emergencycost, P = pmat)
mod_cost_3 <- aovperm(cost ~ LOSc*sex*insurance, data = emergencycost, P = sfmat)
mod_cost_4 <- aovperm(cost ~ LOSc*sex*insurance, data = emergencycost,type="signflip")

## Same p-values for both models 1 and 2 but different of model 0
mod_cost_0
#> Anova Table
#> Resampling test using freedman_lane to handle nuisance variables and 2000 permutations.
#>                           SS  df        F parametric P(>F) resampled P(>F)
#> LOSc               2.162e+09   1 483.4422          0.00000          0.0005
#> sex                1.463e+07   1   3.2714          0.07229          0.0905
#> insurance          6.184e+05   1   0.1383          0.71048          0.6925
#> LOSc:sex           8.241e+06   1   1.8427          0.17646          0.1645
#> LOSc:insurance     2.911e+07   1   6.5084          0.01163          0.0270
#> sex:insurance      1.239e+05   1   0.0277          0.86801          0.8590
#> LOSc:sex:insurance 1.346e+07   1   3.0091          0.08463          0.0885
#> Residuals          7.514e+08 168                                          
mod_cost_1
#> Anova Table
#> Resampling test using freedman_lane to handle nuisance variables and 2000 permutations.
#>                           SS  df        F parametric P(>F) resampled P(>F)
#> LOSc               2.162e+09   1 483.4422          0.00000          0.0005
#> sex                1.463e+07   1   3.2714          0.07229          0.0685
#> insurance          6.184e+05   1   0.1383          0.71048          0.6805
#> LOSc:sex           8.241e+06   1   1.8427          0.17646          0.1530
#> LOSc:insurance     2.911e+07   1   6.5084          0.01163          0.0220
#> sex:insurance      1.239e+05   1   0.0277          0.86801          0.8550
#> LOSc:sex:insurance 1.346e+07   1   3.0091          0.08463          0.0825
#> Residuals          7.514e+08 168                                          
mod_cost_2
#> Anova Table
#> Resampling test using freedman_lane to handle nuisance variables and 2000 permutations.
#>                           SS  df        F parametric P(>F) resampled P(>F)
#> LOSc               2.162e+09   1 483.4422          0.00000          0.0005
#> sex                1.463e+07   1   3.2714          0.07229          0.0685
#> insurance          6.184e+05   1   0.1383          0.71048          0.6805
#> LOSc:sex           8.241e+06   1   1.8427          0.17646          0.1530
#> LOSc:insurance     2.911e+07   1   6.5084          0.01163          0.0220
#> sex:insurance      1.239e+05   1   0.0277          0.86801          0.8550
#> LOSc:sex:insurance 1.346e+07   1   3.0091          0.08463          0.0825
#> Residuals          7.514e+08 168                                          
mod_cost_3
#> Anova Table
#> Resampling test using freedman_lane to handle nuisance variables and 2000 signflips.
#>                           SS  df        F parametric P(>F) resampled P(>F)
#> LOSc               2.162e+09   1 483.4422          0.00000          0.0005
#> sex                1.463e+07   1   3.2714          0.07229          0.2090
#> insurance          6.184e+05   1   0.1383          0.71048          0.7340
#> LOSc:sex           8.241e+06   1   1.8427          0.17646          0.1575
#> LOSc:insurance     2.911e+07   1   6.5084          0.01163          0.0300
#> sex:insurance      1.239e+05   1   0.0277          0.86801          0.8815
#> LOSc:sex:insurance 1.346e+07   1   3.0091          0.08463          0.1305
#> Residuals          7.514e+08 168                                          
mod_cost_4
#> Anova Table
#> Resampling test using freedman_lane to handle nuisance variables and 5000 signflips.
#>                           SS  df        F parametric P(>F) resampled P(>F)
#> LOSc               2.162e+09   1 483.4422          0.00000          0.0002
#> sex                1.463e+07   1   3.2714          0.07229          0.2160
#> insurance          6.184e+05   1   0.1383          0.71048          0.7392
#> LOSc:sex           8.241e+06   1   1.8427          0.17646          0.1602
#> LOSc:insurance     2.911e+07   1   6.5084          0.01163          0.0316
#> sex:insurance      1.239e+05   1   0.0277          0.86801          0.8748
#> LOSc:sex:insurance 1.346e+07   1   3.0091          0.08463          0.1378
#> Residuals          7.514e+08 168