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:
t.test()function handles one-sample, independent samples and paired samples t-tests
chisq.test()function handles chi-square tests of independence and Pearson goodness of fit tests
prop.test()function tests for the equality of two proportions.
binom.test()function allows you to do a binomial test of choice proportion against a known rate
wilcox.test()function handles one- and two-sample nonparametric tests of equality of means
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:
lm()function, and model comparison using the
brm()function (in the
brms) package, and model comparison using Bayes factors
lmer()function (in the
glmer()function (also from
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)