blob: 6cf9befa509e6ed3f9ba1964080cbbce332f1f6b [file] [log] [blame]
Marc Kupietzdcc1de62019-10-04 09:10:36 +02001% 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 Kupietz71d6e052019-11-22 18:42:10 +01007ci(df, x = totalResults, N = total, conf.level = 0.95)
Marc Kupietzdcc1de62019-10-04 09:10:36 +02008}
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
17be a single number between 0 and 1.}
18}
19\description{
20Using \code{\link{prop.test}}, \code{ci} adds three columns to a data frame:
Marc Kupietz3f575282019-10-04 14:46:04 +0200211. relative frequency (\code{f})
222. lower bound of a confidence interval (\code{ci.low})
233. upper bound of a confidence interval
Marc Kupietzdcc1de62019-10-04 09:10:36 +020024}
25\examples{
Marc Kupietz05b22772020-02-18 21:58:42 +010026\donttest{
Marc Kupietzdcc1de62019-10-04 09:10:36 +020027library(ggplot2)
28kco <- new("KorAPConnection", verbose=TRUE)
29expand_grid(year=2015:2018, alternatives=c("Hate Speech", "Hatespeech")) \%>\%
30 bind_cols(corpusQuery(kco, .$alternatives, sprintf("pubDate in \%d", .$year))) \%>\%
Marc Kupietz71d6e052019-11-22 18:42:10 +010031 mutate(total=corpusStats(kco, vc=vc)$tokens) \%>\%
Marc Kupietzdcc1de62019-10-04 09:10:36 +020032 ci() \%>\%
33 ggplot(aes(x=year, y=f, fill=query, color=query, ymin=conf.low, ymax=conf.high)) +
34 geom_point() + geom_line() + geom_ribbon(alpha=.3)
Marc Kupietz05b22772020-02-18 21:58:42 +010035}
Marc Kupietzdcc1de62019-10-04 09:10:36 +020036}
Marc Kupietz3f575282019-10-04 14:46:04 +020037\seealso{
38\code{ci} is alread included in \code{\link{frequencyQuery}}
39}