Fitting in a Model a beta distribution with within-subject variable involved: formula requested

82 Views Asked by At

The distribution of my dependent variable called st follows the Beta distribution (visible through the command descdist). Now I have to create my model. The only problem is that my experimental design is a 3x2, where I have an IV called temp, a factor with 3 levels measured within participants (the same participants at different time), and an IV called cond, a factor with 2 levels measured as a between-participants effect (two different groups). I want to see both main effects and interaction effects. So far I have applied the betareg() formula for beta distribution after fitting the distribution with fitdist(). The only problem is that I don't know how in the betareg() formula I can indicate that my temp variable is within while my cond variable is between subjects. Can you help me out?

I tried to apply this formula:

MSTb=betareg(scaledst~temp*cond, data=ds.cy)

and then the ANOVA

Anova(MSTB)

It gives me a result but I think it doesn't considered the repeated measure situation.

Applying this formula instead doesn't work:

MSTb=betareg(scaledst~temp*cond+(1|id), data=ds.cy)

Where "id" is the Code of the participants to filter. It gives me this error: Error in

`contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  the contrast can be applied only to factors variable with 2 or more levels 
In addition: Warning message:
In Ops.factor(1, id) : ‘|’ not meaningful for factors 

neither this one:

betareg(scaledst~temp*cond+(1+temp|id), data=ds.cy)

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels
In addition: Warning messages:
1: In Ops.factor(1, temp) : ‘+’ not meaningful for factors
2: In Ops.factor(1 + temp, id) : ‘|’ not meaningful for factors
1

There are 1 best solutions below

1
Ben Bolker On

betareg doesn't handle mixed models/random effects, so its formula processor is getting confused. You could try glmmTMB:

library(glmmTMB)
MSTb <- glmmTMB(scaledst~temp*cond+(1|id), data=ds.cy, family = beta_family)

Since temp is a within-subjects variable, and you have more than two levels (so the within-subject variation won't be confounded with the residual variation), you could try

scaledst~temp*cond+(temp|id)

to account for among-subject variation in the effect of temperature.

I believe the GLMMadaptive and brms packages also handle mixed models with Beta-distributed responses (although the Mixed Models task view is less clear on this than it might be ...)


PS it doesn't really make sense to use descdist and fitdist to characterize the marginal (overall) distribution of your response; you need to evaluate whether the conditional distribution of the data follows some particular assumed distribution sufficiently well ...