Skip to content

Instantly share code, notes, and snippets.

View thomvolker's full-sized avatar

Thom Volker thomvolker

View GitHub Profile
@thomvolker
thomvolker / densityratioweighting.md
Last active May 20, 2025 15:50
Density ratio estimation for weighted analyses

How density ratio estimation can be used to reweigh a sample

Density ratio estimation can be used to construct weights for analyses, that is, if the sample of interest does not correspond to the target population in some way, one can reweight the sample of interest such that it is closer to the target population. One way to do that is by estimating the density ratio $$r(x) = \frac{p_{\text{nu}}(x)}{p_{\text{de}}(x)}$$ between the two samples, and reweight the analyses of the target sample $x_{\text{de}}$ with the estimated weights $\hat{r}(x)$. If the analyses of interest is least-squares regression, the solution to the inference problem is given by the optimization problem $$(\mathbf{X^\top W X)\hat{\beta}} = \mathbf{X^\top W y},$$