#————————————————————————————————————————————————————————————————————————————
# Confidence Interval (CI) for the Variance
# Example 1a: Two-Sided 95% CI
ci.var(mtcars)
# Example 1b: One-Sided 99% CI based on the chi-square distribution
ci.var(mtcars, alternative = "less", method = "chisq")
#————————————————————————————————————————————————————————————————————————————
# Confidence Interval (CI) for the Standard Deviation
# Example 2a: Two-Sided 95% CI
ci.sd(mtcars)
# Example 2b: One-Sided 99% CI based on the chi-square distribution
ci.sd(mtcars, alternative = "less", method = "chisq")
if (FALSE) {
#————————————————————————————————————————————————————————————————————————————
# Bootstrap Confidence Interval (CI)
# Example 3a: Bias-corrected (BC) percentile bootstrap CI
ci.var(mtcars, boot = "bc")
# Example 3b: Bias-corrected and accelerated (BCa) bootstrap CI,
# 5000 bootstrap replications, set seed of the pseudo-random number generator
ci.var(mtcars, boot = "bca", nrep = 5000, seed = 42)
#————————————————————————————————————————————————————————————————————————————
# Grouping and Split Variable
# Example 4a: Grouping variable
ci.var(mtcars, mpg, cyl, disp, group = "vs")
# Alternative specification without using the '...' argument
ci.var(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)
# Example 4b: Split variable
ci.var(mtcars, mpg, cyl, disp, split = "am")
# Alternative specification without using the '...' argument
ci.var(mtcars[, c("mpg", "cyl", "disp")], split = mtcars$am)
# Example 4c: Grouping and split variable
ci.var(mtcars, mpg, cyl, disp, group = "vs", split = "am")
# Alternative specification without using the '...' argument
ci.var(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, split = mtcars$am)
#————————————————————————————————————————————————————————————————————————————
# Plot Confidence Intervals
# Example 6a: Two-Sided 95
ci.var(mtcars, plot = "ci")
# Example 6b: Grouping variable
ci.var(mtcars, disp, hp, group = "vs", plot = "ci")
# Example 6c: Split variable
ci.var(mtcars, disp, hp, split = "am", plot = "ci")
# 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.var(mtcars, disp, hp, plot = "ci")
plot(object, ybreaks = seq(0, 25000, by = 2500), title = "Confidence Intervals")
#————————————————————————————————————————————————————————————————————————————
# Plot Bootstrap Samples
# Example 7a: Two-Sided 95
ci.var(mtcars, disp, hp, boot = "bc", plot = "boot")
# Example 7b: Grouping variable
ci.var(mtcars, disp, hp, group = "vs", boot = "bc", plot = "boot")
# Example 7c: Split variable
ci.var(mtcars, disp, hp, split = "am", boot = "bc", plot = "boot")
# Example 7d: Plot results using the plot() function, use additional arguments
# see Details in the help page of the function plot.misty.object
object <- ci.var(mtcars, disp, hp, boot = "bc", plot = "boot")
plot(object, fill = "gray30", title = "Bootstrap Samples")
#————————————————————————————————————————————————————————————————————————————
# Write Results and Save Plot
# Example 8a: Write results into a text file
ci.var(mtcars, disp, write = "CI_Var.txt")
# Example 8b: Write results into an Excel file
ci.var(mtcars, disp, write = "CI_Var.xlsx")
# Example 8c: Save plot as PNG file
ci.var(mtcars, disp, plot = "ci", filename = "CI_Var.png",
width = 9, height = 6)
}
Run the code above in your browser using DataLab