Trouble with glmfit using binomial distribution and logit
3 views (last 30 days)
Show older comments
I'm trying to perform logistic regression on a dataset using glmfit. Here is my code:
N = ones(size(feature));
initcoeff = glmfit(feature(:, 1:(w-1)), [feature(:, w) N], ...
'binomial', 'link', 'logit');
w is the width of feature. feature is an array in which each row is an example, and each column is a feature of that example. The last column is a binary vector with the labels for each example as 0 or 1.
When I use 'binomial' as the distribution, I get the following error:
??? Error using ==> glmfit at 171
Y must be a two column matrix or a vector for the binomial distribution.
Error in ==> comptrain at 28
initcoeff = glmfit(feature(:, 1:(w-1)), [feature(:, w) N], 'binomial', 'link',
'logit');
I'm not sure what to do, because Y (feature(:, w)) is a vector. Using other distributions instead of binomial yields an array index mismatch error from somewhere within glmfit.
Any help would be appreciated. Thanks!
0 Comments
Accepted Answer
Tom Lane
on 6 Apr 2012
The error message is because you have
N = ones(size(feature));
so it is of the size of the whole feature array. You just want
N = ones(size(feature,1),1);
But even easier is to omit N altogether. The default is N=1.
More Answers (0)
See Also
Categories
Find more on Binomial Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!