meanProbs function

Calculate expected confidence bands or prediction intreval with normal or t sampling distribution

Calculate expected confidence bands or prediction intreval with normal or t sampling distribution

The generic function meanProbs produces expected confidence bands under either the t distribution or the normal sampling distribution. This uses qnorm() or qt() with the mean and standard deviation.

meanProbs(x, ...) ## Default S3 method: meanProbs( x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, useT = TRUE, onlyProbs = TRUE, pred = FALSE, n = 0L, ... )

Arguments

  • x: numeric vector whose mean and probability based confidence values are wanted, NA and NaN values are not allowed in numeric vectors unless ‘na.rm’ is ‘TRUE’.
  • ...: Arguments passed to default method, allows many different methods to be applied.
  • probs: numeric vector of probabilities with values in the interval from 0 to 1 .
  • na.rm: logical; if true, any NA and NaN's are removed from x before the quantiles are computed.
  • names: logical; if true, the result has a names attribute.
  • useT: logical; if true, use the t-distribution to calculate the confidence-based estimates. If false use the normal distribution to calculate the confidence based estimates.
  • onlyProbs: logical; if true, only return the probability based confidence interval estimates, otherwise return
  • pred: logical; if true use the prediction interval instead of the confidence interval
  • n: integer/integerish; this is the n used to calculate the prediction or confidence interval. When n=0 (default) use the number of non-NA observations.

Returns

By default the return has the probabilities as names (if named) with the points where the expected distribution are located given the sampling mean and standard deviation. If onlyProbs=FALSE then it would prepend mean, variance, standard deviation, minimum, maximum and number of non-NA observations.

Details

For a single probability, p, it uses either:

mean + qt(p, df=n)*sd/sqrt(n)

or

mean + qnorm(p)*sd/sqrt(n)

The smallest observation corresponds to a probability of 0 and the largest to a probability of 1 and the mean corresponds to 0.5.

The mean and standard deviation of the sample is calculated based on Welford's method for a single pass.

This is meant to perform in the same way as quantile() so it can be a drop in replacement for code using quantile() but using distributional assumptions.

Examples

quantile(x<- rnorm(1001)) meanProbs(x) # Can get some extra statistics if you request onlyProbs=FALSE meanProbs(x, onlyProbs=FALSE) x[2] <- NA_real_ meanProbs(x, onlyProbs=FALSE) quantile(x<- rnorm(42)) meanProbs(x) meanProbs(x, useT=FALSE)

Author(s)

Matthew L. Fidler