how does fitglm treat categorical variables?

7 ビュー (過去 30 日間)
Hans van der Horn
Hans van der Horn 2022 年 3 月 6 日
コメント済み: Jeff Miller 2022 年 3 月 7 日
Dear all,
I'd like to verify something about categorical variables in fitglm. As input I use a table which also contains categorical variables (sex (0 vs 1), and education (on a scale 1 to 7). If I understand the documentation correctly, fitglm automatically treats these as categorical, and it also automatically dummy codes when necessary? (for education in this case). Is this correct?
Thanks very much.
Best
Hans van der Horn

採用された回答

Jeff Miller
Jeff Miller 2022 年 3 月 6 日
I don't that is correct. WIth numerical values in the table, I think you have to mark the variables as categorical with something like:
tbl.sex = categorical(tbl.sex);
tbl.education = categorical(tbl.education);
Where there are three or more categories (e.g., education) you can check the df's to make sure that the variable has been treated as categorical (6 dfs) rather than numerical (1 df, essentially a regression slope across 1-7).
  2 件のコメント
Hans van der Horn
Hans van der Horn 2022 年 3 月 7 日
Dear Jeff,
Thanks for your answer. I tried as you suggested and indeed it works better, with now dummy variables defined in the model.
Best Hans
Jeff Miller
Jeff Miller 2022 年 3 月 7 日
Hi Hans,
That sounds good. If this answer solves the problem that you were having, then please accept it using the "Accept" button (so that the question no longer appears to be open).
Jeff

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

その他の回答 (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