Confidence-Intervals-for-Frequencies {REdaS}R Documentation

Confidence Intervals for Relative Frequencies

Description

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.

Usage

freqCI(x, level = 0.95)

## S3 method for class 'freqCI'
print(x, percent = TRUE, digits, ...)

## S3 method for class 'freqCI'
barplot(height, percent = TRUE, ...)

Arguments

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 'table' of frequencies (produced using table or as.table)

level

a numeric vector of confidence levels in (0,\,1).

percent

if TRUE, all values are printed as percentages, else relative frequencies are printed.

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 'freqCI' must be used with the generic barplot function.

...

further arguments.

Details

ref to the book

Value

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.

Author(s)

Marco J. Maier

See Also

table, as.table, barplot

Examples

# 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)

[Package REdaS version 0.9.4 Index]