Confidence-Intervals-for-Frequencies | R Documentation |
This function computes (one or more) confidence intervals (CIs) for a vector of observations or a table
object and returns an object of class 'freqCI'
to draw a bar plot of the results.
freqCI(x, level = 0.95) ## S3 method for class 'freqCI' print(x, percent = TRUE, digits, ...) ## S3 method for class 'freqCI' barplot(height, percent = TRUE, ...)
x |
must either be a numeric or factor object of individual observations (character vectors are also accepted, but a warning is issued) or an object of class |
level |
a numeric vector of confidence levels in (0, 1). |
percent |
if |
digits |
the number of digits to print (default to 2 if values are represented as percents or 4 if relative frequencies are used. |
height |
to plot the proportions and confidence intervals, an object of class |
... |
further arguments. |
ref to the book
freqCI()
returns an object of class 'freqCI'
as a list:
call |
the function call issued |
x |
the original object |
level |
the confidence levels |
freq |
a numeric vector of frequencies |
n |
the number of observations |
rel_freq |
relative frequencies |
cat_names |
category names |
CIs_low |
lower confidence interval boundary/boundaries |
CIs_high |
upper confidence interval boundary/boundaries |
print.freqCI()
invisibly returns a matrix with the confidence intervals and estimates.
barplot.freqCI()
invisibly returns a vector with the x-coordinates of the plotted bars.
Marco J. Maier
table
, as.table
,
barplot
# generate some simple data using rep() and inspect them using table() mydata <- rep(letters[1:3], c(100,200,300)) table(mydata) 100 * prop.table(table(mydata)) # compute 95% and 99% confidence intervals and print them with standard settings res <- freqCI(mydata, level = c(.95, .99)) res # print the result as relative frequencies rounded to 3 digits, save the result # and print the invisibly returned matrix resmat <- print(res, percent = FALSE, digits = 3) resmat # plot the results and save the x-coordinates x_coo <- barplot(res) x_coo # use the x-coordinates to plot the frequencies per category text(x_coo, 0, labels = paste0("n = ", res$freq), pos = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.