Error using fitrm function classreg.r​egr.Formul​aProcessor​>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!

采纳的回答

the cyclist
the cyclist 2024-1-31
I agree with @Harald, that a linear mixed effects model is likely a good choice here:
load("data.mat","data")
modelspec = 'X ~ Timepoint * TimeafterExp + (1|SubjectID)';
mdl=fitlme(data, modelspec)
mdl =
Linear mixed-effects model fit by ML Model information: Number of observations 80 Fixed effects coefficients 4 Random effects coefficients 20 Covariance parameters 2 Formula: X ~ 1 + Timepoint*TimeafterExp + (1 | SubjectID) Model fit statistics: AIC BIC LogLikelihood Deviance 734.32 748.61 -361.16 722.32 Fixed effects coefficients (95% CIs): Name Estimate SE tStat DF pValue Lower Upper {'(Intercept)' } 68.273 5.9383 11.497 76 2.6629e-18 56.446 80.101 {'Timepoint' } 0.15558 0.85891 0.18113 76 0.85675 -1.5551 1.8662 {'TimeafterExp' } -0.049118 0.19141 -0.25661 76 0.79817 -0.43034 0.3321 {'Timepoint:TimeafterExp'} 0.019561 0.027685 0.70654 76 0.48201 -0.035579 0.0747 Random effects covariance parameters (95% CIs): Group: SubjectID (20 Levels) Name1 Name2 Type Estimate Lower Upper {'(Intercept)'} {'(Intercept)'} {'std'} 0 NaN NaN Group: Error Name Estimate Lower Upper {'Res Std'} 22.1 18.927 25.803
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');
Warning: Table variable names that were not valid MATLAB identifiers have been modified. Since table variable names must be unique, any table variable names that happened to match the new identifiers also have been modified.
To use the original INDVAR values as table variable names, set 'VariableNamingRule' to 'preserve'.
% Rename the columns
data = renamevars(data,["x0","x5","x15","x60"],["y1","y2","y3","y4"])
data = 20×6 table
SubjectID Timepoint y1 y2 y3 y4 _________ _________ ___ __ __ __ 1 1 71 36 70 75 2 1 87 46 72 79 3 1 90 57 58 41 4 1 90 39 55 64 5 1 96 33 78 83 6 1 91 45 72 46 7 5 93 35 77 71 8 5 101 33 53 83 9 5 101 69 62 82 10 5 86 59 63 74 11 5 100 43 79 93 12 5 110 58 63 90 13 10 98 28 74 74 14 10 81 52 63 82 15 10 92 60 76 80 16 10 117 31 70 91
% Define the new modelspec
modelspec = 'y1-y4 ~ Timepoint';
rm = fitrm(data, modelspec)
rm =
RepeatedMeasuresModel with properties: Between Subjects: BetweenDesign: [20×6 table] ResponseNames: {'y1' 'y2' 'y3' 'y4'} BetweenFactorNames: {'Timepoint'} BetweenModel: '1 + Timepoint' Within Subjects: WithinDesign: [4×1 table] WithinFactorNames: {'Time'} WithinModel: 'separatemeans' Estimates: Coefficients: [2×4 table] Covariance: [4×4 table]
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 个评论
David Obert
David Obert 2024-1-31
Thank you for your help. I appreciate it! I needed the repeated measure model to test my data for sphericity. The only test matlab provides for this is the mauchly function, which needs a rm structure as input (tbl = mauchly(rm)).

请先登录,再进行评论。

更多回答(1 个)

Harald
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

类别

Help CenterFile Exchange 中查找有关 Repeated Measures and MANOVA 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by