0

I want to build a saturated model in R for my logistic regression. I already tried the following code obtained from another question posted here (Logistic Regression : How to obtain a saturated model):

y = c(1,1,1,0,0,0)
a <- factor(1:length(y)) 
fit <- glm(y~a,family=binomial) 
summary(fit)

But there is an error probably caused by the length of the y variable; it is too long to process in the above code and causes R to crash with the following error displayed "Error: cannot allocate vector of size 3.4 Gb".

Is there is any other way to build a saturated logistic regression model?

I want to build the saturated model to compare it latter with my model using a Wald Chi-square test as a goodness of fit test. I already have the Wald Chi-square test for the null versus my model.

Thank you

  • 1
    Why not use the deviance goodness of fit test? The deviance for a saturated model is 0 so you don't even have to fit it. – Demetri Pananos Jul 27 '21 at 16:16
  • @DemetriPananos Thank your for your reply. My research boss wants me to report the Wald Chi-square. – Zeinab Elashidy Jul 28 '21 at 09:50
  • Are you saying that your predictor is a factor variable with a huge number of levels? Then the issue is that dummy encoding results in a truly huge design matrix. – Roland Jul 28 '21 at 10:57
  • @Roland The y variable is a 0 or 1 dummy. But the code says a – Zeinab Elashidy Jul 28 '21 at 15:14
  • OK. R needs to add a column of 0/1 values to the design matrix for each observation. The size of the resulting design matrix is n x n. I bet you don't have sufficient memory to create such a large matrix in R. But even if you do have sufficient memory, I'd expect you don't have enough memory for any computations with that matrix. – Roland Jul 28 '21 at 16:10
  • @Roland Yes, that's the problem. Thank you. – Zeinab Elashidy Aug 02 '21 at 09:28

0 Answers0