Description Usage Arguments Value Author(s) References Examples
This function conducts multiple hypothesis tests under the sharp null of no effects and combines the results into a single global p-value.
1 2 3 4 5 6 | NPC(data, keep = TRUE, tr.var, tr.label, y.vars, comb.fun = "ProductCF",
n.perms = 1000, block.var = NULL, clust.var = NULL, event.var = NULL,
alternative = "greater", seed = 1, na.rm = TRUE, FWE.adj = TRUE,
step.down = identical(comb.fun, "MinimumCF"),
test.statistic = "StudentsT", return.matrix = FALSE, print.steps = TRUE,
adapt.test = logical(length(y.vars)))
|
data |
Data frame with treatment, response, and other variables |
keep |
Subset of observations (default keeps all) |
tr.var |
Name of treatment variable (character) |
tr.label |
Level of 'tr.var' indicating treated units (character) |
y.vars |
Names of response variables (character) |
comb.fun |
Combining function (character or function) |
n.perms |
Number of permutations, in addition to the one observed |
block.var |
Variable defining blocks within which to restrict permutations (character) |
clust.var |
Variable defining clusters of observations assigned to treatment en bloc (character) |
event.var |
Logical variable indicating whether duration variables were observed rather than censored (character) |
alternative |
Scalar or vector indicating the alternative hypotheses ("greater", "less", or "two.sided"). If "less", test statistics are multiplied by -1. If "two.sided", the absolute value is used. |
seed |
Random seed (numeric) |
na.rm |
Delete observations with missing values? (logical) |
FWE.adj |
Calculate FWE-adjusted p-values? (logical) |
step.down |
If performing FWE adjustment, use stepdown MinP? (logical) |
test.statistic |
Vector or list of test statistic functions (possibly quoted) for marginal tests. If single value is given, then it is used for all marginal tests. |
return.matrix |
Return the permutation distribution of test statistics and p-values? (logical) |
print.steps |
Print progress of the function? (logical) |
adapt.test |
Use the adaptive test of Hogg et al. (1975)? (logical vector) |
p.values |
vector of marginal p-values plus the joint NPC p-value |
p.matrix |
(optional) matrix containing the permutation distribution of marginal p-values |
T.matrix |
(optional) matrix containing the permutation distribution of test statistics |
Devin Caughey <devin.caughey@gmail.com>
Caughey, Devin, Allan Dafoe, and Jason Seawright. Forthcoming. “Nonparametric Combination (NPC): A Framework for Testing Elaborate Theories.” Journal of Politics.
Chung, EunYi, and Joseph P. Romano. 2013. “Exact and Asymptotically Robust Permutation Tests.” Annals of Statistics 41 (2): 484-507.
Hogg, Robert V., Doris M. Fisher, and Ronald H. Randles. 1975. “A Two-Sample Adaptive Distribution-Free Test.” Journal of the American Statistical Association 70 (351): 656-661.
Pesarin, Fortunato, and Luigi Salmaso. 2010. Permutation Tests for Complex Data. Chichester, UK: Wiley.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | library(NPC)
## Required for this example
library(mvtnorm)
library(car)
## COVARIANCE = CORRELATION = 0.25
cov <- 0.25
N <- 8
Tr <- c(rep(0, 4), rep(1, 4))
d1 <- 1
d2 <- 1
d3 <- 1
sd <- 1
sigma <-
matrix(c(1, cov, cov, cov, 1, cov, cov, cov, 1), ncol = 3)
## Create error matrix
set.seed(2)
ee <- rmvnorm(N, c(0, 0, 0), sigma)
mean(c(cor(ee)[1, 2], cor(ee)[3, 2], cor(ee)[1, 3]))
Y1 <- -.5 + Tr*d1 + ee[, 1]
Y2 <- -.5 + Tr*d2 + ee[, 2]
Y3 <- -.5 + Tr*d3 + ee[, 3]
## Create data
(ex.dta <- data.frame(Tr, Y1, Y2, Y3))
(diffs <- round(colMeans(subset(ex.dta, Tr == 1, -Tr)) -
colMeans(subset(ex.dta, Tr == 0, -Tr)), 2))
mean(diffs)
## NPC
npc.out <- NPC(data=ex.dta, tr.var="Tr", tr.label=1,
y.vars=c("Y1", "Y2", "Y3"), n.perms=1000,
alternative = "greater", seed=1, comb.fun="NormalCF",
test.statistic="DiffMeans", FWE.adj=FALSE)
round(npc.out$p.value, 2) ## one-sided
##> Y1 Y2 Y3 NPC
##> 0.25 0.05 0.07 0.08
## Compare with T-tests and MANOVA
t.test(Y1 ~ Tr, var.equal = TRUE, alternative = "less")
t.test(Y2 ~ Tr, var.equal = TRUE, alternative = "less")
t.test(Y3 ~ Tr, var.equal = TRUE, alternative = "less")
car::Anova(lm(cbind(Y1, Y2, Y3) ~ Tr)) ## two-sided
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.