Error using fitrm function classreg.regr.FormulaProcessor>parseStr
8 views (last 30 days)
Show older comments
I have a dataset with 20 individuals (SubjectID 1-20). These individuals were separated in three groups (n=6, n=6, and n=8) and each group was testet(measured) at a specific time point (T1, T5, T10). Each measurement consisted of 4 consecutive time points (Minute 0, 5, 15, 60, time after exposure). So I have a total of 20 subject with 4 individual measurements and divided into three groups. Using fitrm I want to fit a repeated measurement model with my readout parameter x to look at interaction of T1,T2,T3 with time after exposure. I defined the modelspec as:
modelspec = 'X ~ Timepoint * TimeafterExp + (1|SubjectID)';
Data is a 80x4 table with the variables SubjectID, Timepoint, TimeafterExp, X.
When I run the following code:
rm=fitrm(data, modelspec);
I get the following error:
Error using classreg.regr.FormulaProcessor>parseStr
Unable to understand the character vector or string scalar 'X ~ Timepoint * TimeafterExp + (1|SubjectID)'.
Error in classreg.regr.FormulaProcessor (line 374)
[f.str,f.tree] = parseStr(f,modelSpec);
Error in classreg.regr.MultivariateLinearFormula (line 46)
f = f@classreg.regr.FormulaProcessor(varargin{:});
Error in RepeatedMeasuresModel.fit (line 1314)
formula = classreg.regr.MultivariateLinearFormula(model,varNames);
Error in fitrm (line 77)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Error in untitled2 (line 25)
rm=fitrm(data, modelspec);
I appreciate your help!
2 Comments
the cyclist
on 31 Jan 2024
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
Accepted Answer
the cyclist
on 31 Jan 2024
load("data.mat","data")
modelspec = 'X ~ Timepoint * TimeafterExp + (1|SubjectID)';
mdl=fitlme(data, modelspec)
If you want to use the repeated measures model, I believe you need to "unstack" those measures into their own columns, and use the "y1-y4 ~ ..." form of the model spec.
% Unstack the time after exposure data
data = unstack(data,'X','TimeafterExp');
% Rename the columns
data = renamevars(data,["x0","x5","x15","x60"],["y1","y2","y3","y4"])
% Define the new modelspec
modelspec = 'y1-y4 ~ Timepoint';
rm = fitrm(data, modelspec)
Disclaimer: I got that model to run, but I am not certain it is the model you intend.
Also, I think in the repeated measures model you lose the information that your measurements come at different time spacings. You keep that info in the mixed effects model.
I hope that helps!
More Answers (1)
Harald
on 31 Jan 2024
Hi,
I am not an expert here but will give it a try.
In the "More About" section of the documentation of fitrm, there is a section on Wilkinson Notation and it does not go into the use of |. Thus I suppose it is not supported for this type of model.
https://www.mathworks.com/help/stats/wilkinson-notation.html states that the | syntax is supported by random-effects and mixed-effects models. For example, fitlme is such a model and thus in its documentation refers to the | syntax. Also, the following works:
mdl=fitlme(data, modelspec);
Does this provide you the intended type of model?
Best wishes,
Harald
0 Comments
See Also
Categories
Find more on Repeated Measures and MANOVA in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!