Learn R Programming

USP (version 0.1.2)

USP.test: Independence test for discrete data

Description

Carry out a permutation independence test on a two-way contingency table. The test statistic is \(Tn\), as described in Sections 3.1 and 7.1 of BKS2020USP. This also appears as \(Un\) in BS2021USP. The critical value is found by sampling null contingency tables, with the same row and column totals as the input, via Patefield's algorithm, and recomputing the test statistic.

Usage

USP.test(freq, B = 999, ties.method = "standard", nullstats = FALSE)

Arguments

freq

Two-way contingency table whose independence is to be tested.

B

The number of resampled null tables to be used to calibrate the test.

ties.method

If "standard" then calculate the p-value as in (5) of BKS2020USP, which is slightly conservative. If "random" then break ties randomly. This preserves Type I error control.

nullstats

If TRUE, returns a vector of the null statistic values.

Value

Returns the p-value for this independence test and the value of the test statistic, \(T_n\), as defined in BKS2020USP. The third element of the list is the table of expected counts, and the final element is the table of contributions to \(T_n\). If nullstats=TRUE is used, then the function also returns a vector of the null statistics.

References

BKS2020USP

BS2021USP

Examples

Run this code
# NOT RUN {
freq=r2dtable(1,rep(10,5),rep(10,5))[[1]] + 4*diag(rep(1,5))
USP.test(freq,999)

freq=diag(1:5); USP.test(freq,999)

freq=r2dtable(1,rep(10,5),rep(10,5))[[1]];
test=USP.test(freq,999,nullstats=TRUE)
plot(density(test$NullStats,from=0,
to=max(max(test$NullStats),test$TestStat)),
    xlim=c(min(test$NullStats),max(max(test$NullStats),test$TestStat)),
    main="Test Statistics")
abline(v=test$TestStat,col=2); TestStats=c(test$TestStat,test$NullStats)
abline(v=quantile(TestStats,probs=0.95),lty=2)
# }

Run the code above in your browser using DataLab