mctest {gsse401}R Documentation

GSS 401 - Paired and two-sample Monte Carlo tests

Description

Performs Monte Carlo tests for paired or two-sample analysis.
A graphical display of the results is produced by plot.mctest.

Usage

mctest(x, y, paired = TRUE, nsim, plot = TRUE)

plot(x)

print(x)

Arguments

x a numeric vector with data on first variable
y a numeric vector with data on the second variable
paired logical indicating whether a paired test should be performed. Defualts to FALSE which implies the two-sample analysis.
nsim an integer with the number of Monte Carlo samples. Defaults to 1000.
plot logical. If TRUE plot is automaticaly produced.

Details

Paired data

    1
    For the n pairs of data (x_i, y_i) compute the differences d_i = x_i - y_i and then the test statistic:

    (mean(d))/(sqrt(Var(d)/n))

    2
    For each pair re-allocate the two data to the two groups randomly. Then re-compute the test statistics above.
    3
    repeat the previous step nsim times. This generates an empirical distribution for the test statistics.
    4
    compare the statistics computed for the data with the empirical distribution.

mbox{}

Two-sample

For two-sample test a randomization test is performed as follows:

    1
    For two independent samples x and y of sizes n_x and n_y define

    S^2 = ((n_x-1) Var(x) + (n_y -1) Var(y))/(n_x + n_y - 2)

    and compute the following statistics:

    (mean(x) - mean(y))/sqrt(S^2 * (1/n_x + 1/n_y))

    2
    Pool n_x + n_y data together and re-allocate to the two groups of sizes n_x and n_y randomly.
    3
    repeat the previous step nsim times. This generates an empirical distribution for the test statistics.
    4
    compare the statistics computed for the data with the empirical distribution.

For both cases the test statistic for the original data is compared against the empirical distribution in order to produce P-values. Upper and lower tail probabilities are computed by counting how many values of the statistic computed for the simulated data are above and below the value obtained for the original data.

Additionally, P-values based on the t distribution are also reported.

Value

The function mctest returns an object of the class mctest which is a list with components

p a numerical vector with upper and lower tail probabilities based on the empirical distribution
pt a numerical vector with upper and lower tail probabilities based on the t distribution
data.statistic the statistics above computed for the original data
sim.statistic the statistics above computed for each simulations


mbox{}
The function plot.mctest produces a histogram of the empirical distribution with an indication to the value of the data statistics. A t distribution can be added to the plot.

Author(s)

Peter J. Diggle p.diggle@lancaster.ac.uk
Paulo Justiniano Ribeiro Jr. p.ribeiro@lancaster.ac.uk.

Examples

##
## A two-sample test
##
data(mandible)
mctest(mandible$female, mandible$male, paired = FALSE)
#
# For an interactive input type:

mctest()