Tutorials › Marginal Structural Models › Gamma and Beta Models for Positive or Bounded Doses

Inverse Probability of Treatment Weights · Tutorial 102 of 501

Gamma and Beta Models for Positive or Bounded Doses

Learn to fit gamma and beta conditional treatment-density models and calculate the fitted density assigned to each observed dose.

Advanced 12 min read

What You'll Learn

  • Parameterize gamma conditional densities by their conditional mean and shape.
  • Parameterize beta conditional densities by their conditional mean and precision.
  • Derive the regression score equations for both models.
  • Fit a simple gamma model and evaluate its fitted density at observed doses.
  • Recognize support, boundary, and density-scale problems that can invalidate a model.

Why Match the Density Model to the Dose?

For a continuous treatment, a model must describe a density, not the probability of observing one exact dose. The fitted conditional density at a person's observed dose is the denominator contribution used in a continuous-treatment weight. Its value depends on the dose and covariate history, so a model that gives the wrong shape or support can assign implausible density to observed treatment values.

The Gaussian conditional density model is useful when its support and shape are reasonable. Here we consider two alternatives: the gamma distribution for strictly positive, unbounded doses, and the beta distribution for doses strictly between zero and one. The target is the fitted conditional density \( \hat f(A_{it}\mid H_{it}) \), evaluated at the observed dose \(A_{it}\) and history \(H_{it}\).

Definition: A gamma conditional-density model specifies the distribution of a positive dose \(A_{it}>0\) given history \(H_{it}\), using a conditional mean \( \mu_{it}>0 \) and shape \(k>0\). A beta conditional-density model specifies the distribution of a dose \(0<A_{it}<1\) given \(H_{it}\), using a conditional mean \(0<\mu_{it}<1\) and precision \( \phi>0 \). The fitted density is the model density with its parameters replaced by estimates, evaluated at the observed dose and history.

Gamma Regression for Positive Doses

Use the shape-and-mean parameterization \(A_{it}\mid H_{it}\sim \operatorname{Gamma}(k,\mu_{it}/k)\), where the second argument shown here is the scale. The density, conditional mean, and variance are

$$ f(a\mid H_{it})= \frac{k^k}{\Gamma(k)\mu_{it}^k}a^{k-1} \exp\!\left(-\frac{ka}{\mu_{it}}\right),\quad a>0; \qquad E[A_{it}\mid H_{it}]=\mu_{it},\quad \operatorname{Var}(A_{it}\mid H_{it})=\frac{\mu_{it}^2}{k}. $$

A common regression specification is \( \log(\mu_{it})=X_{it}^{\mathsf T}\beta \), with \(X_{it}\) a vector of functions of the history and \(\beta\) a coefficient vector. The logarithm ensures a positive fitted mean for every finite linear predictor. A constant shape \(k\) gives a variance proportional to the squared mean; it does not imply constant variance.

Suppose the conditional observations are modeled by this density and the design is treated as fixed. The log likelihood, omitting no parameter-dependent terms, is

$$ \ell(\beta,k)=\sum_{i,t}\left[ k\log k-\log\Gamma(k)-k\log\mu_{it} +(k-1)\log A_{it}-\frac{kA_{it}}{\mu_{it}} \right]. $$

For fixed \(k\), differentiate with respect to the linear predictor \( \eta_{it}=\log\mu_{it} \). Since \(d\mu_{it}/d\eta_{it}=\mu_{it}\), the derivative of the two terms involving \(\mu_{it}\) is \(-k+kA_{it}/\mu_{it}\). The score for \(\beta\) is therefore

$$ \frac{\partial\ell}{\partial\beta} =k\sum_{i,t}X_{it}\left(\frac{A_{it}}{\mu_{it}}-1\right). $$
Result: For a gamma model with log-linked mean and fixed shape, any interior maximum-likelihood estimate of \(\beta\) satisfies \( \sum_{i,t}X_{it}(A_{it}/\mu_{it}-1)=0 \). This follows by differentiating the stated log likelihood and setting its score to zero; it is a necessary equation, not a guarantee that a finite maximum exists or is unique.

If \(k\) is estimated too, maximize the likelihood over both mean-regression and shape parameters. In general, there is no simple closed-form joint fit. Numerical optimization must respect \(k>0\); common implementations use a log parameterization for \(k\). The score equation above is conditional on fixed \(k\), and should not be mistaken for the complete set of equations when shape is estimated.

Worked Example: A Gamma Density at an Observed Dose

Suppose a fitted gamma model has \( \log(\hat\mu_{it})=\log(2)+(\log 2)X_{it} \) and \( \hat k=2 \). For a history with \(X_{it}=1\), the fitted mean is \( \hat\mu_{it}=\exp(\log 2+\log 2)=4 \). Evaluate the fitted density at the observed dose \(A_{it}=3\).

