Error using glmfit: Second column in Y?

4 ビュー (過去 30 日間)
Eric
Eric 2017 年 7 月 19 日
編集済み: Walter Roberson 2017 年 7 月 27 日
Hi everyone,
I'm currently trying to use glmfit like this:
B2 = glmfit(x(c,:),y,'binomial');
With y being a n x 1 matrix with 1's and 2's for group one and two. However, it keeps giving me the following error:
For the binomial distribution, Y must be a binary vector or a matrix with two columns with the number of trials in the second column.
My question is: Should I ad a second column with 1:number of observations? Example below:
y = [1,1; 1,2; 1,3; 1,4; 2,5; 2,6; 2,7; 2,8];
Best regards,
Eric

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 27 日
編集済み: Walter Roberson 2017 年 7 月 27 日
B2 = glmfit(x(c,:), y==2, 'binomial');
That is, your use of 1 and 2 is confusing it, so you need to convert those to 0 and 1.

その他の回答 (1 件)

Saurabh Gupta
Saurabh Gupta 2017 年 7 月 21 日
As the error suggests, Y should
1) either be a binary vector i.e. a vector of 0s and 1s only (other values, like 2, are not allowed),
2) or a 2-column matrix where second column is "the number of trials" as demonstrated by the example at the following link.
Hope this helps!
  1 件のコメント
Eric
Eric 2017 年 7 月 27 日
Dear Saurabh Gupta,
Thanks a lot for your reply. However, I've tried all the suggested ways to do it using the glmfit page.
For:
B2 = glmfit(x(c,:),y,'binomial');
The x(c,:) is a 200x12 matrix and my y is a 200x1 matrix. Is it correct to use it when you have to apply multiple features to the same model?
When I add the following to the code:
B2 = glmfit(x(c,:),[y, ntrials],'binomial');
With the ntrials being 200x1 matrix with 1's and y is either 0 or 1. However, this gives me some very weird results. Do you know what I have done wrong?
Best,
Eric

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by