# truelies-package: truelies: Bayesian Methods to Estimate the Proportion of... In truelies: Bayesian Methods to Estimate the Proportion of Liars in Coin Flip Experiments

## Description

Implements Bayesian methods, described in Hugh-Jones (2019) <doi:10.1007/s40881-019-00069-x>, for estimating the proportion of liars in coin flip-style experiments, where subjects report a random outcome and are paid for reporting a "good" outcome.

## Usage

To estimate the proportion of liars in an experiment, use `update_prior()` followed by `dist_mean()`:

 ```1 2``` ```posterior <- update_prior(heads = 33, N = 50, P = 0.5, prior = dunif) dist_mean(posterior) ```

To get confidence intervals for an estimate, use `dist_hdr()`:

 `1` ```dist_hdr(posterior, conf_level = 0.95) ```

To test whether two different samples have the same proportion of liars, use `difference_dist()` followed by `dist_hdr()`:

 ```1 2 3``` ```p2 <- update_prior(heads = 42, N = 49, P = 0.5, prior = dunif) dd <- difference_dist(posterior, p2) dist_hdr(dd, 0.95, bounds = c(-1, 1)) ```

To test power for detecting a given proportion of liars, use `power_calc()`:

 `1` ```power_calc(N = 100, P = 0.5, lambda = 0.2) ```

To test power for detecting differences between groups, use `power_calc_difference()`:

 `1` ```power_calc_difference(N1 = 100, P = 5/6, lambda1 = 0.1, lambda2 = 0.25) ```

To compare different samples by empirical Bayes estimation, use `empirical_bayes()`:

 ```1 2 3``` ```heads <- c(Baseline = 30, Treatment1 = 38, Treatment2 = 45) N <- c(50, 52, 57) result <- empirical_bayes(heads, N, P = 0.5) ```

## Testing the package

To run tests on the package:

 `1` ```source(system.file("test-statistics.R", package = "truelies")) ```

You will need dplyr, purrr, tidyr and ggplot2 installed.

This will take some time and will produce data frames of test results for different parameter values, along with some plots.

David Hugh-Jones

## References

Hugh-Jones, David (2019). True Lies: Comment on Garbarino, Slonim and Villeval (2018). Journal of the Economic Science Association. https://link.springer.com/article/10.1007/s40881-019-00069-x.