- 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?
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Weixi Kang
el 11 de Mzo. de 2022
Comentada: Peter Perkins
el 14 de Mzo. de 2022
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 comentarios
Respuesta aceptada
Star Strider
el 12 de Mzo. de 2022
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 comentarios
Star Strider
el 12 de Mzo. de 2022
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
el 14 de Mzo. de 2022
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Gaussian Process Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!