matchPair | R Documentation |
Implementation of an extension of the McNemar test to non-independant observations proposed by Eliasziw et al. (1991).
matchPair(value, method, strata, type, ...)
.matchPairCorr(value, method, strata, method.correlation = "full", ...)
.matchPairMax(value, method, strata, ...)
.matchPairPerm(value, method, strata, id, n.perm = 1000, ...)
value |
[numeric vector] vector of binary values. |
method |
[character vector] measurement method. |
strata |
[character vector] index of the strata. |
type |
[character] approach used: |
... |
additional arguments. |
method.correlation |
[character] method used to compute the correlation, either |
id |
[character vector] index of the clusters. Only relevant when |
n.perm |
[character] number of permutations used to compute the p-value. Only relevant when |
Brice Ozenne
Eliasziw M. and Donner A.. Application of the mcnemar test to non-independent matched pair data. Statistics in medicine, volume 10, 1981-1991 (1991)
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.