1
$\begingroup$

I would like some help with setting up a linear mixed model with paired data.

I have a dataset where each participant is tested twice: either with a manipulation or without a manipulation. There are two types of manipulations (either 1 or 2 or no manipulation, 0) and we know in which order the manipulation was presented for each subject.

Here's example data:

data_ex <- data.frame( pnum = rep(1:10, each=2),
                       manipulation =  c(0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2),
                       order_manipulation = c(0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1),
                       man_onoff = c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1),
                       score = floor(runif(20, min=0, max=101)))

I would like to find out what the influence of each type of manipulation is on a particular outcome measurement("score"), while controlling for the fact that each participant is tested twice (by adding + (1|pnum)). So basically, is there a significant difference between manipulation 1 and baseline on performance? As well as, is there a significant difference between manipulation 2 and baseline on performance?

mod <- lmer(score ~ as.factor(manipulation) + (1|pnum), data = data_ex)

>summary(mod)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: score ~ as.factor(manipulation) + (1 | pnum)
   Data: data_ex

REML criterion at convergence: 165.3

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-1.78197 -0.43635 -0.06185  0.61631  1.26529 

Random effects:
 Groups   Name        Variance Std.Dev.
 pnum     (Intercept) 359.7    18.97   
 Residual             430.5    20.75   
Number of obs: 20, groups:  pnum, 10

Fixed effects:
                         Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)                50.200      8.889  14.344   5.647 5.49e-05 ***
as.factor(manipulation)1  -21.495     12.196  10.358  -1.762    0.107    
as.factor(manipulation)2  -10.905     12.196  10.358  -0.894    0.392    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) as.()1
as.fctr(m)1 -0.397       
as.fctr(m)2 -0.397  0.158

With this model, I get p-values for the contrast between manipulation type 1 and baseline (0) as well as contrast between manipulation type 2 and baseline (0). However, the model takes all the zeroes of baseline to contrast the manipulation type with. But since I'm working with paired data, I would like the model to only contrast the manipulation data with the baseline of the participants that actually had those manipulations. Concrete this would mean that the model should only contrast manipulation vs baseline for type 1 in subjects 1,3,5,7 and 9. And only contrast manipulation vs baseline for type 2 in subjects 2,4,6,8 and 10.

How could I best re-write my model to take this paired data into account? Could I add some of my order information variables into the model and if so, as fixed and/or random effects or do I need to reshape my data?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.