Computes one standard deviation for the lower half of the distribution of a numeric vector and another SD for the upper half. By default the center of the distribution for purposes of splitting into "halves" is the mean. The user may override this with center. When splitting into halves, observations equal to the center value are included in both subsets.

dualSD(x, na.rm = FALSE, nmin = 10, center = xbar)

Arguments

x

a numeric vector

na.rm

set to TRUE to find any NA values and remove them before computing SDs.

nmin

the minimum number of non-NA obesrvations that must be present for two SDs to be computed. If the mumber of non-missing values falls below nmin, the regular SD is duplicated in the result.

center

center point for making the two subsets. The sample mean is used to compute the two SDs no matter what is specified for center.

Value

a 2-vector of SDs with names bottom and top

Details

The purpose of dual SDs is to describe variability for asymmetric distributions. Symmetric distributions are also handled, though slightly less efficiently than a single SD does.

See also

Author

Frank Harrell

Examples

set.seed(1)
x <- rnorm(20000)
sd(x)
#> [1] 1.001601
dualSD(x)
#>    bottom       top 
#> 0.9929023 1.0104516 
y <- exp(x)
s1 <- sd(y)
s2 <- dualSD(y)
s1
#> [1] 2.141995
s2
#>   bottom      top 
#> 1.001717 3.575357 
quantile(y, c(0.025, 0.975))
#>      2.5%     97.5% 
#> 0.1411558 7.2922808 
mean(y) + 1.96 * c(-1, 1) * s1
#> [1] -2.55258  5.84404
mean(y) + 1.96 * c(- s2['bottom'], s2['top'])
#>     bottom        top 
#> -0.3176346  8.6534307 
c(mean=mean(y), pseudomedian=pMedian(y), median=median(y))
#>         mean pseudomedian       median 
#>    1.6457302    1.2084559    0.9825899