Survival analysis and the stratified sample
By: Edward Wagner
Tags: Logistic Regression, Survival Analysis, R, Data Science

Part II: Case-control sampling and regression strategy

Due to resource constraints, it is unrealistic to perform logistic regression on data sets with millions of observations, and dozens (or even hundreds) of explanatory variables. Luckily, there are proven methods of data compression that allow for accurate, unbiased model generation.

Traditional logistic case-control

Case-control sampling is a method that builds a model based on random subsamples of “cases” (such as responses) and “controls” (such as non-responses). Regardless of subsample size, the effect of explanatory variables remains constant between the cases and controls, so long as the subsample is taken in a truly random fashion. For example, if women are twice as likely to respond as men, this relationship would be borne out just as accurately in the case-control data set as in the full population-level data set. Thus, we can get an accurate sense of what types of people are likely to respond, and what types of people will not respond.

After the logistic model has been built on the compressed case-control data set, only the model’s intercept needs to be adjusted. While relative probabilities do not change (for example male/female differences), absolute probabilities do change. For example, take​​​ a population with 5 million subjects, and 5,000 responses. If the case-control data set contains all 5,000 responses, plus 5,000 non-responses (for a total of 10,000 observations), the model would predict that response probability is 1/2, when in reality it is 1/1000. When all responses are used in the case-control set, the offset added to the logistic model’s intercept is shown below:

Here, N_0 is equal to the number of non-events in the population, while n_0 is equal to the non-events in the case-control set.

As a reminder, in survival analysis we are dealing with a data set whose unit of analysis is not the individual, but the individual*week. The following very simple data set demonstrates the proper way to think about sampling:

This technique incorrectly picks a few individuals and follows them over time.

This technique captures much more variability by randomly selecting individual observations from the data set.

Survival analysis case-control and the stratified sample

Things become more complicated when dealing with survival analysis data sets, specifically because of the hazard rate. For example, if an individual is twice as likely to respond in week 2 as they are in week 4, this information needs to be preserved in the case-control set. And the best way to preserve it is through a stratified sample.

With stratified sampling, we hand-pick the number of cases and controls for each week, so that the relative response probabilities from week to week are fixed between the population-level data set and the case-control set. This way, we don’t accidentally skew the hazard function when we build a logistic model.

This can easily be done by taking a set number of non-responses from each week (for example 1,000).

This method requires that a variable offset be used, instead of the fixed offset seen in the simple random sample. The offset value changes by week and is shown below:

Again, the formula is the same as in the simple random sample, except that instead of looking at response and non-response counts across the whole data set, we look at the counts on a weekly level, and generate different offsets for each week j.

Because the offset is different for each week, this technique guarantees that data from week j are calibrated to the hazard rate for week j.

Code for logistic regression

The following R code reflects what was used to generate the data (the only difference was the sampling method used to generate sampled_data_frame ):

glm_object = glm(response ~ age + income + factor(week),

data = sampled_data_frame,

family = "binomial")