Error in generalized linear mixed-effects model with poisson distribution.
17 views (last 30 days)
Show older comments
Dear All
I have daily measurements for four days (day 0 to 3) from patients. I would like to fit a glme with a poisson distribution with the formula "Measurement ~ Day*Group + (1|Patient)".
The code I use is:
mdl = fitglme(tbl,"Measurement ~ Day*Group + (1|Patient)",'Distribution','Poisson')
I receive the following error message:
Error using classreg.regr.lmeutils.StandardGeneralizedLinearMixedModel/validateyRange
For Poisson distribution, the responses must be non-negative, 'Weights' must be positive integers and the product of responses and 'Weights' must be integers.
Error in classreg.regr.lmeutils.StandardGeneralizedLinearMixedModel (line 4193)
validateyRange(sglme,sglme.y,binomialsize,weights,distribution);
Error in GeneralizedLinearMixedModel/fitStandardLMEModel (line 1319)
slme = classreg.regr.lmeutils.StandardGeneralizedLinearMixedModel(X,model.y,Zs,Psi,model.FitMethod,dofit,dostats,args{:});
Error in GeneralizedLinearMixedModel/fitter (line 893)
model.slme = fitStandardLMEModel(model);
Error in classreg.regr.FitObject/doFit (line 94)
model = fitter(model);
Error in GeneralizedLinearMixedModel.fit (line 2419)
model = doFit(model);
Error in fitglme (line 398)
glme = GeneralizedLinearMixedModel.fit(T,formula,varargin{:});
If I fit the same data without the mixed-effects (fitglm) using the formula "Measurement ~ Day*Group", I do not encounter any problems:
mdl = fitglm(tbl,"Measurement ~ Day*Group",'Distribution','Poisson')
I don't understand the reason for this error message and how to fix, so any help would be highly appreciated.
Thank you very much
Kind regards
Kaspar
4 Comments
the cyclist
on 28 Oct 2023
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
Answers (1)
Jeff Miller
on 29 Oct 2023
I haven't used Poisson models myself, but I thought they required the values of the dependent variable to be non-negative integers. Your data values are reals. Note that your script runs find if you add (for example) the two extra lines below to make the data values integers:
% Add daily trend
DataA = DailyReductionA(i).*A;
DataB = DailyReductionB(i).*B;
% Added these two lines to make sure the data are integers:
DataA = round(10*DataA);
DataB = round(10*DataB);
% Store data
Data = [Data;DataA;DataB];
According to the data model underlying this type of analysis, I think that the factors, intercepts, and trends, etc influence the lamba parameter values of the different conditions--not the data values as you have them being created in your script. Thus, the final random values generated in the various conditions (with their different lambdas) would all be integers.
This doesn't explain why fitglm works even with non-integer data values; maybe it just doesn't check as thoroughly as fitglme. And fitglme's error message could be improved by adding "integers" after "must be non-negative".
Maybe you shouldn't be using a Poisson-based model if your measured data values are not integers?
2 Comments
Jeff Miller
on 30 Oct 2023
Sorry, if the integer issue isn't the problem, then I don't have any other idea. (I still think it is pretty diagnostic that fitglme runs find if the data values are converted integers, though. It looks to me like fitglm supports some more generalized theory that allows non-integer values of the "Poisson" DV, but fitglme doesn't.)
I don't know of any general approach that works for non-normal distributions. It depends on what the DV is and why/how it is non-normal. For example, various different transformations (log, sqrt, inverse, etc) can be used to make DVs more normal. Typically the people working with a given DV have adopted some specific approach that seems to work well for that DV.
Sorry I couldn't be more help.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!