permtest | R Documentation |
Performs a permutation test on long-format data to evaluate differences between two groups using a specified test statistic.
permtest(x, y = NULL, statistic, alternative = "two.sided",
Q = seq(0.1, 0.9, by = 0.1), qt = 7, R = 10000)
x |
A data frame or matrix containing the data in long format. |
y |
An optional second data frame or matrix. If provided, the data will be combined with |
statistic |
The function name to compute the statistic of interest. |
alternative |
Type of alternative hypothesis: |
Q |
A vector of quantile probabilities specifying the quantiles to be compared. The default is |
qt |
An integer between 0 and 9 specifying the quantile calculation method. The default is 7. |
R |
An integer indicating the number of permutations. The default is 10000. |
The function allows researchers to perform robust statistical testing by utilizing permutations. This approach does not rely on distributional assumptions and is particularly useful when the sample size is small or the data distribution is unknown. The test generates an empirical distribution of the test statistic by repeatedly permuting group labels and recalculating the statistic, providing p-values based on these permutations.
A list containing the following components:
t0 |
The estimated statistics of the differences. |
t |
A matrix of the permuted values of the statistics. |
pval |
A numeric vector of p-values for each statistic. |
alternative |
The specified alternative hypothesis. |
R |
The number of permutations. |
pvalsk |
A numeric vector of p-values for skewness and kurtosis with two-sided alternative. These are used to check the similarity of distributions to decide whether to use a bootstrap and a permutation test for inference. |
call |
The matched call. |
Zeynel Cebeci, A. Firat Ozdemir, Engin Yildiztepe
bootstrap
# Group1 normal, Group 2 right skewed with equal means and different variances
set.seed(1199)
grp1 <- rnorm(20, 45, 5)
grp2 <- c(rnorm(10, 45, 10), rnorm(10, 52, 20))
df <- data.frame(cbind(grp1=grp1, grp2=grp2))
head(df)
bivarplot(df)
# Reshape the data into long format
df <- wide2long(df)
head(df)
# Differences between the basic stats
calcstatdif(df)
# Permutation test for the differences between the basic stats of two groups
result <- permtest(df, statistic = calcstatdif, alternative = "two.sided", R = 500)
result$pval
# Permutation with custom statistics
# A custom function to compute the differences between the group means
meancomp <- function(x, ...){
meandif <- diff(rev(tapply(x[,1], x[,2], mean)))
return(meandif)
}
# Permutation test with meancomp function
result <- permtest(x = df, statistic = meancomp, alternative="less", R=500)
result$pval
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.