matlab dummyvar is creating extra binary variable

2 ビュー (過去 30 日間)
MB
MB 2019 年 3 月 15 日
編集済み: MB 2019 年 3 月 16 日
Let's say I have a categorical variable with level {'1', '2', '3'}. Now in ideal case, there should be 2 binary variable - b0 and b1 and above categorical variable should be mapped as b0=0,b1=0 for '1', b0=1,b1=0 for '2' and b0=0,b1=1 for '3'.
However, Matlab dummyvar is creating b0,b1,b2 binary variables. How can I get only 2 binary variables and above representation?
cat ={'1','2','3'}'
cat1 = categorical(cat)
result = dummyvar(cat1)
result =
1 0 0
0 1 0
0 0 1

採用された回答

Jeff Miller
Jeff Miller 2019 年 3 月 16 日
I guess there is a typo in your question and you really want ''b0=1,b1=0 for '2'".
Notice that you get what (I think) you want if you just drop the first column created by dummyvar.
This explanation of dummy indicator variables may be helpful: look here
  1 件のコメント
MB
MB 2019 年 3 月 16 日
Yes- thank you. I have corrected the typo and it seems to be matching with my requirement after dropping the first column.
I was just expecting 'dummyvar' to be equivalent to 'asfactor' in R but apparently it's not.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by