Creating a design matrix for linear mixed effect modelling
19 views (last 30 days)
Show older comments
I am very new to matlab and can't seem to figure this out. I am trying to analyze some data using linear mixed effect analysis, but am stuck on the design matrix step. My fixed effects are patient group and age, and the random effect is subject. Because group is a categorical variable, and only has two levels, from what I understand I need to create one dummy variable (ie the control group), with my patient group being the reference group. Because it is a random intercept and fixed slope model, I think the the first row should just consist of ones, ie:
ones(M,1)
where M = the matrix where my data is stored.
Next,
D = dummyvar(group); % Create dummy variables
X = [ones(n,1) D(:,2) M(:,3) D(:.2).*M(:,3)];
Z = [ones(n,1)];
Where X is the fixed effects design matrix and Z is the random effects design matrix.
I've created an array called "group" with the categorical group coding, yet when I run the dummyvar command I get the following error:
D = dummyvar(group)
Error using reshape
To RESHAPE the number of elements must not change.
Error in dummyvar (line 101)
colidx = reshape(colidx(ones(m,1),:),m*n,1);
Any input at all is appreciated as I'm pretty lost at the moment. Thank you in advance!!
0 Comments
Answers (1)
Antonio DiTommaso
on 18 Feb 2018
You have to nominal your group, try: ngroup = nominal(group) D=dummyvar(ngroup)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!