matchPair: McNemar Test for non-Independant Observations

View source: R/matchPair.R

matchPairR Documentation

McNemar Test for non-Independant Observations

Description

Implementation of an extension of the McNemar test to non-independant observations proposed by Eliasziw et al. (1991).

Usage

matchPair(value, method, strata, type, ...)

.matchPairCorr(value, method, strata, method.correlation = "full", ...)

.matchPairMax(value, method, strata, ...)

.matchPairPerm(value, method, strata, id, n.perm = 1000, ...)

Arguments

value

[numeric vector] vector of binary values.

method

[character vector] measurement method.

strata

[character vector] index of the strata.

type

[character] approach used: "correction", "max-test", "permutation".

...

additional arguments.

method.correlation

[character] method used to compute the correlation, either "full" or "discordant", from section 2 and 4 of Eliasziw et al. (1991), respectively. Only relevant when type is "correction".

id

[character vector] index of the clusters. Only relevant when type is "permutation".

n.perm

[character] number of permutations used to compute the p-value. Only relevant when type is "permutation".

Author(s)

Brice Ozenne

References

Eliasziw M. and Donner A.. Application of the mcnemar test to non-independent matched pair data. Statistics in medicine, volume 10, 1981-1991 (1991)

Examples

n <- 100

set.seed(10)
n.obs <- rbinom(n, size = 2, prob = 1)+1
df <- data.frame(id = unlist(lapply(1:n, function(x){rep(x, n.obs[x])})),
           X = rbinom(sum(n.obs), size = 1, prob = 0.5),
           Y = rbinom(sum(n.obs), size = 1, prob = 0.5))
df$strata <- unlist(tapply(df$id, df$id, function(x){cumsum(duplicated(x))}))+1

dfL <- data.table::melt(df, id.vars = c("id","strata"))
matchPair(value = dfL$value, method = dfL$variable, strata = dfL$strata, type = "correction")
matchPair(value = dfL$value, method = dfL$variable, strata = dfL$strata, type = "max-test")
matchPair(value = dfL$value, method = dfL$variable, strata = dfL$strata, id = df$id, type = "permutation")

mcnemar.test(table(df$X,df$Y))

bozenne/butils documentation built on Oct. 14, 2023, 6:19 a.m.