Paired t-test In the video, you learned how paired t-tests can be more powerful than regular t-tests. During this exercise, you will see an example demonstrating this. The first step will be to simulate data. Similar data might come from a people's weights before or after a drug treatment or amount of money spent by a customer before or after a seeing a commercial. Simulated data allows you to know the properties of the data and check to see if your model behaves as expected. R comes with many distributions including the normal. Your simulated data will have unequal variance (that is, the standard deviations will be different). The second step will be to analyze the data with both a paired and regular t-test. Last, you will be asked about the results from the paired t-tests. # Set the seed to be 345659 set.seed(345659) # Model 10 individuals n_ind <- 10 # simulate before with mean of 0 and sd of 0.5 before <- rnorm(n = n_ind, mean = 0, sd = 0.5) # simulate after with mean effect of 4.5 and standard devation of 5 after <- before + rnorm(n = n_ind, mean = 4.5, sd = 5) # Run a standard, non-paired t-test t.test(x = before, y = after, paired = FALSE) # Run a standard, paired t-test t.test(x = before, y = after, paired = TRUE) Notice how the paired t-test has a larger t-score. The paired t-test is more powerful because it accounts for individual variability. ############################################################################################ Repeated measures ANOVA In the previous exercise, you saw how a paired t-test is more powerful than a regular t-test. During this exercise, you will see how statistical methods generalize. First, you will see how a paired t-test is a special case of a repeated measures ANOVA. In the process, you will see how a repeated measures ANOVA is a special case of a mixed-effects model by using lmer() in R. The first part of this exercise will consist of transforming the simulated data from two vectors into a data.frame(). The second part will have you examine the model results to see how they are different. The third part will have you examine the outputs of the models and compare the results. library(lmerTest) # Create the data.frame, using the variables from the previous exercise. # y is the joined vectors before and after. # trial is the repeated names before and after, each one repeated n_ind # ind is the letter of the individual, repeated 2 times (because there were two observations) dat <- data.frame(y = c(before, after), trial = rep(c("before", "after"), each = n_ind), ind = rep(letters[1:n_ind], times = 2)) # Run a standard, paired t-test t.test(y ~ trial, data = dat, paired = TRUE) # Run a lmer and save it as lmer_out lmer_out <- lmer(y ~ trial + (1 | ind), data = dat) # Look at the summary() of lmer_out summary(lmer_out) The t-test does not provide an intercept estimate. The main purpose of this exercise was to show you a paired t-test is a special case of repeated measures ANOVA and a repeated measures ANOVA is simply a special case of a linear mixed-effects model.