# Accounting for dependencies between data points within groups

I ran an experiment where participants had to perform perceptual tasks and were assigned to 1 of 3 experimental conditions. In two of the three conditions, participants performed that task in groups of size 5. In the last condition, participants performed the task independently. I am trying to measure the effect of my experimental conditions on the performance of individuals.

I want to compare the performance difference-in-means between participants assigned to condition 1 versus participants assigned to condition 2 (both conditions are done in groups, with different settings).

#(treatment is binary indicating the experimental condition)
fit <- lm(performance ~ treatment , data=df)
tidy(fit)


How can I extend this code to account for dependencies between data points within groups? (I have a variable 'group_id' for each participant)

Also, how do I compare participants assigned to condition 2 versus participants assigned to condition 3 (participants in condition 3 did the task independently, while condition 2 did it in a group -- hence the within group dependency)

This looks like a classic situation for a random effects model (assuming you had a non-tiny number of groups in each treatment). Using R:

library('lme4')
lmer(performance ~ treatment + (1|group), data=df)

• Thanks. But how can I obtain the P-value from this? (this provides the same effect size, as expected, as the difference-in-mean method .. I want to compute a P-value that accounts for the dependencies) Jun 1, 2017 at 6:25
• There are simple commands in R to get p-values... simple to execute, but difficult to understand! Understanding the challenges of getting p-values from random effects models is really crucial to knowing how to interpret your model. Therefore, rather than giving a "plug-and-chug" answer, I'll point you to this webpage, which is the canonical reference nowadays for random effects models in R. glmm.wikidot.com/faq#df Jun 1, 2017 at 6:28
• Once you've digested that, you might check out either of the R packages mentioned here: mindingthebrain.blogspot.com/2014/02/… Jun 1, 2017 at 6:32

For p-values, use the package lmerTest. Load it BEFORE the model fitting.

library('lme4')
library('lmerTest')
mod <- lmer(performance ~ treatment + (1|group), data=df)
summary(mod)