Learn R Programming

wPerm (version 1.0.1)

perm.relation: Permutation Test for a Relationship

Description

Performs a permutation (randomization) test for a relationship (correlation, association) for two quantitative variables, using Pearson's r (product moment correlation coefficient), Spearman's rho (rank correlation coefficient), or Kendall's tau as the test statistic.

Usage

perm.relation(x, y, method = c("pearson", "kendall", "spearman"),
              alternative = c("two.sided", "less", "greater"),
              R = 9999)

Arguments

x
a numeric vector of data values representing the first variable.
y
a numeric vector of data values representing the second variable.
method
a character string indicating which method is to be used for the test; one of "pearson" (default), "kendall", or "spearman".
alternative
a character string specifying the alternative hypothesis; must be one of "two.sided" (default), "less", or "greater".
R
number of replications (default = 9999).

Value

  • A list with class "perm.two.var" containing the following components:
  • Perm.valuesthe values of the test statistic obtained from the permutations.
  • Headerthe main title for the output.
  • Variable.1the name of the first variable.
  • Variable.2the name of the second variable.
  • nthe sample size.
  • Statisticthe test statistic.
  • Observedthe observed value of the test statistic.
  • Nullthe null hypothesis; here, always no relation.
  • Alternativethe alternative hypothesis.
  • P.valuethe P-value or a statement like P < 0.001.
  • p.valuethe P-value.

concept

  • permutation tests
  • randomization tests
  • correlation test
  • association test
  • tests for a relationship
  • Pearson's r
  • Spearman's rho
  • Kendall's tau

Details

The null hypothesis is that there is no relationship between the variables. The possible alternative hypotheses are: Two tailed ("two.sided"): There is a relationship between the variables---"relation". Left tailed ("less"): There is a negative relationship between the variables---"neg.relation". Right tailed ("greater"): There is a positive relationship between the variables---"pos.relation".

Examples

Run this code
# Prices, in euros, of a 50cl bottle of water and distances, in meters,
# of convenience stores from the Contemporary Art Museum in El Raval,
# Barcelona.
data("water")
str(water)
attach(water)

# Permutation test to decide whether a negative relationship exists
# between price and distance, using Pearson's r as the test statistic.
perm.relation(PRICE, DISTANCE, alternative = "less")

# Permutation test to decide whether a negative relationship exists
# between price and distance, using Kendall's tau as the test statistic.
perm.relation(PRICE, DISTANCE, "kendall", "less")

# Permutation test to decide whether a negative relationship exists
# between price and distance, using Spearman's rho as the test statistic.
perm.relation(PRICE, DISTANCE, "spearman", "less")

detach(water)  # clean up.

Run the code above in your browser using DataLab