coefficient p-values in fitglm are all NaN

hi,
I am trying to use fitglm, and keep getting NaN for all the p-values of the betas, even though the t statistics are computed.
This happens even when I run matlab's examples.
For example:
load hospital
dsa = hospital;
modelspec = 'Smoker ~ Age*Weight*Sex - Age:Weight:Sex';
mdl = fitglm(dsa,modelspec,'Distribution','binomial')
I get the same results as in the example, except all the p-values are NaN.
Any advice would be highly appreciated.

10 comentarios

Down in the bowels GLM eventually calls FCDF() to compute the p-values.
Try calling fcdf directly and see if it succeeds.
See what
which -all fcdf
returns. Maybe somehow managed to alias it altho that would seem an unlikely only symptom.
clear fcdf
and retry is worth a shot, probably.
Those failing, it would then seem to be time for TMW official support request.
IL
IL el 5 de Mzo. de 2019
Thanks for the quick response! this doesn't seem to be it - the correct fcdf is called, and using clear did not make a difference.
I should also mention that i do get the p values if I use glmfit, instead of fitglm. Also, i tried a different computer with a different matlab version, and still same thing.
I will submit a support request.
Natalia Lopez
Natalia Lopez el 5 de Sept. de 2019
Hi! Sorry to bother you. Did you receive any help? Im having exaclty the same issue and I dont know why. Thanks!
Adam Danz
Adam Danz el 6 de Sept. de 2019
@dpb, I realize this is an oldish post but when I open fcdf() (the F cumulative distribution function) and put a break point at the first line, and then run the demo code provided in the question, that file is never evoked. I haven't looked too thoroughly but it seems the fcdf function is only called under certain conditions.
r2019a.
Zhensen Chen
Zhensen Chen el 8 de Nov. de 2019
Hi,
Any update on this issue? I got the same one on R2019a.
Thanks
the cyclist
the cyclist el 8 de Nov. de 2019
In R2019b, on a Mac running Catalina, I get the results from the example, including valid p-values.
Sounds like a bug to me; I would report to support.
Yunshu Fan
Yunshu Fan el 18 de Mayo de 2021
I'm using R2019b on a windows machine. Same issue!
the cyclist
the cyclist el 18 de Mayo de 2021
Now I'm on R2020a on a Mac running Big Sur, and stll get valid p-values.
So, I think my advice would (still) be to submit a bug report. MathWorks is responsive to those, so even if this is an old bug that for some reason has not been fixed, you should at least hear back from them about the status.
dpb
dpb el 23 de Jul. de 2021
Editada: dpb el 24 de Jul. de 2021
>> load hospital
dsa = hospital;
modelspec = 'Smoker ~ Age*Weight*Sex - Age:Weight:Sex';
mdl = fitglm(dsa,modelspec,'Distribution','binomial')
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
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.9.0.1592791 (R2020b) Update 5
...
>>
Oh. This is also on Windows (old machine, still Win7 though).
Prabhjot Dhami
Prabhjot Dhami el 26 de Feb. de 2022
I'm running into the same issue (with the example data) with Matlab 2021b on Mac.
Did anyone else figure out how to solve this issue?

Iniciar sesión para comentar.

Respuestas (2)

Samaneh Nemati
Samaneh Nemati el 23 de Jul. de 2021

0 votos

@the cyclist Hi, I am using MATLAB R2019b and trying to use fitglm function, but it returns only NANs in the output "mdl". Here I attached the "Data.mat" file which includes the X and Y (predictors and resposne) and also the output of the fitglm ("mdl"). And below is the command I used. Do you know what I am doing wrong?
mdl = fitglm(X,Y,'linear','Distribution','normal');

4 comentarios

You have more predictors than observations, which means that you have so many degrees of freedom that you can fit a "perfect" model, where the fitted line (in 154 dimensions) goes exactly through every data point. You get parameter estimates, with no errors.
You can see that when I plot your data versus the model prediction. (I'm just plotting the first X variable, as an example.)
load('Data.mat')
mdl = fitglm(X,Y,'linear','Distribution','normal');
Warning: Regression design matrix is rank deficient to within machine precision.
Y_predicted = predict(mdl,X);
plot(X(:,1),Y,'b.', X(:,1),Y_predicted,'rx','MarkerSize',24)
xlabel('X(:,1)')
ylabel('Y')
legend({'data','fit'},'Location','Southeast')
xiaoyu
xiaoyu el 1 de Mzo. de 2023
thanks for you reply. but I don't think this could explain the problem.
The exact problem is why the analyses with IDENTICAL code and data running on my PC yield different results (all p values were nan).
this problem is really confusing.
and I just could not believe it that it serves as a tutorial in the matlab document for fitglm.
xiaoyu
xiaoyu el 1 de Mzo. de 2023
I tested whether this replication failure was due to the different versions of matlab.
I tested this possibility on three PCs and one MAC with different matlab versions.
1 on the first PC,
I tried on 2020b on my PC, all pvalues nan;
2022a on PC, all pvalues nan.
2on the second PC,
2020b, all pvalues were normal;
3on the third PC,
2020b, all pvalues nan;
2022a, all pvalues nan.
4on MAC
2018a on MAC, all pvalues were normal...
really confusing....
xiaoyu
xiaoyu el 1 de Mzo. de 2023
update: 2022b matlab fixed this problem out of nowhere...

Iniciar sesión para comentar.

xiaoyu
xiaoyu el 2 de Mzo. de 2023

0 votos

I have solved this problem by following the suggestions from Guru Kumaresan from MathWorks Technical Support Team:
This might happen because some function is being shadowed by another function. I would suggest you to restore your default paths by following the steps given below:
1)You can take a backup of your search path by executing the following command to give you the location of the search path.
>> which -all pathdef
Before proceeding, you should backup this file by copying it to a folder outside of your MATLAB path. This step is optional and only matters you if you have customized 'pathdef.m' by adding custom paths.
2) After making the backup, please execute the following commands in the MATLAB Command Window to restore the default MATLAB search path and rehash the toolbox cache:
>> restoredefaultpath
>> rehash toolboxcache
3) After this step, please use MATLAB again to see if the issue persists. If the issue is resolved, then you can save the new MATLAB search path by executing the following command:
>> savepath

1 comentario

Philipp
Philipp el 27 de Sept. de 2024
I was running into similar problems on Matlab 2024a using MacOs Monterey. Problems could be resolved simply by restoredefaultpath. P-values were reported without any trouble. Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Etiquetas

Preguntada:

IL
el 5 de Mzo. de 2019

Comentada:

el 27 de Sept. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by