In fitglm(), logistic regression, when response is two columns matrix, the response in the table can not be recognized

8 views (last 30 days)
age = categorical([1,1,1,1,1,2,2,2,2,2,3,3,3,3,3]');
stage = categorical([1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]');
y = [11,15,2,5,18,3,3,5,0,1,4,4,3,3,2]';
m = [12,16,4,18,19,4,7,8,25,3,5,12,15,93,5]';
resp = [y,m];
data = table(resp, age, stage);
% data = table(age, stage, resp); % This works.
mdl = fitglm(data, 'resp ~ age + stage', 'Distribution', 'binomial', 'link', 'logit');
When 'resp' is at the last column in the table, this works well. But when resp is not in the last column, fitglm() doesn't work;
The error is "Response variable must be a numeric vector".
  3 Comments
Hang Du
Hang Du on 23 Feb 2019
I submitted a bug report and the following is the reply:
%%%%%%%%%%%%
I understand that you are facing an issue while using "fitglm()" to perform linear regression on your data that has multi-variate response (i.e. the response variable has more than one column). Linear regression with "fitglm()" is performed between a single response variable (i.e. an n-by-1 vector) and one or more explanatory (or, independent variables).
Hence, in your use case, you could use the 'mvregress' function which is used to fit a model using multi-variate regression. The following documentation links might be useful to you:
However, I have also filed a bug report as to why the function "fitglm()" works differently when you place the response variable as the last versus when you place it elsewhere in your table.
%%%%%%%%%%%%%
the cyclist
the cyclist on 25 Feb 2019
Thanks for submitting the bug report, and reporting back!
Searching the bug reports for "fitglm" doesn't currently find anything, but hopefully it gets fixed in the next release.

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!