Learn R Programming

CarletonStats (version 2.2)

permTest: Permutation test

Description

Permutation test to test a hypothesis involving two samples.

Usage

permTest(x, ...)

# S3 method for default permTest( x, group, statistic = mean, B = 9999, alternative = "two.sided", plot.hist = TRUE, plot.qq = FALSE, xlab = NULL, ylab = NULL, title = NULL, seed = NULL, ... )

# S3 method for formula permTest(formula, data = parent.frame(), subset, ...)

Value

Returns invisibly a vector of the replicates of the test statistic.

Arguments

x

a numeric vector. If the function is the mean (fun = mean) and x is a binary numeric vector of 0's and 1's, then the test is between proportions.

...

further arguments to be passed to or from methods.

group

a factor variable with two levels. If group is a binary numeric vector, it will be coerced into a factor variable.

statistic

the statistic of interest.

B

the number of resamples (positive integer greater than 2).

alternative

the alternative hypothesis. Options are "two.sided", "less" or "greater".

plot.hist

a logical value. If TRUE, the permutation distribution of the statistic is plotted.

plot.qq

a logical value. If TRUE, then a normal quantile-quantile plot of the resampled test statistic is created.

xlab

an optional character string for the x-axis label

ylab

an optional character string for the y-axis label

title

an optional character string giving the plot title

seed

optional argument to set.seed

formula

a formula of the form y ~ group where y is numeric and group is a factor variable.

data

a data frame with the variables in the formula.

subset

an optional expression specifying which observations to keep.

Methods (by class)

  • permTest(default): Permutation test

  • permTest(formula): Permutation test

Author

Laura Chihara

Details

Permutation test to see if a population parameter is the same for two populations. For instance, test \(latex\) where \(latex\) denotes the population mean. The values of the numeric variable are randomly assigned to the two groups and the difference of the statistic for each group is calculated. The command will print the mean and standard error of the distribution of the test statistic as well as a P-value.

Observations with missing values are removed.

References

Tim Hesteberg's website: https://www.timhesterberg.net/bootstrap-and-resampling

Examples

Run this code

permTest(states03$ViolentCrime, states03$DeathPenalty)

#using formula syntax
permTest(ViolentCrime ~ DeathPenalty, data = states03, alt = "less")

Run the code above in your browser using DataLab