boot2pvalue | R Documentation |
Compute the p.value associated with the estimated statistic using a bootstrap sample of its distribution under H1.
boot2pvalue(
x,
null,
estimate = NULL,
alternative = "two.sided",
FUN.ci = quantileCI,
tol = .Machine$double.eps^0.5
)
x |
[numeric vector] a vector of bootstrap estimates of the statistic. |
null |
[numeric] value of the statistic under the null hypothesis. |
estimate |
[numeric] the estimated statistic. |
alternative |
[character] a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". |
FUN.ci |
[function] the function used to compute the confidence interval.
Must take |
tol |
[numeric] the absolute convergence tolerance. |
For test statistic close to 0, this function returns 1.
For positive test statistic, this function search the quantile alpha such that:
quantile(x, probs = alpha)=0
when the argument alternative is set to "greater"
.
quantile(x, probs = 0.5*alpha)=0
when the argument alternative is set to "two.sided"
.
If the argument alternative is set to "less"
, it returns 1.
For negative test statistic, this function search the quantile alpha such that:
quantile(x, probs = 1-alpha=0
when the argument alternative is set to "less"
.
quantile(x, probs = 1-0.5*alpha=0
when the argument alternative is set to "two.sided"
.
If the argument alternative is set to "greater"
, it returns 1.
set.seed(10)
#### no effect ####
x <- rnorm(1e3)
boot2pvalue(x, null = 0, estimate = mean(x), alternative = "two.sided")
## expected value of 1
boot2pvalue(x, null = 0, estimate = mean(x), alternative = "greater")
## expected value of 0.5
boot2pvalue(x, null = 0, estimate = mean(x), alternative = "less")
## expected value of 0.5
#### positive effect ####
x <- rnorm(1e3, mean = 1)
boot2pvalue(x, null = 0, estimate = 1, alternative = "two.sided")
## expected value of 0.32 = 2*pnorm(q = 0, mean = -1) = 2*mean(x<=0)
boot2pvalue(x, null = 0, estimate = 1, alternative = "greater")
## expected value of 0.16 = pnorm(q = 0, mean = 1) = mean(x<=0)
boot2pvalue(x, null = 0, estimate = 1, alternative = "less")
## expected value of 0.84 = 1-pnorm(q = 0, mean = 1) = mean(x>=0)
#### negative effect ####
x <- rnorm(1e3, mean = -1)
boot2pvalue(x, null = 0, estimate = -1, alternative = "two.sided")
## expected value of 0.32 = 2*(1-pnorm(q = 0, mean = -1)) = 2*mean(x>=0)
boot2pvalue(x, null = 0, estimate = -1, alternative = "greater")
## expected value of 0.84 = pnorm(q = 0, mean = -1) = mean(x<=0)
boot2pvalue(x, null = 0, estimate = -1, alternative = "less") # pnorm(q = 0, mean = -1)
## expected value of 0.16 = 1-pnorm(q = 0, mean = -1) = mean(x>=0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.