Error using fitrm function classreg.regr.FormulaProcessor>parseStr
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
the cyclist
2024-1-31
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
采纳的回答
the cyclist
2024-1-31
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!
更多回答(1 个)
Harald
2024-1-31
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Repeated Measures and MANOVA 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!