Learn R Programming

Hmisc (version 5.2-4)

pMedian: pMedian

Description

Pseudomedian

Usage

pMedian(
  x,
  na.rm = FALSE,
  conf.int = 0,
  B = 1000,
  type = c("percentile", "bca")
)

Value

a scalar numeric value if conf.int = 0, or a 3-vector otherwise, with named elements estimate, lower, upper and attribute type. If the number of non-missing values is less than 5, NA is returned for both lower and upper limits.

Arguments

x

a numeric vector

na.rm

set to TRUE to exclude NAs before computing the pseudomedian

conf.int

confidence level, defaulting to 0 so that no confidence limits are computed. Set to a number between 0 and 1 to compute bootstrap confidence limits

B

number of bootstrap samples if conf.int > 0

type

type of bootstrap interval, defaulting to 'percentile' for n >= 150 or 'bca' for n < 150

Details

Uses fast Fortran code to compute the pseudomedian of a numeric vector. The pseudomedian is the median of all possible midpoints of two observations. The pseudomedian is also called the Hodges-Lehmann one-sample estimator. The Fortran code is was originally from JF Monahan, and was converted to C++ in the DescTools package. It has been converted to Fortran 2018 here. Bootstrap confidence intervals are optionally computed.

If n > 250,000 a random sample of 250,000 values of x is used to limit execution time. For n > 1,000 only the percentile bootstrap confidence interval is computed.

Bootstrapping uses the Fortran subroutine directly, for efficiency.

See Also

Examples

Run this code
x <- c(1:4, 10000)
pMedian(x)
pMedian(x, conf.int=0.95)
# Compare with brute force calculation and with wilcox.test
w <- outer(x, x, '+')
median(w[lower.tri(w, diag=TRUE)]) / 2
wilcox.test(x, conf.int=TRUE)

Run the code above in your browser using DataLab