# How many predictors can I include in my logistic regression model

If I am dealing with a small sample size (n = 48; n = 29 have disease vs n = 19 without disease), what are the maximum numbers of the predictors I can include in my multivariable logistic regression model (I am building a predictive model)?

There are so many rules online and I am not sure which one I should use.

Any help is much appreciated!

• Nov 24 at 19:38
• If you are building a predictive model then you can probably include as many variables as you think are relevant and use regularisation (L1 or L2 or both) to avoid over-fitting (don't do feature selection, it is more likely to make things worse rather than better if you have regularization) Nov 24 at 19:42
• @DikranMarsupial Can you pls share the R code for L2 or L2 method? Any sample example would be much appreciated Nov 24 at 20:36
• @RBeginner unfortunately I don't use R, but any good implementation of logistic regression ought to provide L2 regularisation (c.f. ridge regression). There are undoubtedly packages for L1 regularisation (look for "LASSO") and both L1 and L2 regularisation (look for "elastic net"). Nov 25 at 7:38
• @DikranMarsupial No worries! So, in your opinion, we don't have to worry about the p-value for inclusion into my predictive model (e.g. only included predictors in my final model with p<0.05)? Nov 25 at 18:29

A useful rule of thumb for logistic regression is to limit yourself to about 1 unpenalized predictor per 15 cases of the minority class. See Section 4.4 of Frank Harrell's course notes, for example. That's when you have a

typical problem in medicine, epidemiology, and the social sciences in which the signal:noise ratio is small.

I highlighted the word "unpenalized" above because you don't have to throw out all except 1 or 2 of your predictors. A penalized method ("regularization" mentioned in one of the comments) allows you to use more predictors than that rule of thumb.

The regression coefficients of the predictors are penalized to lower magnitudes than they would be in a standard regression, to help avoid overfitting. The penalty that provides best performance is typically chosen by cross-validation. Ridge regression ("L2 regularization") provides coefficients for all predictors. LASSO ("L1 regularization") provides penalized coefficients for some predictors and sets coefficients of others to 0. My guess is that you would be better served by ridge regression here, perhaps after you apply your knowledge of the subject matter to reduce the effective number of predictors. See Harrell's notes for ideas on how to implement data reduction, to cut down on the numbers of predictors without using the outcomes.

For logistic regression, penalization is implemented in the glmnet package.

• Thank you for the great contribution. So, if I decide to use an unpenalized approach, I can roughly fit 2 only predictors in my data (cases mean participants with a disease, correct)? Nov 24 at 20:34
• @RBeginner that's correct. The limiting number is the size of the minority class regardless of how you name the classes, so in your case it's limited by the 19 without disease. Thus even 2 predictors would be pushing it and could overfit. I recommend that you try ridge regression with glmnet(), illustrated in Section 6.6.1 of ISLR for ordinary least squares but directly applicable to your logistic regression with a family="binomial" argument.
– EdM
Nov 24 at 21:49
• Does the minority class mean the group with the smaller sample size? Nov 25 at 1:24
• Can you pls share a R code with the glmnet( )? Is it similar to the logistic regression one (e.g. glm)? Nov 25 at 1:25
• @RBeginner the minority group is the one with the smaller sample size. ISLR in my prior comment is freely available and the cited section 6.6.1 shows how to do ridge regression with glmnet(), including use of cv.glmnet() to find the optimum penalty. You specify the argument alpha = 0 to do ridge regression. If you also use a family="binomial" argument it will do logistic ridge regression. Unlike other R functions, you have to provide separate outcome and predictor vectors/matrices, however.
– EdM
Nov 25 at 2:48