#————————————————————————————————————————————————————————————————————————————
# 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", nrep = 5000, seed = 42)
#————————————————————————————————————————————————————————————————————————————
# 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)
#————————————————————————————————————————————————————————————————————————————
# Plot Confidence Intervals
# Example 5a: Two-Sided 95
ci.mean(mtcars, disp, hp, plot = "ci")
# Example 5b: Grouping variable
ci.mean(mtcars, disp, hp, group = "vs", plot = "ci")
# Example 5c: Split variable
ci.mean(mtcars, disp, hp, split = "am", plot = "ci")
# Example 5d: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- ci.mean(mtcars, disp, hp, plot = "ci")
plot(object, ybreaks = seq(0, 300, by = 50), title = "Confidence Intervals")
#————————————————————————————————————————————————————————————————————————————
# Plot Bootstrap Samples
# Example 6a: Two-Sided 95
ci.mean(mtcars, disp, hp, boot = "bc", plot = "boot")
# Example 6b: Grouping variable
ci.mean(mtcars, disp, hp, group = "vs", boot = "bc", plot = "boot")
# Example 6c: Split variable
ci.mean(mtcars, disp, hp, split = "am", boot = "bc", plot = "boot")
# Example 6d: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- ci.mean(mtcars, disp, hp, boot = "bc", plot = "boot")
plot(object, fill = "gray30", title = "Bootstrap Samples")
#————————————————————————————————————————————————————————————————————————————
# Write Results and Save Plot
# Example 7a: Write results into a text file
ci.mean(mtcars, write = "CI_Mean_Text.txt")
# Example 7b: Write results into an Excel file
ci.mean(mtcars, write = "CI_Mean_Excel.xlsx")
# Example 7ce: Save plot as PNG file
ci.mean(mtcars, disp, hp, plot = "ci", filename = "CI_Mean.png",
width = 9, height = 6)
}
Run the code above in your browser using DataLab