Posthoc (planned) comparisons as contrasts between different levels of a regressor, in fitlme

15 views (last 30 days)
I have participant data for 5 different rating dimensions (A to E), and I have fitted linear mixed-effects models, separately for each rating, with several fixed- and random-effects predictors:
tbl = table(M.rating_A, M.groupSize, M.cond, M.rep, M.training, M.id_rater, M.melody, 'VariableNames',{'ratings' 'groupSize' 'cond' 'rep' 'training' 'id_rater' 'melody'});
formula = 'ratings ~ groupSize + cond + rep + training + (1|id_rater) + (1|melody)';
lme.rating_A = fitlme(tbl,formula);
I'm interested in running post-hoc (planned) comparisons between the different levels of some of those predictors, e.g. see if one type of learning condition (`cond`) leads to higher rating_A scores thann another type.
To that end, I tried to define contrasts with coefTest, as shown here. I'm probably misunderstanding how the contrast vector is coded, but those contrasts appear to compare regressors to one another, isntead of different levels of a single regressor?!
In any case, the stats reported in my fitlme results suggest the regressors are treated as continuous instead of the categorical variables they in fact are, so I converted all variables from double to categorical or string, but then fitlme wont accept them as inputs:
M_categ = convertvars(M,{'groupSize', 'cond', 'rep', 'id_rater','melody'},"string"); % same if converting to categorical, or cellstr
tbl = table(M_categ.rating_A, M_categ.groupSize, M_categ.cond, M_categ.rep, M_categ.training, M_categ.id_rater, M_categ.melody, 'VariableNames',{'ratings' 'groupSize' 'cond' 'rep' 'training' 'id_rater' 'melody'});
Error using classreg.regr.lmeutils.StandardLinearLikeMixedModel/validateInputs
I then attempted the same by using nominal(), which still gives an error:
tbl = table(M.rating_A, nominal(M.groupSize), nominal(M.cond), nominal(M.rep), M.training, nominal(M.id_rater), nominal(M.melody), 'VariableNames',{'ratings' 'groupSize' 'cond' 'rep' 'training' 'id_rater' 'melody'});
lme.rating_A = fitlme(tbl,formula);
Fixed Effects design matrix X must be of full column rank.
Any advice? Do I need to run the LME using some function other than fitlme? Or do I need to call fitlme with different parameters (e.g. different dummy coding), that later allow comparing levels within any one given regressor?
Thanks in advance!

Answers (1)

the cyclist
the cyclist on 7 Jun 2023
Edited: the cyclist on 7 Jun 2023
I'm not certain you can fit the model you want in MATLAB, but I think your best bet is to fit a generalized linear mixed effects model, using fitglme.
The reason that fitlme didn't accept categorical predictors is that only the grouping variables can be categorical in a (non-"generalized") linear model. fitglme will handle those correctly, by using the data type of the input. (So, you will need to convert to categorical, as you tried to do with fitlme.)
I didn't quite understand how you are handling your ratings as response variables, as they also seemed categorical. But, I do think fitglme is probably closest to what you want.
  4 Comments
z8080
z8080 on 17 Jul 2023
Hi @the cyclist, did you meanwhile by any chance have anything else you could add to your already helpful answer? Thanks again!

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!