permcluster {mvctm} | R Documentation |
Generates a Permuted Data Set
Description
This function generates a permuted data set that can be used to perform a permutation test for a variance component for 2-level, 3-level or 4-level data.
Usage
permcluster(cluster, data, leveltested)
Arguments
cluster |
A vector giving the name of the variables in the data frame |
data |
A data frame containing the data. |
leveltested |
An integer giving the level to be tested. It must be 1 for 2-level data, 1 or 2 for 3-level data, and 1, 2 or 3 for 4-level data. It corresponds to the element in |
Details
This is a utility function that allows to perform a permutation test with another test statistic than the one in the function mvctm
.
Value
A data frame that contains the original variables plus 1, 2 or 3 new columns. For 2-level data, a single new column called clusperm1
contains the permuted indices for the level 1 cluster. For 3-level data, two new columns called clusperm1
and clusperm2
contain the permuted indices for the level 1 and level 2 clusters, respectively. For 4-level data, three new columns called clusperm1
, clusperm2
and clusperm3
contain the permuted indices for the level 1, level 2, and level 3 clusters, respectively.
Author(s)
Denis Larocque <denis.larocque@hec.ca>
References
Larocque, D., Nevalainen, J. and Oja, H. (2018). Multivariate Variance Components Tests for Multilevel Data. Les Cahiers du GERAD G-2018-58.
Examples
data(toydata)
# generates a permuted data set with 2-level data
permcluster(cluster=c("classroom"),data=toydata,leveltested=1)
# generates a permuted data set with 4-level data to test for level 2
permcluster(cluster=c("region","school","classroom"),
data=toydata,leveltested=2)
# performing a permutation test with another
# test statistic might look like this
## Not run:
pval=0
# compute the statistic with the original data. Call in stato.
for (i in 1:npermut)
{
pdata=permcluster(cluster=c("classroom"),data=toydata,leveltested=1)
# compute the statistic with pdata using the new column
# clusperm1 instead of classroom as the cluster index.
# call it statp.
pval=pval+(statp>stato)
}
pval/npermut
## End(Not run)