Oversampling glm in R: how to define `weights` Let's say I have 10 positives out of 1000 observations. I'd like to run glm on the 10 positives and a sample of 10 non-positives (so a total of 20 records in the dataset going into the analysis).
How do I define weights in the following call?
 glm(is_positive ~ ., data = D_sampled, family = binomial, 
     weights = ???)

 A: You really don't want to do this.
The intuitive weighting lets each of the 10 non-positives represent (1000 - 10)/10 = 99 positive values in the dataset.  Here is a simulation of 500 results from 500 such samples with this weighting.  The model is generous in the sense that the underlying relationship is clear and strong, suggesting this simulation is the nearly the best performance you could hope for:

The blue curve at left is the underlying regression that generated the data plotted as 990 gray points at a height of 0 and 10 black points at a height of 1.  The nearly 500 gray curves plot the nearly 500 fits found in the simulation.  (In 16 cases, there was "perfect separation" and so I haven't plotted those obviously poor fits.)  Finally, the red curve was estimated from all 1000 observations.
At right is a plot of the pair of coefficient estimates.  As you can see, subsampling gives some wildly inaccurate estimates.  Even though the estimate based on all 1000 observations (red triangle) is not exactly correct (blue triangle), it's relatively close.
You are correct to suppose that weighting helps.  Here is the same set of simulations -- same data, same random subsamples -- using unweighted fits.

These fits are all terrible.