Substitute \(k=2\), \(\mu=4\), and \(a=3\) in the gamma density. Because \(\Gamma(2)=1\), the coefficient is \(2^2/(1\cdot4^2)=1/4\). Thus \( \hat f(3\mid H_{it})=(1/4)(3)^{1}\exp(-2\cdot3/4)=(3/4)e^{-1.5}\approx0.16735 \).

This is a density value per unit of dose, not the probability that the dose equals exactly 3. Probabilities require integrating the density over an interval.

Beta Regression for Doses Between Zero and One

For a dose whose support is exactly the open interval \((0,1)\), parameterize a beta distribution by its mean \( \mu_{it} \) and precision \( \phi \). Its shape parameters are \( \alpha_{it}=\mu_{it}\phi \) and \( \beta_{it}=(1-\mu_{it})\phi \). The density and moments are

$$ f(a\mid H_{it})= \frac{a^{\alpha_{it}-1}(1-a)^{\beta_{it}-1}} {B(\alpha_{it},\beta_{it})},\quad 0<a<1; \qquad E[A_{it}\mid H_{it}]=\mu_{it},\quad \operatorname{Var}(A_{it}\mid H_{it})= \frac{\mu_{it}(1-\mu_{it})}{\phi+1}. $$

A standard regression uses \( \operatorname{logit}(\mu_{it})=X_{it}^{\mathsf T}\gamma \), where \( \operatorname{logit}(u)=\log\{u/(1-u)\} \). This maps every finite linear predictor to a mean strictly between zero and one. A simple model uses constant precision \(\phi\); other specifications can model precision as well, but the score below assumes it is constant.

For observations strictly inside the support, the log likelihood is

$$ \ell(\gamma,\phi)=\sum_{i,t}\left[ (\alpha_{it}-1)\log A_{it} +(\beta_{it}-1)\log(1-A_{it}) -\log B(\alpha_{it},\beta_{it}) \right]. $$

To derive the mean-regression score, write \( \eta_{it}=X_{it}^{\mathsf T}\gamma \). Then \(d\mu_{it}/d\eta_{it}=\mu_{it}(1-\mu_{it})\), \(d\alpha_{it}/d\eta_{it}=\phi\mu_{it}(1-\mu_{it})\), and \(d\beta_{it}/d\eta_{it}=-\phi\mu_{it}(1-\mu_{it})\). Let \( \psi(u)=d\log\Gamma(u)/du \), the digamma function. Since \( \log B(\alpha,\beta)=\log\Gamma(\alpha)+\log\Gamma(\beta)-\log\Gamma(\alpha+\beta) \), differentiating and using \(d\alpha+d\beta=0\) cancels the terms involving \( \psi(\alpha+\beta) \). Consequently,

$$ \frac{\partial\ell}{\partial\gamma} =\sum_{i,t}X_{it}\phi\mu_{it}(1-\mu_{it}) \left[ \log\!\left(\frac{A_{it}}{1-A_{it}}\right) -\psi(\alpha_{it})+\psi(\beta_{it}) \right]. $$
Result: For a beta model with logit-linked mean and constant precision, an interior maximum-likelihood estimate of \(\gamma\) makes the displayed score zero. This equation is obtained by the chain rule from the beta log likelihood. It does not ensure that the likelihood has a finite or unique maximizer; estimation of \(\phi\) adds its own score equation.

In either model, fitting means maximizing the conditional likelihood under the chosen specification and checking that the optimization converged to an admissible solution. With repeated observations per person, a product of conditional densities can be used for point estimation under the stated treatment model; dependence across a person's observations still matters for uncertainty calculations.

Worked Example: A Beta Density at an Observed Dose

Suppose the fitted beta regression gives \( \hat\mu_{it}=0.4 \) for a particular history and \( \hat\phi=10 \). The fitted shape parameters are \( \hat\alpha_{it}=0.4(10)=4 \) and \( \hat\beta_{it}=0.6(10)=6 \). Evaluate the density at \(A_{it}=0.5\).

The beta normalizing constant is \(B(4,6)=\Gamma(4)\Gamma(6)/\Gamma(10)=6(120)/362880=1/504\). Therefore \( \hat f(0.5\mid H_{it})=504(0.5)^3(0.5)^5=504/256=1.96875 \).

A density greater than one is valid: density is not probability. For example, the probability of an interval is its integrated density and cannot exceed one.

Worked Example: Fitting an Intercept-Only Gamma Mean

