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?

采纳的回答

Star Strider
Star Strider 2022-3-12
The way I read the documentation for using a table (the tbl section), and
  • By default, fitglm takes the last variable as the response variable and the others as the predictor variables.
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
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
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 CenterFile Exchange 中查找有关 Gaussian Process Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by