Marc Kupietz | dcc1de6 | 2019-10-04 09:10:36 +0200 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/ci.R |
| 3 | \name{ci} |
| 4 | \alias{ci} |
| 5 | \title{Add confidence interval and relative frequency variables} |
| 6 | \usage{ |
Marc Kupietz | 71d6e05 | 2019-11-22 18:42:10 +0100 | [diff] [blame] | 7 | ci(df, x = totalResults, N = total, conf.level = 0.95) |
Marc Kupietz | dcc1de6 | 2019-10-04 09:10:36 +0200 | [diff] [blame] | 8 | } |
| 9 | \arguments{ |
| 10 | \item{df}{table with columns for absolute and total frequencies.} |
| 11 | |
| 12 | \item{x}{column with the observed absolute frequency.} |
| 13 | |
| 14 | \item{N}{column with the total frequncies} |
| 15 | |
| 16 | \item{conf.level}{confidence level of the returned confidence interval. Must |
| 17 | be a single number between 0 and 1.} |
| 18 | } |
| 19 | \description{ |
| 20 | Using \code{\link{prop.test}}, \code{ci} adds three columns to a data frame: |
Marc Kupietz | 3f57528 | 2019-10-04 14:46:04 +0200 | [diff] [blame] | 21 | 1. relative frequency (\code{f}) |
| 22 | 2. lower bound of a confidence interval (\code{ci.low}) |
| 23 | 3. upper bound of a confidence interval |
Marc Kupietz | dcc1de6 | 2019-10-04 09:10:36 +0200 | [diff] [blame] | 24 | } |
| 25 | \examples{ |
| 26 | library(ggplot2) |
| 27 | kco <- new("KorAPConnection", verbose=TRUE) |
| 28 | expand_grid(year=2015:2018, alternatives=c("Hate Speech", "Hatespeech")) \%>\% |
| 29 | bind_cols(corpusQuery(kco, .$alternatives, sprintf("pubDate in \%d", .$year))) \%>\% |
Marc Kupietz | 71d6e05 | 2019-11-22 18:42:10 +0100 | [diff] [blame] | 30 | mutate(total=corpusStats(kco, vc=vc)$tokens) \%>\% |
Marc Kupietz | dcc1de6 | 2019-10-04 09:10:36 +0200 | [diff] [blame] | 31 | ci() \%>\% |
| 32 | ggplot(aes(x=year, y=f, fill=query, color=query, ymin=conf.low, ymax=conf.high)) + |
| 33 | geom_point() + geom_line() + geom_ribbon(alpha=.3) |
| 34 | |
| 35 | } |
Marc Kupietz | 3f57528 | 2019-10-04 14:46:04 +0200 | [diff] [blame] | 36 | \seealso{ |
| 37 | \code{ci} is alread included in \code{\link{frequencyQuery}} |
| 38 | } |