qwraps2 (version 0.4.2)

mean_ci: Means and Confidence Intervals

Description

A function for calculating and formatting means and confidence interval.

Usage

mean_ci(
  x,
  na_rm = FALSE,
  transform,
  alpha = getOption("qwraps2_alpha", 0.05),
  qdist = stats::qnorm,
  qdist.args = list()
)

# S3 method for qwraps2_mean_ci print(x, ...)

Arguments

x

a numeric vector

na_rm

if true, omit NA values

transform

function transform to the mean and the confidence limits. See Details.

alpha

defaults to getOption('qwraps2_alpha', 0.05). The symmetric 100(1-alpha)% CI will be determined.

qdist

defaults to qnorm. use qt for a Student t intervals.

qdist.args

list of arguments passed to qdist

...

arguments passed to frmtci.

Value

a vector with the mean, lower confidence limit (LCL), and the upper confidence limit (UCL).

Details

Given a numeric vector, mean_ci will return a vector with the mean, LCL, and UCL. Using frmtci will be helpfull for reporting the results in print.

The transform arguement allows the use to transform the data. A common occurance of using mean_ci(log(x), transform = exp) will return the geometric mean and confidence interval for x.

See Also

frmtci

Examples

Run this code
# NOT RUN {
# using the standard normal for the CI
mean_ci(mtcars$mpg)

# print it nicely
qwraps2::frmtci(mean_ci(mtcars$mpg))
qwraps2::frmtci(mean_ci(mtcars$mpg), show_level = TRUE)
qwraps2::frmtci(mean_ci(mtcars$mpg, alpha = 0.01), show_level = TRUE)

# Compare to the ci that comes form t.test
t.test(mtcars$mpg)
t.test(mtcars$mpg)$conf.int
mean_ci(mtcars$mpg, qdist = stats::qt, qdist.args = list(df = 31))

# geometric version
mean_ci(log(mtcars$mpg), transform = exp, qdist = stats::qt, qdist.args = list(df = 31))

# }

Run the code above in your browser using DataLab