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.
Samplesk0…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.
Reference: Primary method reference or author-maintained documentation (opens in a new tab) ↗
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.
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.