---
title: "Check your understanding of how to set Bayesian priors"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)
```


```{r where}

question("What information can you use when setting priors? (Select all that apply)",
  answer("Means & sds from related previous studies", correct = TRUE),
  answer("Approximate means & sds from your current data"),
  answer("The range of possible values of the dependent variable", correct = TRUE),
  answer("Results from a previous analysis of your current data"),
  answer("Effect sizes from previous studies", correct = TRUE),
  correct = "Correct! You can use any information you could have known before running your current study.",
  incorrect = "Incorrect. Did you select option 2 or 4? Priors can only include information you could have known before running your current study. Pretend you don't know anything about your current data!",
  allow_retry = TRUE)

```


```{r example-a}

question("Say you have conducted an experiment with 2 conditions (control and treatment). Your outcome variable is a continuous variable with a range [0,100]. You have no previous studies to use for your priors, so you are going to set weakly informative priors that just tell the model which values are implausible. What values do you use for the priors? Assume you're using our template, which requires priors to have normal distributions.",
  answer("Control mean: 50 | Control max value: 50 | Effect size mean: 0 | Effect sd: 50"),
  answer("Control mean: 50 | Control sd: 25 | Effect size mean: 0 | Effect sd: 25", correct = TRUE),
  answer("Control mean: 0 | Control sd: 50 | Effect size mean: 0 | Effect sd: 50"),
  answer("Control mean: 50 | Control sd: 25 | Effect size mean: 50 | Effect sd: 25"),
  incorrect = "Incorrect. Your control mean is the mean of the range (so here, mean = 50). In our template, which uses a normal distribution for priors, you want your max value to be 2 sds away from the mean: (100 - 50)/2 = 25. You don't have any info about an effect so you set the effect mean = 0 and the effect sd = control sd (25).",
  allow_retry = TRUE)

```


```{r example-b}

question("Say you have conducted an experiment with 2 conditions (a control condition and 2 treatment conditions). Participants in the experiment were asked to rate a product from 0 to 5 stars. You have no previous literature to use to set priors, and you know from exploratory analysis that your study participants rated the product with an overall mean score of 3.5, and sd of 0.5. What values do you use for the priors? Assume you're using our template, which requires priors to have normal distributions.",
  answer("Control mean: 3.5 | Control sd: 0.5 | Effect size mean: 0 | Effect sd: 0.5"),
  answer("Control mean: 2.5 | Control sd: 2.5 | Effect size mean: 0 | Effect sd: 2.5"),
  answer("Control mean: 2.5 | Control sd: 1.25 | Effect size mean: 0 | Effect sd: 1.25", correct = TRUE),
  answer("Control mean: 3.5 | Control sd: 5 | Effect size mean: 0 | Effect sd: 5"),
  incorrect = "Incorrect. (Sort of) trick question - you shouldn't use any of the provided information about your current data to set priors. Your control mean is the mean of the range (so here, mean = 2.5). In our template, which uses a normal distribution for priors, you want your max value to be 2 sds away from the mean: (5 - 2.5)/2 = 1.25. You don't have any info about an effect so you set the effect mean = 0 and the effect sd = control sd (1.25).",
  allow_retry = TRUE)

```


```{r example-c}

question("Say you have conducted an experiment with 2 conditions (control and treatment). Participants in the experiment were asked to rate a product from 0 to 5 stars. This time, you have previous literature to use to set priors, which says that the mean score is 3 in the control condition, with a sd of 0.25, and a mean score that is 0.75 points higher in the treatment condition, with an sd of 0.5. What values do you use for the priors? Assume you're using our template, which requires priors to have normal distributions.",
  answer("Control mean: 3 | Control sd: 0.25 | Effect size mean: 0.75 | Effect sd: 0.5", correct = TRUE),
  answer("Control mean: 3 | Control sd: 0.25 | Effect size mean: 3.75 | Effect sd: 0.5"),
  answer("Control mean: 2.5 | Control sd: 1.25 | Effect size mean: 0 | Effect sd: 1.25"),
  answer("Control mean: 0 | Control sd: 5 | Effect size mean: 0 | Effect sd: 5"),
  incorrect = "Incorrect. Your control mean and sd are taken from the previous literature: 3 and 0.25, respectively. The effect size is also taken straight from the literature: mean = 0.75 and sd = 0.5.",
  allow_retry = TRUE)

```


```{r example-d}

question("Say you have gathered data on 25 different subreddits (message forums) and you want to compare the word counts of comments on each subreddit. Say that you know from a previously-published study that word counts of comments on subreddits follow a normal distribution with a mean of 85 and a sd of 35. You have no previous information about the individual subreddits you are using in your current study, so have no information about what the 'effect size' might be between the different subreddits. What values do you use for the priors?",
  answer("Control mean: 85 | Control sd: 35 | Effect size mean: 85 | Effect sd: 35"),
  answer("Control mean: 0 | Control sd: 35 | Effect size mean: 25 | Effect sd: 35"),
  answer("Control mean: 35 | Control sd: 85 | Effect size mean: 0 | Effect sd: 25"),
  answer("Control mean: 85 | Control sd: 35 | Effect size mean: 0 | Effect sd: 35", correct = TRUE),
  incorrect = "Incorrect. Your control mean and control sd are the mean and sd of the previous study. You have no information about how the 25 individual subreddits might be different from one another, so you set the 'effect size' mean = 0 and the effect sd = control sd (35).",
  allow_retry = TRUE)

```


```{r definition}

question("When you set priors, you're giving your best guess of what the probability distribution of some unknown quantity would be, if you didn't know anything about the data from your current study. What is that unknown quantity?",
  answer("The parameters of the model", correct = TRUE),
  answer("The outcome variable"),
  correct = "Correct! Priors are the probability distributions of the *parameters*, not the outcome variable. Note though that the two values may be identical if your model has only main effects with dummy variables.",
  incorrect = "Incorrect. Priors are the probability distributions of the parameters, not the outcome variable. Note though that the two values may be identical if your model has only main effects with dummy variables.",
  allow_retry = TRUE)

```

All done! You can head back to the analysis template.
