- By default, fitglm takes the last variable as the response variable and the others as the predictor variables.
How to concatenate a double array and a categorical array?
45 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I was trying to run a binary logistic regression using the function fitglm(Tf{:,3:11},Tf.Var2,'Distribution','binomial'). However, it returns me the error "Unable to concatenate a double array and a categorical array." The reason for this is that Tf{:,4} is the categorical variable gender whereas other variables are double. I am wondering how to include both numeric and catogorical variables as predictors in this logistic regression model?
0 件のコメント
採用された回答
Star Strider
2022 年 3 月 12 日
it might be necessary to create a new table by changing the order of the variables, for example:
Tf2 = table(TF{:,3:11},TF.Var2)
and then use ‘Tf2’ as the argument table.
Without the actual ‘Tf’ to experiment with, this is the best I can do.
3 件のコメント
Star Strider
2022 年 3 月 12 日
As always, my plesaure!
I do not understand what ‘Nuisance variables’ are. If they are Dummy variables, then Automatic Creation of Dummy Variables and specifically Dummy Variables with Reference Group would likely apply.
I do not have much experience with regression applications that create ‘dummy variables’. It appears that they are created as numeric equivalents to categorical variables, and that would appear to me to be appropriate. It may not be possible to prevent their appearing.
Peter Perkins
2022 年 3 月 14 日
Weixi, I strongly recommend that you use the table itself as the input to fitglm, i.e. this syntax:
GLM = fitglm(TBL,MODELSPEC)
which is what SS is suggesting. Tht way you do not need to concatenate your categorical with the numeric vars, or "convert" the categorical to numeric to do so.
However:
fit = fitglm(TBL,<model>,"ResponseVariable",2)
will do it without needing to rearrange the variables. I don't know what your model specification would be. In my world, "controlling for nuisance variables" might mean including them as predictors. The doc will show how to do that.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Gaussian Process Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!