MATLAB Answers

coefficient p-values in fitglm are all NaN

23 views (last 30 days)
IL on 5 Mar 2019
Edited: dpb on 24 Jul 2021
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.
dpb on 23 Jul 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: (R2020b) Update 5
Oh. This is also on Windows (old machine, still Win7 though).

Sign in to comment.

Answers (1)

Samaneh Nemati
Samaneh Nemati on 23 Jul 2021
@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');
  1 Comment
the cyclist
the cyclist on 23 Jul 2021
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.)
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)

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!