Learn R Programming

RKorAPClient (version 0.5.9)

ci: Add confidence interval and relative frequency variables

Description

Using prop.test, ci adds three columns to a data frame: 1. relative frequency (f) 2. lower bound of a confidence interval (ci.low) 3. upper bound of a confidence interval

Usage

ci(df, x = totalResults, N = total, conf.level = 0.95)

Arguments

df

table with columns for absolute and total frequencies.

x

column with the observed absolute frequency.

N

column with the total frequencies

conf.level

confidence level of the returned confidence interval. Must be a single number between 0 and 1.

See Also

ci is already included in frequencyQuery

Examples

Run this code
# NOT RUN {
library(ggplot2)
kco <- new("KorAPConnection", verbose=TRUE)
expand_grid(year=2015:2018, alternatives=c("Hate Speech", "Hatespeech")) %>%
  bind_cols(corpusQuery(kco, .$alternatives, sprintf("pubDate in %d", .$year))) %>%
  mutate(total=corpusStats(kco, vc=vc)$tokens) %>%
  ci() %>%
  ggplot(aes(x=year, y=f, fill=query, color=query, ymin=conf.low, ymax=conf.high)) +
    geom_point() + geom_line() + geom_ribbon(alpha=.3)
# }

Run the code above in your browser using DataLab