Subscript indices error on fitrm with NaN values

2 次查看(过去 30 天)
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

回答(1 个)

Abhaya
Abhaya 2024-12-9
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.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by