# Model Selection: Logistic Regression

Suppose we have $n$ covariates $x_1, \dots, x_n$ and a binary outcome variable $y$. Some of these covariates are categorical with multiple levels. Others are continuous. How would you choose the "best" model? In other words, how do you choose which covariates to include in the model?

Would you model $y$ with each of the covariates individually using simple logistic regression and choose the ones with a significant association?

-

1
– gung Nov 19 '11 at 20:36

2
I'll quote @jthetzel from a recent comment on this site: "A good question, but one that most here studied in semester-long university courses, and some have spent careers studying." It's kind of like sitting down with a person and saying, "Can you teach me Swahili this afternoon?" Not that Gung doesn't make good points in his answer. It's just a vast territory. – rolando2 Nov 19 '11 at 20:44

1
– EpiGrad Nov 19 '11 at 23:30
Okay so I think I will just use AIC as a criterion. The full model has the lowest AIC. Also the AIC's are pretty different from each other. – Thomas Nov 21 '11 at 18:55

## 3 Answers

This is probably not a good thing to do. Looking at all the individual covariates first, and then building a model with those that are significant is logically equivalent to an automatic search procedure. While this approach is intuitive, inferences made from this procedure are not valid (e.g., the true p-values are different from those reported by software). The problem is magnified the larger the size of the initial set of covariates is. If you do this anyway (and, unfortunately, many people do), you cannot take the resulting model seriously. Instead, you must run an entirely new study, gathering an independent sample and fitting the previous model, to test it. However, this requires a lot of resources, and moreover, since the process is flawed and the previous model is likely a poor one, there is a strong chance it will not hold up--meaning that it is likely to waste a lot of resources.

A better way is to evaluate models of substantive interest to you. Then use an information criterion that penalizes model flexibility (such as the AIC) to adjudicate amongst those models. For logistic regression, the AIC is:

$AIC = -2*ln(likelihood) + 2*k$

where $k$ is the number of covariates included in that model. You want the model with the smallest value for the AIC, all things being equal. However, it is not always so simple; be wary when several models have similar values for the AIC, even though one may be lowest.

I include the complete formula for the AIC here, because different software outputs different information. You may have to calculate it from just the likelihood, or you may get the final AIC, or anything in between.

-

4
I like AIC but beware that computing AIC on more than 2 pre-specified models results in a multiplicity problem. – Frank Harrell Nov 20 '11 at 14:31
@FrankHarrell nice tip! – gung Nov 20 '11 at 17:29
@gung: it's good to have you on this site, you are adding a lot. – rolando2 Nov 22 '11 at 2:02
@rolando2 thanks! I seem to have caught the bug, although I may not be able to contribute this much forever. I'm learning a lot from the real experts like Frank Harrell and whuber as well. – gung Nov 22 '11 at 6:44

There are many ways to choose what variables go in a regression model, some decent, some bad, and some terrible. One may simply browse the publications of Sander Greenland, many of which concern variable selection.

Generally speaking however, I have a few common "rules":

• Automated algorithms, like those that come in software packages, are probably a bad idea.
• Using model diagnostic techniques, like gung suggests, are a good means of evaluating your variable selection choices
• You should also be using a combination of subject-matter expertise, literature searchers, directed acyclic graphs, etc. to inform your variable selection choices.
-

2
Well put, especially points 1 and 3. Model diagnostic techniques can result in a failure to preserve type I error. – Frank Harrell Nov 20 '11 at 14:32

1
Well put @Epigrad. I would add one point though. Automated algorithms become very attractive when your problem becomes large. They may be the only feasible way of doing model selection in some cases. People are now analysing huge data sets with 1000s of potential variables and millions of observations. How is the subject matter's expertise at 1000-dimensional intuition? And what you will find is that even if you do it manually (i.e. with an analyst), they will likely end up creating some short-cut rules for choosing variables. The hard part is really coding up those choices. – probabilityislogic Nov 26 '11 at 11:22
@probabilityislogic I would agree with that. Honestly, I think traditional techniques are poorly suited for very large data sets, but the tendency to fall back to more amenable techniques alarms me. If an automated algorithm can bias a data set with 10 variables, there's no reason it can't bias one with 10,000. The current emphasis on the acquisition of big data over its analysis in some parts makes me somewhat skittish. – EpiGrad Nov 27 '11 at 1:22

How would you choose the "best" model?

There isn't enough information provided to answer this question; if you want to get at causal effects on y you'll need to implement regressions that reflect what's known about the confounding. If you want to do prediction, AIC would be a reasonable approach.

These approaches are not the same; the context will determine which of the (many) ways of choosing variables will be more/less appropriate.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 6, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9481223225593567, "perplexity_flag": "middle"}