This function computes the boundaries of an interval which is symmetric around the median and includes a given percentage of the data. If that's impossible due to ties the interval is chosen to minimize the squared difference between the desired percentage and the actual percentage of the observations included.

innerval(x, p = 0.95, data.points = TRUE)

Arguments

x

A data vector.

p

The percentage of observations inside the interval.

data.points

Whether to return the most extreme data points within the interval or the interval boundaries.

Value

A vector with the lower and upper boundaries of the interval.

See also

Examples

x1 <- rnorm(200) innerval(x1)
#> [1] -1.794889 1.677345
quantile(x1, c(0.025, 0.975))
#> 2.5% 97.5% #> -1.797975 1.874588
x2 <- rexp(200) innerval(x2, data.points = FALSE)
#> [1] -2.024842 3.425876
innerval(x2)
#> [1] 0.01297325 3.39154184
quantile(x2, c(0.025, 0.975))
#> 2.5% 97.5% #> 0.04570832 4.06564713