```
library(here)
library(tidyverse)
library(lme4)
library(brms)
library(tidybayes)
frames <- read_csv(here("samplingframes", "data", "data_samplesize.csv"))
set.seed(1) # for replicability
```

Because R is a *statistical* programming language it comes with a lot of hypothesis tests and tools built in, and of course there is an overwhelming number of packages out there that extend this. It is impossible to cover the whole thing in one tutorial, so I’m going to be a little picky. For example, I’m going to skip over the most commonly used classical tests, because they’re comparatively easy to learn and it’s not the best use of our time! For future reference though:

- The
`t.test()`

function handles one-sample, independent samples and paired samples t-tests - The
`chisq.test()`

function handles chi-square tests of independence and Pearson goodness of fit tests - The
`prop.test()`

function tests for the equality of two proportions. - The
`binom.test()`

function allows you to do a binomial test of choice proportion against a known rate - The
`wilcox.test()`

function handles one- and two-sample nonparametric tests of equality of means - The
`cor.test()`

function tests the significance of a correlation

Of course, there are many, many others! What we’re going to focus on here is:

- Linear modelling with the
`lm()`

function, and model comparison using the`anova()`

function - Bayesian regression using the
`brm()`

function (in the`brms`

) package, and model comparison using Bayes factors - Linear mixed models with the
`lmer()`

function (in the`lme4`

package) - Generalised linear mixed models with the
`glmer()`

function (also from`lme4`

)

One of our goals is to get to the point where we can analyze the sampling frames data from yesterday. After exploring and visualizing these data yesterday, you have some idea of what they look like. Below is a summary plot that shows how generalization curves varied across both conditions (category, property) and sample sizes (small, medium, large).

```
frames_avg <- frames %>%
mutate(sample_size = factor(sample_size, levels = c("small","medium","large"))) %>%
group_by(test_item, condition, sample_size) %>%
summarise(
n = n(),
sd=sd(response),
se=sd/sqrt(n),
response = mean(response),
) %>%
ungroup()
frames_avg %>%
ggplot(aes(x = test_item, y = response, colour = condition)) +
geom_line() +
geom_point() +
geom_errorbar(aes(ymin = response - se, ymax = response + se)) +
facet_wrap(~sample_size)
```