psychcoder
psychcoder

Reputation: 675

lmer model for proportion of values in dataframe

I have a dataframe in R in which I'd like to calculate if there is a significantly higher proportion of A's in the column value between condition X and Y.

toy dataset below:

subject   condition   value   proportion

1         X           A       .33
1         X           B       .33
1         Y           A       .5
1         X           C       .33
1         Y           B       .5
2         X           A       1
2         Y           A       .5
2         Y           B       .5
3         X           B       1
3         Y           A       .5
3         Y           B       .5
...

But I'm having trouble putting a lmer model together for this, since I'm comparing proportions. Does anyone have advice? Below is the code that I'm working with that is incorrect:

m1 <- lmer(value ~ condition + (1 + condition | subject), data = data)
summary(m1)

Upvotes: 0

Views: 186

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226732

This sounds like a logistic regression. Try:

glmer(as.numeric(value=="A") ~ condition + (1 + condition | subject), 
         data = data, family=binomial)

Upvotes: 1

Related Questions