How can I avoid error in mnrfit line 164?

9 ビュー (過去 30 日間)
Shiladitya Sen
Shiladitya Sen 2013 年 7 月 19 日
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...

採用された回答

Wayne King
Wayne King 2013 年 7 月 19 日
編集済み: Wayne King 2013 年 7 月 19 日
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.
  1 件のコメント
Shiladitya Sen
Shiladitya Sen 2013 年 7 月 19 日
In that case, how should I perform logistic regression on a sparse dataset like this?

サインインしてコメントする。

その他の回答 (1 件)

Thomas
Thomas 2013 年 7 月 19 日
I'm assuming mnrfit does not like 'NaN' values as its input.
works fine with
x =
0.14 0.66 0.76
0.42 0.04 0.74
0.92 0.85 0.39
0.79 0.93 0.66
0.96 0.68 0.17
y =
-1.00
1.00
-1.00
1.00
-1.00
b=mnrfit(x,y+2)
b =
95.33 47.37
-58.97 -31.76
15.27 6.52
-112.15 -62.24

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by