---
title: "Homework 10"
subtitle: "Psychology 2812B FW23"
output: html_document
---

# Lab Component

## 1. Load the data

We will be working on a fictitious dataset in which male and female mice were tested on spatial memory after receiving either a saline placebo, a low dose of the (fictitious) drug memzipan, or a high dose of memzipan. Thus this is a two-factor between subjects design with drug as one factor with three levels (placebo, low dose, high dose) and sex as a second factor with two levels (male, female). The dependent variable is memory score, higher values are better. The researcher was interested in whether memzipan improves memory and whether it may have different effects for male versus female mice.

Load the data, making sure that the two columns coding the drug and sex factors are indeed loaded as factors not strings. This can be done by passing the `read_csv()` function an argument `col_types="nff"` where `n` indicates that the first column should be loaded as numeric, `f` indicates that the second and third columns should be loaded as factors. You can read more about this argument in the `read_csv()` documentation here: https://readr.tidyverse.org/reference/read_csv.html.

```{r,message=FALSE,warning=FALSE}
library(tidyverse)
mem_data <- read_csv(url("https://www.gribblelab.org/2812/data/mem_data.csv"),
                     col_types="nff")
glimpse(mem_data)
```

## 2. Compute Means

Compute some summary statistics for each of the 6 groups of mice. You can use `group_by()` and `summarize()` to do this. Include the mean, the number of observations, and the standard error of the mean.

```{r}
# your code goes here
```


## 3. Produce a plot

Produce a plot of your choosing showing the means of each of the 6 groups. Organize your plot in a way that makes it intuitive to interpret. Include a title and axis labels. Include a legend if appropriate. Here is a sample plot but this is only one possible way to organize the data. You can produce a plot of your choosing as long as it makes sense for interpreting the data.

```{r}
# your code goes here
```


## 4. Perform a 3x2 factorial ANOVA

Perform a 3x2 factorial ANOVA on the data. Use the `aov()` function. Include the output of the `summary()` function. Write a sentence or two interpreting the results of the ANOVA output.

```{r}
# your code goes here
```

> your text goes here

## 5. Follow-up tests

Write a few sentences to explain what your approach will be for conducting follow-up tests, based on the ANOVA output above in question 4. Which specific tests will you conduct and why? What will your approach be for controlling Type-I error? In the Home Component below you will actually conduct the follow-up tests.

> your text goes here

# Home Component

## 6. Check ANOVA assumptions

Oops! We forgot to check ANOVA assumptions. Check the normality assumption and the homogeneity of variance assumptions for the data. Use the `shapiro.test()` function to check the Normality assumption, and also produce a Q-Q plot. Use the `leveneTest()` function to check the homogeneity of variance assumption. Write a sentence or two interpreting the results of the tests.

### Normality assumption

```{r}
# your code goes here
```

> your text goes here


### Homogeneity of variance assumption

```{r}
# your code goes here
```

> your text goes here


## 7. Follow-up tests

Conduct and interpret the follow-up tests that you described in question 5 above. Also write a sentence or two with your "conclusions" about the data with respect to the original scientific question(s) that the researcher had.

```{r}
# your code goes here
```

> your text goes here

## 8. Effect Size

Compute a measure of effect size for the effect of memzipan on memory score in female mice. Write a sentence or two interpreting the effect size that you compute.

```{r}
# your code goes here
```

> your text goes here

## 9. Power analysis

The researcher notices that the effect of high dose memzipan on memory score in male mice appears small but perhaps non-zero, and they want to design a focused follow-up experiment to try to better test whether high dose memzipan in male mice improves memory.

Conduct a power analysis for a t-test in which placebo and high dose memzipan will be tested in male mice, to determine how many mice per group the researcher would need to achieve 80% power to detect differences between means as large as the difference between means they obtained in the data above for high dose vs placebo in male mice. You can use the `power.t.test()` function in R. To estimate `delta` you can use the difference between means of the male placebo and male high dose groups. To estimate the `sd` parameter you can average the standard deviations of the male high dose and the male placebo groups. Assume a `sig.level` of 0.05. Justify whether you should use a one-sided or two-sided test in your power calculation.

```{r}
# your code goes here
```

> your text goes here
