rcompanion (version 2.4.35)

percentileTest: Test of percentiles by permutation test

Description

Conducts a permutation test to compare two groups for medians, percentiles, or proportion below a threshold value.

Usage

percentileTest(
  formula = NULL,
  data = NULL,
  x = NULL,
  y = NULL,
  test = "median",
  tau = 0.5,
  type = 7,
  threshold = NA,
  comparison = "

Value

A list of three data frames with the data used, a summary for each group, and the p-value from the test.

Arguments

formula

A formula indicating the response variable and the independent variable. e.g. y ~ group.

data

The data frame to use.

x

If no formula is given, the response variable for one group.

y

The response variable for the other group.

test

The statistic to compare between groups. Can be "median", "percentile", "iqr", "proportion", "mean", or "variance".

tau

If "percentile" is chosen as the test, tau indicates the percentile to test. Expressed as a quantile. That is, 0.5 indicates a test for medians. 0.75 indicates a test for 75th percentiles.

type

The type value passed to the quantile function.

threshold

If "proportion" is chosen as the test, threshold indicates the value of the dependent variable to use as the threshold. For example, to test if there is a different in the proportion of observations below $10,000, threshold = 10000 would be used.

comparison

If "proportion" is chosen as the test, comparison indicates the inequality to use. Options are "<", "<=", ">", ">=", or , "=="

r

The number of replicates in the permutation test.

digits

The number of significant digits in the output.

progress

If TRUE, prints a dot for every 1 percent of progress while conducting the test.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Details

The function will test for a difference in medians, percentiles, interquartile ranges, proportion of observations above or below some threshold value, means, or variances between two groups by permutation test.

The permutation test simply permutes the observed values over the two groups and counts how often the calculated statistic is at least as extreme as the original observed statistic.

The input should include either formula and data; or x and y.

The function removes cases with NA in any of the variables.

If the independent variable has more than two groups, only the first two levels of the factor variable will be used.

The p-value returned is a two-sided test.

References

https://rcompanion.org/handbook/F_15.html

Examples

Run this code
data(BrendonSmall)
percentileTest(Sodium ~ Instructor, 
               data=BrendonSmall, 
               test="median")

percentileTest(Sodium ~ Instructor, 
               data=BrendonSmall, 
               test="percentile", 
               tau = 0.75)

percentileTest(Sodium ~ Instructor, 
               data=BrendonSmall, 
               test="proportion", 
               threshold = 1300)
               

Run the code above in your browser using DataLab