MATLAB: How to avoid error in mnrfit line 164

mnrfit

I am getting an error message when I use the mnrfit function on a matrix X and Y like this:
X =
1 NaN 2
NaN 3 NaN
NaN NaN 4
6 NaN NaN
5 NaN NaN
Y =
-1
1
-1
1
-1
b=mnrfit(X,Y+2);
Error using mnrfit (line 164)
X and Y must contain at least one valid observation.
I cannot understand why I'm running into such an error…please advise…

Best Answer

The problem is that you have NaNs in every single row of your X matrix.
As the documentation states:
"mnrfit treats NaNs in X and Y as missing data, and removes the corresponding observations."
Every row in your X matrix is an observation on P predictor variables.
Since you have at least one NaN for every observation, all the observations are removed.