Skip to content
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: boot.pval
Title: Bootstrap p-Values
Version: 0.6
Version: 0.6.0.2000
Authors@R:
person(given = "Måns",
family = "Thulin",
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Generated by roxygen2: do not edit by hand

S3method(boot_median_test,data.frame)
S3method(boot_median_test,default)
S3method(boot_median_test,formula)
S3method(boot_median_test,matrix)
S3method(boot_t_test,data.frame)
S3method(boot_t_test,default)
S3method(boot_t_test,formula)
S3method(boot_t_test,matrix)
export(boot.pval)
export(boot_median_test)
export(boot_summary)
export(boot_t_test)
export(censboot_summary)
export(summary_to_flextable)
export(summary_to_gt)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# boot.pval development version
Updated documentation for boot_summary and censboot_summary to not mention studentized intervals (which aren't supported by upstream packages).
Added support for one-sided tests. Added the boot_t_test and boot_median_test functions for carrying out bootstrap tests of location. Updated documentation for boot_summary and censboot_summary to not mention studentized intervals (which aren't supported by upstream packages). Added a new vignette.

# boot.pval version 0.6
Added automatic handling of missing values, so that these don't have to be removed manually from the data prior to using boot_summary(). Added support for BCa intervals again, and improved performance for these intervals. Improved presentation of p-values in regression models. Added a vignette.
Expand Down
26 changes: 23 additions & 3 deletions R/boot.pval.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @param type A vector of character strings representing the type of interval to base the test on. The value should be one of "norm", "basic", "stud", "perc" (the default), and "bca".
#' @param theta_null The value of the parameter under the null hypothesis.
#' @param pval_precision The desired precision for the p-value. The default is 1/R, where R is the number of bootstrap samples in \code{boot_res}.
#' @param alternative A character string specifying the alternative hypothesis. Must be one of "two.sided" (default), "greater", or "less".
#' @param ... Additional arguments passed to \code{boot.ci}.
#'
#' @return A bootstrap p-value.
Expand All @@ -16,7 +17,8 @@
#' @references
#' \insertRef{hall92}{boot.pval}
#'
#' \insertRef{thulin21}{boot.pval}
#' \insertRef{thulin21}{boot.pval}'
#' @seealso [boot_t_test()] for bootstrap t-tests, [boot_median_test()] for bootstrap tests for medians, [boot_summary()] for bootstrap tests for coefficients of regression models.
#' @examples
#' # Hypothesis test for the city data
#' # H0: ratio = 1.4
Expand Down Expand Up @@ -46,6 +48,7 @@ boot.pval <- function(boot_res,
type = "perc",
theta_null = 0,
pval_precision = NULL,
alternative = "two.sided",
...)
{
if(is.null(pval_precision)) { pval_precision = 1/boot_res$R }
Expand All @@ -56,7 +59,7 @@ boot.pval <- function(boot_res,
# Compute the 1-alpha confidence intervals, and extract
# their bounds:
ci <- suppressWarnings(boot::boot.ci(boot_res,
conf = 1- alpha_seq,
conf = 1-alpha_seq,
type = type,
...))

Expand All @@ -69,7 +72,24 @@ boot.pval <- function(boot_res,

# Find the smallest alpha such that theta_null is not contained in the 1-alpha
# confidence interval:
alpha <- alpha_seq[which.min(theta_null >= bounds[,1] & theta_null <= bounds[,2])]
if(alternative == "two.sided") {
alpha <- alpha_seq[which.min(theta_null >= bounds[,1] & theta_null <= bounds[,2])]
}
if(alternative == "greater") {
if(sum(theta_null < bounds[,1]) == 0)
{ alpha <- 1 } else
{
alpha <- alpha_seq[which.min(theta_null >= bounds[,1])]/2
}

}
if(alternative == "less") {
if(sum(theta_null > bounds[,2]) == 0)
{ alpha <- 1 } else
{
alpha <- alpha_seq[which.min(theta_null <= bounds[,2])]/2
}
}

# Return the p-value:
return(alpha)
Expand Down
1 change: 1 addition & 0 deletions R/boot_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @references
#' \insertRef{hall92}{boot.pval}
#' \insertRef{thulin21}{boot.pval}
#' @seealso [boot_t_test()] for bootstrap t-tests, [boot_median_test()] for bootstrap tests for medians.
#' @examples
#' # Bootstrap summary of a linear model for mtcars:
#' model <- lm(mpg ~ hp + vs, data = mtcars)
Expand Down
Loading