#————————————————————————————————————————————————————————————————————————————
# Confidence Interval (CI) for Proportions
# Example 1a: Two-Sided 95% CI
ci.prop(mtcars, vs, am)
# Alternative specification without using the '...' argument
ci.prop(mtcars[, c("vs", "am")])
# Example 1b: One-Sided 95% CI using Wald method
ci.prop(mtcars, vs, am, method = "wald", alternative = "less")
if (FALSE) {
#————————————————————————————————————————————————————————————————————————————
# Bootstrap Confidence Interval (CI)
# Example 2a: Bias-corrected (BC) percentile bootstrap CI
ci.prop(mtcars, vs, am, boot = "bc")
# Example 2b: Bias-corrected and accelerated (BCa) bootstrap CI,
# 5000 bootstrap replications, set seed of the pseudo-random number generator
ci.prop(mtcars, vs, am, boot = "bca", nrep = 5000, seed = 42)
#————————————————————————————————————————————————————————————————————————————
# Grouping and Split Variable
# Example 3a: Grouping variable
ci.prop(mtcars, vs, group = "am")
# Alternative specification without using the '...' argument
ci.prop(mtcars$vs, group = mtcars$am)
# Example 3b: Split variable
ci.prop(mtcars, vs, split = "am")
# Alternative specification without using the '...' argument
ci.prop(mtcars$vs, split = mtcars$am)
# Example 3c: Grouping and split variable
ci.prop(mtcars, vs, group = "am", split = "cyl")
# Alternative specification without using the '...' argument
ci.prop(mtcars$vs, group = mtcars$am, split = mtcars$cyl)
#————————————————————————————————————————————————————————————————————————————
# Plot Confidence Intervals
# Example 5a: Two-Sided 95
ci.prop(mtcars, vs, am, plot = "ci")
# Example 5b: Grouping variable
ci.prop(mtcars, vs, am, group = "am", plot = "ci")
# Example 5c: Split variable
ci.prop(mtcars, vs, am, 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.prop(mtcars, vs, am, plot = "ci")
plot(object, ybreaks = seq(0, 1, by = 0.1), title = "Confidence Intervals")
#————————————————————————————————————————————————————————————————————————————
# Plot Bootstrap Samples
# Example 6a: Two-Sided 95
ci.prop(mtcars, vs, am, boot = "bc", plot = "boot")
# Example 6b: Grouping variable
ci.prop(mtcars, vs, am, group = "am", boot = "bc", plot = "boot")
# Example 6c: Split variable
ci.prop(mtcars, vs, am, 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.prop(mtcars, vs, am, 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.prop(mtcars, vs, am, write = "CI_Prop.txt")
# Example 7b: Write results into an Excel file
ci.prop(mtcars, vs, am, write = "CI_Prop.xlsx")
# Example 7ce: Save plot as PNG file
ci.prop(mtcars, vs, am, plot = "ci", filename = "CI_Prop.png",
width = 9, height = 6)
}
Run the code above in your browser using DataLab