Learn R Programming

wPerm (version 1.0.1)

perm.ind.test: Permutation Independence Test

Description

Performs a permutation (randomization) test for independence of two variables, using chi-square as the test statistic.

Usage

perm.ind.test(x, type = c("cont", "flat", "raw"),
              var.names = NULL, R = 9999)

Arguments

x
a data frame (see details below).
type
a character string indicating the type of data frame; must be one of "cont" (default), "flat", or "raw".
var.names
an optional character string of length two that gives the names of the variables under consideration; if omitted Var.1 and Var.2 are used.
R
number of replications (default = 9999).

Value

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

concept

  • permutation tests
  • randomization tests
  • independence test
  • test for association

Details

The null hypothesis is that the two variables are not associated (i.e., are independent). The alternative hypothesis is that the two variables are associated (i.e., are dependent). Types of data frames permitted: cont: In this type of data frame, the first variable gives the possible values of one of the two variables under consideration. The remaining variables of the data frame give the observed frequencies. flat: This type of data frame consists of three variables. The first two variables give the pairs of possible values of the two variables under consideration; the third variable of the data frame gives the frequencies of the pairs. raw: This type of data frame consists of two variables, which give the raw data of the two variables under consideration.

Examples

Run this code
# Religious belief vs education for a sample of 509 people.
data("relig.and.ed")
str(relig.and.ed)
relig.and.ed
# Note that relig.and.ed is in the form of a flat contingency table ("flat").

# Permutation independence test to decide whether an association exists
# between religiosity and education, using 999 replications.
perm.ind.test(relig.and.ed, "flat", c("Religiosity", "Education"), 999)

# Social class vs nursery-rhyme knowledge for a sample of 66 grade-school
# children.
data("learning")
str(learning)
learning
# Note that the learning data is in the form of a contingency table ("cont").

# Permutation independence test to decide whether an association exists
# between social class and nursery-rhyme knowledge, using 999 replications.
perm.ind.test(learning, "cont", c("Social class", "Nursery-rhyme knowledge"), 999)
# Or, equivalently, since "cont" is the default "type":
perm.ind.test(learning, var.names = c("Social class", "Nursery-rhyme knowledge"), R = 999)

Run the code above in your browser using DataLab