- 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 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Weixi Kang
il 11 Mar 2022
Commentato: Peter Perkins
il 14 Mar 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 Commenti
Risposta accettata
Star Strider
il 12 Mar 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 Commenti
Star Strider
il 12 Mar 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
il 14 Mar 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Gaussian Process Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!