Subscript indices error on fitrm with NaN values
3 views (last 30 days)
Show older comments
Hello everyone,
I am having issues with creating a repeated measures model with fitrm. The issue occurs when I choose to omit a certain amount of data points within the table and replace with NaN values. What confuses me is that the dataset works with some values replaced with NaN, however,with a certain combination of omitted data points I receive a 'Subscript indices must either be real positive integers or logicals' error.
Here is my code:
load('Bad_ranova.mat');
%Fit Repeated Measures Model
MOS_fitrm = fitrm(t,'neg2del_os-pos2del_fix~Gender*Gait_Parameter','WithinDesign',within);
%Repeated measures ANOVA
MOS_rm = ranova(MOS_fitrm,'WithinModel','BP_Condition*Step_Width');
The tables 't' and 'within' are included as attached matlab structures. Good_ranova.mat runs with no issues, Bad_ranova.mat is the same dataset but with additional data values replaced with NaN (and does not run properly).
Thanks, - JP
2 Comments
Answers (1)
Abhaya
on 9 Dec 2024
Hi JP,
The issue you're encountering is related to how MATLAB ‘fitrm’ function handles missing data. Specifically, ‘fitrm’ function removes any rows that contain missing values (NaN) before fitting the repeated measures model.
In the ‘Bad_ranova.mat’ file, the table ‘t’ contains at least one NaN value in each row. When ‘fitrm’ function is executed, it removes all rows from the ‘t’ table, resulting in an empty table, which triggers the error.
To resolve this issue, you can use any workaround to handle or replace NaN values. For guidance on handling missing data in MATLAB, refer to this resource.
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!