ci.mean | R Documentation |
The function ci.mean
computes and plots confidence intervals for
arithmetic means with known or unknown population standard deviation or
population variance and the function ci.median
computes confidence
intervals for medians, optionally by a grouping and/or split variable. These
functions also supports six types of bootstrap confidence intervals (e.g.,
bias-corrected (BC) percentile bootstrap or bias-corrected and accelerated
(BCa) bootstrap confidence intervals) and plots the bootstrap samples with
histograms and density curves.
ci.mean(data, ..., sigma = NULL, sigma2 = NULL, adjust = FALSE,
boot = c("none", "norm", "basic", "stud", "perc", "bc", "bca"),
R = 1000, seed = NULL, sample = TRUE,
alternative = c("two.sided", "less", "greater"),
conf.level = 0.95, group = NULL, split = NULL, sort.var = FALSE,
na.omit = FALSE, digits = 2, as.na = NULL,
plot = c("none", "ci", "boot"), point.size = 2.5, point.shape = 19,
errorbar.width = 0.3, dodge.width = 0.5, hist = TRUE,
binwidth = NULL, bins = NULL, hist.alpha = 0.4, fill = "gray85", density = TRUE,
density.col = "#0072B2", density.linewidth = 0.5, density.linetype = "solid",
point = TRUE, point.col = "#CC79A7", point.linewidth = 0.6,
point.linetype = "solid", ci = TRUE, ci.col = "black",
ci.linewidth = 0.6, ci.linetype = "dashed", line = FALSE, intercept = 0,
linetype = "solid", line.col = "gray65", xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xbreaks = ggplot2::waiver(),
ybreaks = ggplot2::waiver(), axis.title.size = 11, axis.text.size = 10,
strip.text.size = 11, title = NULL, subtitle = NULL, group.col = NULL,
plot.margin = NA, legend.title = "",
legend.position = c("right", "top", "left", "bottom", "none"),
legend.box.margin = c(-10, 0, 0, 0), facet.ncol = NULL, facet.nrow = NULL,
facet.scales = "free", filename = NULL, width = NA, height = NA,
units = c("in", "cm", "mm", "px"), dpi = 600, write = NULL,
append = TRUE, check = TRUE, output = TRUE)
ci.median(data, ..., boot = c("none", "norm", "basic", "stud", "perc", "bc", "bca"),
R = 1000, seed = NULL, sample = TRUE,
alternative = c("two.sided", "less", "greater"),
conf.level = 0.95, group = NULL, split = NULL, sort.var = FALSE,
na.omit = FALSE, digits = 2, as.na = NULL, plot = c("none", "ci", "boot"),
point.size = 2.5, point.shape = 19, errorbar.width = 0.3, dodge.width = 0.5,
hist = TRUE, binwidth = NULL, bins = NULL, hist.alpha = 0.4, fill = "gray85",
density = TRUE, density.col = "#0072B2", density.linewidth = 0.5,
density.linetype = "solid", point = TRUE, point.col = "#CC79A7",
point.linewidth = 0.6, point.linetype = "solid", ci = TRUE, ci.col = "black",
ci.linewidth = 0.6, ci.linetype = "dashed", line = FALSE, intercept = 0,
linetype = "solid", line.col = "gray65", xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xbreaks = ggplot2::waiver(),
ybreaks = ggplot2::waiver(), axis.title.size = 11, axis.text.size = 10,
strip.text.size = 11, title = NULL, subtitle = NULL, group.col = NULL,
plot.margin = NA, legend.title = "",
legend.position = c("right", "top", "left", "bottom", "none"),
legend.box.margin = c(-10, 0, 0, 0), facet.ncol = NULL, facet.nrow = NULL,
facet.scales = "free", filename = NULL, width = NA, height = NA,
units = c("in", "cm", "mm", "px"), dpi = 600, write = NULL, append = TRUE,
check = TRUE, output = TRUE)
data |
a numeric vector or data frame with numeric
variables, i.e., factors and character variables are
excluded from |
... |
an expression indicating the variable names in |
sigma |
a numeric vector indicating the population standard
deviation when computing confidence intervals for the
arithmetic mean with known standard deviation Note
that either argument |
sigma2 |
a numeric vector indicating the population variance
when computing confidence intervals for the arithmetic
mean with known variance. Note that either argument
|
adjust |
logical: if |
boot |
a character string specifying the type of bootstrap
confidence intervals (CI), i.e., |
R |
a numeric value indicating the number of bootstrap replicates (default is 1000). |
seed |
a numeric value specifying seeds of the pseudo-random numbers used in the bootstrap algorithm when conducting bootstrapping. |
sample |
logical: if |
alternative |
a character string specifying the alternative hypothesis,
must be one of |
conf.level |
a numeric value between 0 and 1 indicating the confidence level of the interval. |
group |
either a character string indicating the variable name
of the grouping variable in |
split |
either a character string indicating the variable name
of the split variable in |
sort.var |
logical: if |
na.omit |
logical: if |
digits |
an integer value indicating the number of decimal places to be used. |
as.na |
a numeric vector indicating user-defined missing
values, i.e. these values are converted to |
plot |
a character string indicating the type of the plot
to display, i.e., |
point.size |
a numeric value indicating the |
point.shape |
a numeric value between 0 and 25 or a character string
as plotting symbol indicating the |
errorbar.width |
a numeric value indicating the |
dodge.width |
a numeric value indicating the |
hist |
logical: if |
binwidth |
a numeric value or a function for specifying the
|
bins |
a numeric value for specifying the |
hist.alpha |
a numeric value between 0 and 1 for specifying the
|
fill |
a character string specifying the |
density |
logical: if |
density.col |
a character string specifying the |
density.linewidth |
a numeric value specifying the |
density.linetype |
a numeric value or character string specifying the
|
point |
logical: if |
point.col |
a character string specifying the |
point.linewidth |
a numeric value specifying the |
point.linetype |
a numeric value or character string specifying the
|
ci |
logical: if |
ci.col |
character string specifying the |
ci.linewidth |
a numeric value specifying the |
ci.linetype |
a numeric value or character string specifying the
|
line |
logical: if |
intercept |
a numeric value indicating the |
linetype |
a character string indicating the |
line.col |
a character string indicating the |
xlab |
a character string indicating the |
ylab |
a character string indicating the |
xlim |
a numeric vector with two elements indicating the
|
ylim |
a numeric vector with two elements indicating the
|
xbreaks |
a numeric vector indicating the |
ybreaks |
a numeric vector indicating the |
axis.title.size |
a numeric value indicating the |
axis.text.size |
a numeric value indicating the |
strip.text.size |
a numeric value indicating the |
title |
a character string indicating the |
subtitle |
a character string indicating the |
group.col |
a character vector indicating the |
plot.margin |
a numeric vector with four elements indicating the
|
legend.title |
a character string indicating the |
legend.position |
a character string indicating the |
legend.box.margin |
a numeric vector with four elements indicating the
|
facet.ncol |
a numeric value indicating the |
facet.nrow |
a numeric value indicating the |
facet.scales |
a character string indicating the |
filename |
a character string indicating the |
width |
a numeric value indicating the |
height |
a numeric value indicating the |
units |
a character string indicating the |
dpi |
a numeric value indicating the |
write |
a character string naming a file for writing the output
into either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
list with the input specified in |
args |
specification of function arguments |
boot |
data frame with bootstrap replicates of the arithmetic mean of median when bootstrapping was requested |
plot |
ggplot2 object for plotting the results and the data frame used for plotting |
result |
result table |
Bootstrap confidence intervals are computed using the R package boot
by Angelo Canty and Brain Ripley (2024).
Takuya Yanagida takuya.yanagida@univie.ac.at
Baguley, T. S. (2012). Serious stats: A guide to advanced statistics for the behavioral sciences. Palgrave Macmillan.
Canty, A., & Ripley, B. (2024). boot: Bootstrap R (S-Plus) Functions. R package version 1.3-31.
Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.
test.z
, test.t
, ci.mean.diff
,
ci.cor
, ci.prop
, ci.var
,
ci.sd
, descript
#----------------------------------------------------------------------------
# Confidence Interval (CI) for the Arithmetic Mean
# Example 1a: Two-Sided 95% CI
ci.mean(mtcars)
# Example 1b: Two-Sided 95% Difference-Adjusted CI
ci.mean(mtcars, adjust = TRUE)
# Example 1c: Two-Sided 95% CI with known population standard deviation
ci.mean(mtcars, mpg, sigma = 6)
# Alternative specification without using the '...' argument
ci.mean(mtcars$mpg, sigma = 6)
#----------------------------------------------------------------------------
# Confidence Interval (CI) for the Median
# Example 2a: Two-Sided 95% CI
ci.median(mtcars)
# Example 2b: One-Sided 99% CI
ci.median(mtcars, alternative = "less", conf.level = 0.99)
## Not run:
#----------------------------------------------------------------------------
# Bootstrap Confidence Interval (CI)
# Example 3a: Bias-corrected (BC) percentile bootstrap CI
ci.mean(mtcars, boot = "bc")
# Example 3b: Bias-corrected and accelerated (BCa) bootstrap CI,
# 5000 bootstrap replications, set seed of the pseudo-random number generator
ci.mean(mtcars, boot = "bca", R = 5000, seed = 123)
#----------------------------------------------------------------------------
# Grouping and Split Variable
# Example 4a: Grouping variable
ci.mean(mtcars, mpg, cyl, disp, group = "vs")
# Alternative specification without using the '...' argument
ci.mean(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)
# Example 4b: Split variable
ci.mean(mtcars, mpg, cyl, disp, split = "am")
# Alternative specification
ci.mean(mtcars[, c("mpg", "cyl", "disp")], split = mtcars$am)
# Example 4c: Grouping and split variable
ci.mean(mtcars, mpg, cyl, disp, group = "vs", split = "am")
# Alternative specification
ci.mean(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, split = mtcars$am)
#----------------------------------------------------------------------------
# Write Output
# Example 5a: Text file
ci.mean(mtcars, write = "CI_Mean_Text.txt")
# Example 5b: Excel file
ci.mean(mtcars, write = "CI_Mean_Excel.xlsx")
#----------------------------------------------------------------------------
# Plot Confidence Intervals
# Example 6a: Two-Sided 95
ci.mean(mtcars, disp, hp, plot = "ci")
# Example 6b: Grouping variable
ci.mean(mtcars, disp, hp, group = "vs", plot = "ci")
# Example 6c: Split variable
ci.mean(mtcars, disp, hp, split = "am", plot = "ci")
# Example 6d: Save plot as PDF file
ci.mean(mtcars, disp, hp, plot = "ci", saveplot = "CI_Mean.pdf",
width = 9, height = 6)
# Example 6e: Save plot as PNG file
ci.mean(mtcars, disp, hp, plot = "ci", saveplot = "CI_Mean.png",
width = 9, height = 6)
#----------------------------------------------------------------------------
# Example 7: Plot Bootstrap Samples
# Example 7a: Two-Sided 95
ci.mean(mtcars, disp, hp, boot = "bc", plot = "boot")
# Example 7b: Grouping variable
ci.mean(mtcars, disp, hp, group = "vs", boot = "bc", plot = "boot")
# Example 7c: Split variable
ci.mean(mtcars, disp, hp, split = "am", boot = "bc", plot = "boot")
# Example 7d: Save plot as PDF file
ci.mean(mtcars, disp, hp, boot = "bc", plot = "boot", saveplot = "CI_Mean_Boot.pdf",
width = 12, height = 7)
# Example 7e: Save plot as PNG file
ci.mean(mtcars, disp, hp, boot = "bc", plot = "boot", saveplot = "CI_Mean_Boot.png",
width = 12, height = 7)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.