2
$\begingroup$

I've tried to build a predictive logistic regression model. However, there are only 500 observations with disease (+) and over 60,000 observations with disease (-).

Can I take a random sample (e.g., 10,000) of 60,000 observations with disease (-) to build the predictive model?

$\endgroup$
6
  • 2
    $\begingroup$ The proposed method is called "under-sampling." Here are some related questions & answers on this topic stats.stackexchange.com/… $\endgroup$
    – Sycorax
    Commented May 17, 2022 at 14:54
  • 3
    $\begingroup$ Why do you want to do that? In general, this can be a bad idea. Imagine that there's no predictive information in any "predictors" you have. In that case, the best risk prediction for all members in the population (assuming your sample is representative) is 500/60500. If you subsampled, you'd get e.g. 500/10500. Of course, there are methods that can correct estimates for the sub-sampling that would account for this. $\endgroup$
    – Björn
    Commented May 17, 2022 at 14:55
  • 2
    $\begingroup$ Never discard data that someone has already spent the money to collect. The except is when debugging your code you might take weighted samples, temporarily. $\endgroup$ Commented May 17, 2022 at 15:04
  • $\begingroup$ random sample is OK as long as it is representative of the population. So if you happen to get 'unlucky' with your 10,000 and not get any of the adverse observations in your sample, that obviously won't work. How did you come up with the 10,000 sampling number? $\endgroup$ Commented May 17, 2022 at 15:19
  • $\begingroup$ Closely-related in the context of logistic regression is the case-control design. stats.stackexchange.com/… $\endgroup$
    – Sycorax
    Commented May 17, 2022 at 16:56

1 Answer 1

0
$\begingroup$

Can I take a random sample (e.g., 10,000) of 60,000 observations with disease (-) to build the predictive model?

Let's try it out. The code below simulates data and fits two times the data one time without and one time with the reduction in data.

We see that the result is nearly the same. The reason that the reduction does not matter so much is because the estimate of the control group is very accurate already.

In the code we have computed the logistic model in two different ways.

  • Using a glm model, which is the typical and straightforward approach
  • Estimating the distribution of the two groups. This is not the typical approach (it requires a normal distribution of the two groups, control and cases), but it is comparable. (you can see the black line and the thick dotted red line coincide)

So what happens when you reduce the data is that your estimate of the control group becomes less accurate. However, the limiting factor is the estimate of the group with the cases. The cases group is smaller and the estimates are less accurate which dominate the overal estimation. So reducing the control group has little influence.

Of course, when you have all the data already, then there is no reason to reduce the groups. But when you still have to gather the data then it can make sense to safe resources by not measuring the entire control group.

Note, you do need to keep in mind the frequency of cases in the population of interest and not use the frequency of cases in the sample with a relatively higher frequency of cases. In the code below this is done by correcting the odds from the fit with the sample according to the frequency of the population. This is done in the line odds2 = odds*(reduce*nx+ny)/(nx+ny).

example

layout(matrix(1:2,2))

### generate two groups of data
set.seed(1)
nx = 6*10^4
ny = 500
y = rnorm(ny,2,1)
x = rnorm(nx,0,1)
z = c(x,y)
cat = c(rep(0,nx), rep(1,ny))

### plot
plot(z,cat)

### compute logistic model by approximating normal distributions
mu_x = mean(x)
mu_y = mean(y)
sig = ( (sum((y-mu_y)^2) + sum((x-mu_x)^2)) /(ny+nx-2))^0.5 

zs = seq(-4,6,0.1)
p_caty = (dnorm(zs,mu_y,sig)*ny)/(dnorm(zs,mu_x,sig)*nx+dnorm(zs,mu_y,sig)*ny)
lines(zs,p_caty, lty = 1)

### compute logistic model with glm
mod = glm(cat ~ z, family = binomial)
lines(zs, predict(mod, newdata = list(z=zs), type = "response"), col = 2, lty = 2, lwd = 2)

title("estimate with all data 60000 vs 500 cases", cex.main = 1)

### generate two groups of data
set.seed(1)
nx = 6*10^4
reduce = 1/6
ny = 500
y = rnorm(ny,2,1)
x = rnorm(nx*reduce,0,1)
z = c(x,y)
cat = c(rep(0,nx*reduce), rep(1,ny))

### plot
plot(z,cat)

### compute logistic model by approximating normal distributions
mu_x = mean(x)
mu_y = mean(y)
sig = ( (sum((y-mu_y)^2) + sum((x-mu_x)^2)) /(ny+nx*reduce-2))^0.5 

zs = seq(-4,6,0.1)
p_caty = (dnorm(zs,mu_y,sig)*ny)/(dnorm(zs,mu_x,sig)*nx+dnorm(zs,mu_y,sig)*ny)
lines(zs,p_caty, lty = 1)

### compute logistic model with glm
mod = glm(cat ~ z, family = binomial)
out = predict(mod, newdata = list(z=zs), type = "response")
odds = out/(1-out)
odds2 = odds*reduce
out2 = odds2/(odds2+1)
lines(zs, out2, col = 2, lty = 2, lwd = 2)

title("estimate with reduced data 10000 vs 500 cases", cex.main = 1)
$\endgroup$
20
  • 1
    $\begingroup$ When the proportion of positives and negatives is fixed by the design, the intercept is likewise fixed. stats.stackexchange.com/questions/69561/… Appeals to sample size are misdirected. The intercept depends on the class ratio, and the ratio is fixed by the researcher in both of your demonstrations, instead of arising from SRS of the population. $\endgroup$
    – Sycorax
    Commented May 17, 2022 at 17:55
  • 3
    $\begingroup$ The intercept has been screwed up royally. $\endgroup$ Commented May 17, 2022 at 19:01
  • 3
    $\begingroup$ If simple random sampling is not used it will be messed up. It depends on the mean of the predictors and on the Y=0,1 relative frequencies. $\endgroup$ Commented May 17, 2022 at 20:24
  • 1
    $\begingroup$ @FrankHarrell in the example I have corrected for this by scaling the odds with the same factor as used to reduce the sample size. The curves in the two images are nearly the same and there is no screwed up intercept. The estimation basically comes down to estimating the mean of the two groups and the variance. $\endgroup$ Commented May 17, 2022 at 21:01
  • 2
    $\begingroup$ I think the correction you did is approximately correct. The full correction needs an offset term on the logit scale. $\endgroup$ Commented May 17, 2022 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.