#----------------------------------------------------------------------------
# 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)
if (FALSE) {
#----------------------------------------------------------------------------
# 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)
}
Run the code above in your browser using DataLab