Consider three positive observed doses \(2,4,6\), modeled independently with a common gamma mean \(\mu\) and fixed shape \(k=2\). The intercept-only model has \(X_{it}=1\) and \( \mu=\exp(\beta) \). Use the gamma score to estimate the mean, then evaluate the density at dose 2.

The score equation is \( \sum_j(A_j/\mu-1)=0 \), since \(k\) is nonzero. Thus \( (2+4+6)/\mu-3=0 \), giving \( \hat\mu=12/3=4 \) and \( \hat\beta=\log 4 \). The log likelihood as a function of \(\mu\), after dropping terms not involving \(\mu\), is \( -3k\log\mu-k(12)/\mu \). Its derivative is \( -3k/\mu+12k/\mu^2 \), which is zero at \(\mu=4\); its second derivative there is \( -3k/16<0 \), confirming a local maximum. Also, the derivative is positive for \(0<\mu<4\) and negative for \(\mu>4\), so this is the unique maximum over \(\mu>0\).

At the observed dose \(a=2\), \( \hat f(2)=\{2^2/\Gamma(2)4^2\}(2)^{1}\exp(-2\cdot2/4)=(1/4)(2)e^{-1}=0.5e^{-1}\approx0.18394 \).

Checking Support, Fit, and Interpretation

A well-defined maximum-likelihood fit does not establish that the conditional density is adequate. Inspect observed and fitted dose distributions across important histories, compare fitted means and spread with the data, and examine whether observed doses receive extremely small fitted densities. In a longitudinal weighting analysis, very small denominator densities can produce large weights. This is a warning about the fitted treatment mechanism and resulting weights, not proof that any one modeling choice is correct.

  • Check the support first. A gamma model assigns density only to positive values; a beta model assigns density only to values strictly between zero and one. Observations outside these supports cannot be evaluated under the model.
  • Check boundaries and masses. Standard beta likelihoods require every dose to be strictly between zero and one. Exact zeros or ones, including values created by rounding or censoring, are not ordinary beta observations. A model with an explicit boundary component may be needed; adding an arbitrary small constant changes the data and does not solve the modeling problem.
  • Check the variance pattern. Gamma constant-shape models impose \( \operatorname{Var}(A\mid H)=\mu^2/k \); beta constant-precision models impose \( \operatorname{Var}(A\mid H)=\mu(1-\mu)/(\phi+1) \). Strong departures from these patterns can lead to poor density estimates even if the mean regression looks plausible.
  • Check estimated parameters and computation. Nonconvergence, estimates driven toward support boundaries, or large changes under reasonable initial values may indicate weak information, separation-like behavior, or a misspecified model. Inspect the fitted density at the actual observed doses, not only coefficient estimates.

The Gaussian model has support on the whole real line and may be reasonable for approximately symmetric doses with little probability near zero or other boundaries. The gamma model respects positive support and accommodates right skew, but its mean-variance relationship can be restrictive. The beta model respects the unit interval and permits a range of shapes, but excludes exact boundary values. Kernel estimation is a flexible alternative that does not impose these parametric shapes, but it introduces smoothing choices; it is a separate approach rather than a reason to ignore the support of the dose.

These parametric models have limitations. A conditional density can be sensitive to omitted history terms, incorrect functional forms, and a restrictive constant-shape or constant-precision assumption. A density value also depends on the measurement scale: its units are inverse dose units, and a value is not directly comparable across differently scaled treatments without accounting for that scale. In practice, use a specification compatible with the treatment's support, evaluate its fitted densities at observed values, and assess the consequences of model inadequacy for the weights.

Key takeaway: A gamma model is for strictly positive doses and a beta model is for doses strictly inside \((0,1)\). Fit the conditional model, plug in each observed history and dose to compute \( \hat f(A_{it}\mid H_{it}) \), and treat support violations, poor fit, and very small fitted densities as substantive warnings.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A gamma model has shape \(k=3\) and fitted mean \(6\). What is its conditional variance?
  2. A beta model has fitted mean \(0.25\) and precision \(7\). What are its two shape parameters?
  3. Why is a fitted density of \(1.97\) not an invalid probability?
  4. Can a standard beta likelihood directly evaluate a dose recorded as exactly \(1\)? What is the modeling issue?

Solutions. (1) The gamma variance is \( \mu^2/k=6^2/3=12 \). (2) The shapes are \( \alpha=0.25(7)=1.75 \) and \( \beta=(1-0.25)(7)=5.25 \). (3) A density is probability per unit of dose; only its integral over a set is a probability, so its value may exceed one. (4) No. The standard beta density is defined on \(0<a<1\), and its likelihood requires an interior observation. A boundary value needs a defensible model for how it arose, rather than direct substitution or an arbitrary adjustment.

Clinical Biostats