Statistics & probability

Empirical density ratio model calculator for several biased samples

Fit exponential density-ratio tilts between samples and recover normalized masses on pooled observations.

Your numbers

Valid JSON.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A density-ratio model relates several sample distributions to one baseline through an exponential tilt. The baseline distribution remains flexible, while the chosen basis controls how the relative distributions can change.

THE FORMULASamplesk0…m sharebaselineF0 withdF_k/dF0=exp(alpha_k+beta_k^Tq(x)),baselinecoeff0. Knownsamplefractionsρ_k=n_k/N. MaximizeconditionalmultinomialloglikΣ_obs[logρ_label+η_label(x)-logΣ_kρ_kexpη_k(x)] over nonbaselinecoeffs usingfullrankNewton/dampedIRLS;strictconvexnegativeobjectiveexceptseparation. Recoveredbaseline supportmass atuniquex_j withmultiplicityc_j:p0_j=c_j/[NΣ_kρ_kexpη_k(x_j)];samplek massp0_jexpη_k(x_j). At optimumcheckallnormalizations,gradientanddensityratios. DistinctfromKDEratio and genericlogisticclassificationbecause empiricaldistribution recoveryrequired.

A worked example

With the prefilled inputs, tiltParameters = [[0,0]].

Good to know

Baseline distribution supported on pooled supplied tilt-coordinate rows; exponential density-ratio model with first sample baseline. Coordinates need not determine an ordered scalar CDF; no extrapolated density supplied.

Compare distributions through a ratio model

A density-ratio model relates several sample distributions to one baseline through an exponential tilt. The baseline distribution remains flexible, while the chosen basis controls how the relative distributions can change.

This is not the same as fitting a separate smooth density to every sample and dividing the curves. The shared ratio structure supplies the connection used to pool information across samples.

Density-ratio identity modelIdentical samples imply a unit density ratiosample 001sample 1011density ratiobaseline mass: 0.5, 0.5α = 0; β = 0Same support and same frequencies give no exponential tilt.
Scroll across to see the full diagram.
Two samples each containing0and1 have fitted tilt coefficients zero and ratio1, with recovered baseline masses1/2 each. Repeat or expand them to meet the public fitting minimum.

Compare with the Kernel density estimate calculator with bandwidth selection. Estimate pooled distributions linked by exponential tilting, rather than fit independent KDE curves or assume identical sampling laws.

Select a baseline and basis

Use the prefilled input structure and preserve the declared column or index order. Choose the reference sample and a small, prespecified set of basis functions such as x or x and x-squared. Each other sample receives its own intercept and basis coefficients relative to that reference.

A more flexible basis can fit stronger shape changes but needs sufficient overlap and information. Redundant columns or a basis chosen only after searching for a desired result undermine a simple interpretation of the fitted tilt. Each sample contains rows of prespecified tilt-basis coordinates. The interface supports two to four samples, one to three coordinates and at most five hundred pooled observations. It adds the tilt intercept automatically. Supplying both a constant coordinate and that implicit intercept creates rank deficiency. The first sample is the baseline, and sample fractions are taken from the observed group sizes. If the basis includes transformations such as x squared, compute those columns consistently before entry and retain their definitions with the resulting parameter vector.

Use sample fractions in the fit

The relative number of observations collected from each sample enters the conditional likelihood. It is a sampling-design quantity, not automatically the population prevalence of each distribution.

Ignoring unequal sample fractions can shift fitted intercepts. The model must distinguish the distribution being estimated from the probability that an observation appears in one labeled sample rather than another.

Recover probability mass as well as coefficients

The fitted tilt determines baseline masses on the pooled observed support. Multiplying those baseline masses by a sample's fitted density ratio gives that sample's estimated distribution masses.

Every recovered distribution should normalize to one within numerical tolerance. Reporting only classifier-like coefficients without the mass recovery would omit the empirical-distribution part of this calculation.

A balanced identical-sample check

Let both samples contain zero and one, with the basis q(x)=x. The fitted intercept and slope are zero, so the density ratio is one at both support points.

The recovered baseline places one-half at zero and one-half at one, as does the other sample. The conditional label log likelihood is minus four times log two, providing a symmetric reference case.

Recognize poor overlap and separation

If sample labels can be perfectly separated by the basis values, finite tilt coefficients may not exist. Large numerical coefficients can indicate that problem rather than a well-measured distribution ratio.

Low overlap also makes extrapolated ratios sensitive to the chosen basis. Inspect support and optimization diagnostics before interpreting a smooth-looking ratio curve outside the shared data region.

State what the estimated ratio means

A ratio above one at a value means the modeled sample distribution gives that neighborhood more relative mass than the baseline. It is not automatically a probability bounded by one.

The interpretation is conditional on the exponential-tilt family and sampling assumptions. Estimating causal importance weights or correcting a particular selection mechanism requires an additional argument connecting this ratio to that task. Mass is represented on pooled observation rows, including repeated rows; summing masses across duplicate coordinate values recovers the mass of that support point. Each sample's recovered distribution is checked for normalization after the dual optimization. The returned coordinates need not define a single ordered scalar variable, so this version reports masses rather than inventing an ordered CDF for a multivariate basis. A local score check and bounded coefficient search can reject separation or weak-overlap cases without proving a global statistical fit. The modeled ratio is not itself bounded by one, and its use as a causal or selection weight needs assumptions beyond the numerical exponential-tilt calculation. Baseline distribution supported on pooled supplied tilt-coordinate rows; exponential density-ratio model with first sample baseline. Coordinates need not determine an ordered scalar CDF; no extrapolated density supplied.

A few questions, answered

Can the density ratio exceed one?

Yes. It is a relative density or mass factor, not a probability.

Why does the baseline sample matter?

It fixes the reference distribution and sets its tilt coefficients to zero for identification.

Are sample fractions the same as population prevalences?

Not generally. They describe the collected sample counts used in the conditional fitting likelihood.

What if labels are perfectly separated by x?

A finite exponential-tilt fit may not exist; report separation rather than treating diverging coefficients as stable estimates.

Find your calculator

Start typing to explore the library.