how to fix Iteration limit reached warning

32 Ansichten (letzte 30 Tage)
mina
mina am 3 Sep. 2014
Kommentiert: mina am 16 Sep. 2014
Dear All
I am using logistic regression . I have results using glmfit but with a warning message that "iteration limit is reached". I would like to increase this limit. How to do do that when I ask "glmfit" ? beside i have to say that i tried edit glmfit, line 284, and change itration from 100 to 10000 but it dose not work.
Thank you in advance
  2 Kommentare
John D'Errico
John D'Errico am 3 Sep. 2014
Editing MATLAB toolbox codes is almost always a bad idea unless you know enough about the tool to have written it yourself.
mina
mina am 3 Sep. 2014
thank for your answer but how can i fix this problem?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Tom Lane
Tom Lane am 12 Sep. 2014
This can be a symptom of perfect separation between the classes, or of something similar to perfect separation. Consider this:
>> x = [7 0;0 0;8 0;9 0;7 1;8 0;7 0;4 0;7 0;2 0];
>> y = [0 0 1 1 1 0 0 1 0 0]';
>> fitglm(x,y,'distr','binomial');
Warning: Iteration limit reached.
>> fitglm(x(:,2),y,'distr','binomial');
Warning: Iteration limit reached.
Warning: The estimated coefficients perfectly separate failures from successes. This means the theoretical best estimates are not
finite. For the fitted linear combination XB of the predictors, the sample proportions P of Y=N in the data satisfy:
XB=-0.693147: P=0.333333
XB>-0.693147: P=1
Here's a case where the iteration limit was met because the true parameter values are drifting off to infinity. In the second case, the function diagnosed the problem and tried to explain it. In the first case, the function was unable to diagnose the problem and just gave up.
I don't know if this is the case in your example. Do you see coefficients getting large so that x*b is big? I'd be willing to try to diagnose the problem if you want to send me your data.
  2 Kommentare
mina
mina am 16 Sep. 2014
Dear Mr.Tom
thank you in advance.
the Warning that i am face to it is the second case. for example:
{Warning: The estimated coefficients perfectly separate failures from successes. This means the theoretical best estimates are not finite. For the fitted linear combination XB of the predictors, the sample proportions P of Y=N in the data satisfy: XB<-3.17805: P=0 XB=-3.17805: P=0.04 > In glmfit>diagnoseSeparation at 566 In glmfit at 363 In ravesh1 at 20 Warning: Iteration limit reached. > In glmfit at 357 In ravesh1 at 20}
and the part of my code is:
n = input('insert number of sample in each level : '); n2 = n * ones(9, 1); x=[log(0.1),log(0.2),log(0.3),log(0.4),log(0.5),log(0.6),log(0.7),log(0.8),log(0.9)]-3;
q = zeros(1, 9);
for i = 1 : 9
p = (exp(3+2*x(i)))/(1+exp(3+2*x(i)));
q(i)=p;
end
Y = zeros(10000, 9);
for j = 1 : 9
for i = 1 : 10000
y=binornd(n,q(j));
Y(i,j)=y;
end
end
B = cell(1,10000);
for j=1:10000
b = glmfit(x,[Y(j,:)' n2],'binomial','logit');
B{j}=b;
end
i will be appreciated if you could help me. thank you in advance.
mina
mina am 16 Sep. 2014
@Tom Lane

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by