MATLAB Answers

Increasing the number of iterations in Generalize​dLinearMod​

2 views (last 30 days)
Leonardo Tozzi
Leonardo Tozzi on 7 May 2021
Commented: Leonardo Tozzi on 13 May 2021
Dear Experts,
I am fitting a matrix of predictors (desmat) to a timeseries (ts) and to do it I use a GeneralizedLinearModel object as follows:
m =, ts);
However, I often get the following warning:
Warning: Iteration limit reached.
> In glmfit (line 332)
In GeneralizedLinearModel/postFit (line 605)
In classreg.regr.FitObject/doFit (line 95)
In (line 887)
I have to use instead of glmfit because I am also running some contrasts between the model parameters down the line.
My question is this: how can I increase the number of maximum iterations in this fit method, so I can try to make my model converge? Alternatively, is there a way to do a contrast of coefficients that returns p-values using the glmfit function?
Thank you very much,
Leonardo Tozzi

Answers (1)

Aditya Patil
Aditya Patil on 13 May 2021
As per my understanding, you want to get the p values from the fitted model. You can use fitglm for this purpose. You can increase the iterations using the MaxIter option.
load hospital
dsa = hospital;
modelspec = 'Smoker ~ Age*Weight*Sex - Age:Weight:Sex';
mdl = fitglm(dsa,modelspec,'Distribution','binomial','Options',statset('MaxIter',1000))
mdl =
Generalized linear regression model: logit(Smoker) ~ 1 + Sex*Age + Sex*Weight + Age*Weight Distribution = Binomial Estimated Coefficients: Estimate SE tStat pValue ___________ _________ ________ _______ (Intercept) -6.0492 19.749 -0.3063 0.75938 Sex_Male -2.2859 12.424 -0.18399 0.85402 Age 0.11691 0.50977 0.22934 0.81861 Weight 0.031109 0.15208 0.20455 0.83792 Sex_Male:Age 0.020734 0.20681 0.10025 0.92014 Sex_Male:Weight 0.01216 0.053168 0.22871 0.8191 Age:Weight -0.00071959 0.0038964 -0.18468 0.85348 100 observations, 93 error degrees of freedom Dispersion: 1 Chi^2-statistic vs. constant model: 5.07, p-value = 0.535
  1 Comment
Leonardo Tozzi
Leonardo Tozzi on 13 May 2021
Unfortunately, the p-values I would like to get are for the difference of two effects estimates, not of the effects themselves. Sorry if this was not clear. My code to achieve this at the moment is as follows:
m =, ts);
con=zeros(1, height(m.Coefficients));

Sign in to comment.





Community Treasure Hunt

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

Start Hunting!

Translated by