Post

Exponential families and link functions

A response model must give positive probability or density only to values that can actually occur on the recorded scale. A count of successes and a continuous measurement therefore require different distributions, even when both are related to the same covariates. The link function connects the mean on that response scale to a linear predictor. This reference brings the distributions and link functions together so that their interpretation can be checked against the units and possible values of the response.

B.1 Log densities, cumulant functions, means, and variances

Fix the covariate values for one observation and let $Y$ denote its response. A single expression for the conditional density or probability at $y$ is

\[f(y\mid\xi,\phi)=\exp\!\left\{\frac{y\xi-b(\xi)}{a(\phi)}+c(y,\phi)\right\}.\]

Here $\xi$ is the natural parameter, $b$ is the cumulant function and $\phi$ is the dispersion parameter, with scale $a(\phi)>0$. For a count, $f$ is a probability mass function and expectations are sums over possible counts. For a continuous response, $f$ is a density and expectations are integrals over the response scale. The term $c(y,\phi)$ supplies the part of the log probability or density that does not depend on $\xi$. To see why the same $b$ determines two moments, multiply $f$ by $e^{ty}$. This changes the coefficient of $y$ just as replacing $\xi$ by $\xi+a(\phi)t$ would. Assume that an open interval around $\xi$ lies within its allowed domain, fix $\phi$, and use the same set of possible responses throughout that interval. Also assume that $E(e^{tY})$ is finite for all $t$ in an open interval around zero, allowing the two derivatives used below. Summing or integrating the product $e^{ty}f(y\mid\xi,\phi)$ leaves the ratio of the two normalizing constants. Its logarithm is

\[K(t)=\log E(e^{tY})=\frac{b(\xi+a(\phi)t)-b(\xi)}{a(\phi)}.\]

At zero, the expectation inside the logarithm is one. Its first derivative there is $E(Y)$ and its second is $E(Y^2)$. Differentiating the logarithm subtracts $E(Y)^2$ in the second derivative, so $K^{\prime}(0)=b^{\prime}(\xi)$ gives the conditional mean and $K^{\prime\prime}(0)=a(\phi)b^{\prime\prime}(\xi)$ gives the conditional variance.

The first two derivatives of the cumulant function give the mean and variance, but evaluating a response also requires the terms that normalize its probability or density. Write $\ell(y)=\log f(y\mid\xi,\phi)$ for the value at the observed $y$. For a normal measurement with mean $\mu$ and variance $\sigma^2>0$, a Bernoulli trial with success probability $0<p<1$, and a count of successes in $m$ independent trials with that same probability, the expressions are

\[\begin{aligned} \ell_{\rm normal}(y)&=-\tfrac12\log(2\pi\sigma^2)-(y-\mu)^2/(2\sigma^2), && y\in\mathbb R,\\ \ell_{\rm Bernoulli}(y)&=y\log p+(1-y)\log(1-p), && y\in\{0,1\},\\ \ell_{\rm binomial}(y)&=\log\binom{m}{y}+y\log p+(m-y)\log(1-p), && y=0,\ldots,m. \end{aligned}\]

Collecting the terms in $y$ gives $\xi=\mu$ and $b(\xi)=\xi^2/2$ for the normal row, with scale $\sigma^2$. The two binomial rows have unit scale and the same $\xi=\log\lbrace p/(1-p)\rbrace $. The single-trial cumulant function is $\log(1+e^\xi)$ and the count cumulant function is $m$ times as large. For the next three families, let $\mu>0$ be the mean, $\alpha>0$ the gamma shape and $k>0$ the negative binomial size. With $\Gamma$ denoting the gamma function, the log probabilities and the log density are

\[\begin{aligned} \ell_{\rm Poisson}(y)&=y\log\mu-\mu-\log(y!), && y=0,1,\ldots,\\ \ell_{\rm gamma}(y)&=\alpha\log(\alpha/\mu)-\log\Gamma(\alpha) +(\alpha-1)\log y-\alpha y/\mu, && y>0,\\ \ell_{\rm NB}(y)&=\log\frac{\Gamma(y+k)}{\Gamma(k)y!} +y\log\frac{\mu}{k+\mu}+k\log\frac{k}{k+\mu}, && y=0,1,\ldots. \end{aligned}\]

For Poisson counts, $\xi=\log\mu$ gives $b(\xi)=e^\xi$. For gamma responses, use scale $1/\alpha$, so $\xi=-1/\mu$ and $b(\xi)=-\log(-\xi)$. For negative binomial counts at fixed size, the coefficient of $y$ gives $\xi=\log\lbrace \mu/(k+\mu)\rbrace $ and $b(\xi)=-k\log(1-e^\xi)$. The Poisson and negative binomial rows both use unit dispersion scale. For the negative binomial this does not imply equality of mean and variance: the fixed size $k$ gives variance $\mu+\mu^2/k$. At fixed mean, increasing $k$ reduces the extra variance above the Poisson value. For the gamma response, the variance is $\mu^2/\alpha$, so increasing shape $\alpha$ at fixed mean reduces its spread.

The normal variance $\sigma^2$ is free of the mean. A Bernoulli response has mean $p$ and variance $p(1-p)$; summing $m$ independent trials gives mean $mp$ and variance $mp(1-p)$. The Poisson mean and variance both equal $\mu$. These variances describe responses at fixed covariates, in squared response units.

The six log densities and probabilities can be evaluated with the book’s response families. From the book directory, open a new R session and follow code/examples/appendix-families.R. The log_probability_or_density(y, eta) function from resp_family() is described in Section 1.1. The gamma and negative binomial calls use the mean to set the rate or to specify the distribution directly.

1
2
3
4
5
6
7
8
9
10
11
12
13
for (file in c("stability","families","transforms","irt"))
  source(paste0("code/lib/",file,".R"))
p <- plogis(.3)
m <- 10L
mu <- 2
shape <- 3
size <- 4
log_density_or_probability <- c(normal=resp_family("normal",dispersion=2)$log_probability_or_density(1,mu),
  Bernoulli=resp_family("binomial")$log_probability_or_density(1,.3),
  grouped=resp_family("binomial",trials=m)$log_probability_or_density(3,.3),
  Poisson=resp_family("poisson")$log_probability_or_density(3,log(mu)),
  gamma=dgamma(1,shape=shape,rate=shape/mu,log=TRUE),
  NB=dnbinom(3,size=size,mu=mu,log=TRUE))

The names of these six values identify the rows. The natural and cumulant columns evaluate $\xi$ and $b(\xi)$ at the specified inputs. For the negative binomial row, substituting $e^\xi=\mu/(k+\mu)$ gives size*log1p(mu/size) for the value of the cumulant function.

1
2
3
4
5
6
7
8
print(data.frame(family=names(log_density_or_probability),observed=c(1,1,3,3,1,3),
  support=c("real","0 or 1","0 through m","nonnegative integer",
    "positive real","nonnegative integer"),
  natural=c(mu,.3,.3,log(mu),-1/mu,log(mu/(size+mu))),
  cumulant=c(mu^2/2,log1pexp(.3),m*log1pexp(.3),mu,log(mu),size*log1p(mu/size)),
  dispersion=c(2,1,1,1,1/shape,1),conditional_mean=c(mu,p,m*p,mu,mu,mu),
  conditional_variance=c(2,p*(1-p),m*p*(1-p),mu,mu^2/shape,mu+mu^2/size),
  log_density_or_probability=unname(log_density_or_probability)))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
     family observed             support    natural  cumulant dispersion conditional_mean
1    normal        1                real  2.0000000 2.0000000  2.0000000        2.0000000
2 Bernoulli        1              0 or 1  0.3000000 0.8543552  1.0000000        0.5744425
3   grouped        3         0 through m  0.3000000 8.5435524  1.0000000        5.7444252
4   Poisson        3 nonnegative integer  0.6931472 2.0000000  1.0000000        2.0000000
5     gamma        1       positive real -0.5000000 0.6931472  0.3333333        2.0000000
6        NB        3 nonnegative integer -1.0986123 1.6218604  1.0000000        2.0000000
  conditional_variance log_density_or_probability
1            2.0000000                 -1.5155121
2            0.2444583                 -0.5543552
3            2.4445831                 -2.8560607
4            2.0000000                 -1.7123179
5            1.3333333                 -0.9767519
6            3.0000000                 -1.9219650

For the grouped row, plogis(.3) gives the per-trial probability $p=0.5744425$. Three successes can occur in $\binom{10}{3}=120$ arrangements. With the unrounded value of p, the sum $\log 120+3\log p+7\log(1-p)$ gives the displayed log probability of $-2.8560607$. The Bernoulli, Poisson and negative binomial rows likewise report log probabilities at the recorded counts. The normal and gamma entries in log_density_or_probability give log densities at 1. A probability for either continuous response requires integrating its density over an interval.

These evaluations use specified parameters, including success log odds of 0.3. In a regression, observations across people could instead inform the coefficients determining those log odds. The trial total of ten comes from the design. Multiplying $p$ by ten gives an expected count of 5.7444252 and multiplying $p(1-p)$ by ten gives a count variance of 2.4445831. The other four rows all have mean 2, yet their variances depend on how the response is measured and modeled. The normal variance is set to 2 independently of its mean. For the Poisson count, the mean itself gives variance 2. For the gamma response, $b^{\prime\prime}(\xi)=1/\xi^2=\mu^2$. Multiplication by the dispersion $1/\alpha$ gives variance $4/3$ at the specified shape of 3. The negative binomial size of 4 gives variance $\mu+\mu^2/k=3$. A collection of counts could provide information about that extra variation. Here dnbinom() uses the specified size and mean to evaluate the log probability of the reported count of three.

The negative binomial as a gamma mixture of Poisson counts

How can two count distributions have the same mean but different variances? Suppose $Y$ is Poisson conditional on a rate $\lambda$, and let the rate vary across observations according to a gamma distribution with shape $k$ and rate $\rho=k/\mu$. The conditional Poisson variance contributes $E(\lambda)=\mu$ and variation of the conditional mean contributes $\operatorname{Var}(\lambda)=\mu^2/k$. To find the probability of a particular count, average its Poisson probability over the possible rates. Combining the powers of $\lambda$ and the two exponential factors gives

\[\begin{aligned} P(Y=y) &=\frac{\rho^k}{y!\,\Gamma(k)} \int_0^\infty \lambda^{y+k-1}e^{-(1+\rho)\lambda}\,d\lambda\\ &=\frac{\Gamma(y+k)}{y!\,\Gamma(k)} \left(\frac{k}{k+\mu}\right)^k \left(\frac{\mu}{k+\mu}\right)^y . \end{aligned}\]

The integral equals $\Gamma(y+k)/(1+\rho)^{y+k}$ by rescaling its argument. Taking logs recovers the negative binomial row. At fixed size, equating the linear predictor to the natural parameter therefore gives the canonical link function $g(\mu)=\log\lbrace \mu/(k+\mu)\rbrace $. As $k$ increases at fixed $\mu$, the mixing variance tends to zero, so $\lambda$ concentrates at $\mu$. For each fixed count, its Poisson probability is a bounded continuous function of the rate. Its average therefore tends to $e^{-\mu}\mu^y/y!$.

1
2
print(c(sum_binomial=sum(dbinom(0:m,m,p)),poisson_limit=dpois(3,mu),
  NB_size_4=dnbinom(3,size,mu=mu),NB_size_100000=dnbinom(3,1e5,mu=mu)))
1
2
  sum_binomial  poisson_limit      NB_size_4 NB_size_100000 
     1.0000000      0.1804470      0.1463192      0.1804452 

The first number sums probabilities across the entire binomial support. The other three numbers are probabilities of the single count $y=3$ at mean 2. Raising the negative binomial size from 4 to 100000 moves the probability from 0.1463192 to 0.1804452. Its limiting value, 0.1804470, comes from the separate Poisson call dpois(3,mu).

A simulated gamma sample

The gamma simulation uses 4,096 independent continuous responses with shape 3 and rate $\alpha/\mu=3/2$. These choices give population mean 2 and variance $4/3$. Across repeated samples of this size, the variance of the sample mean is the variance of one draw divided by 4,096. The sample standard deviation divided by $\sqrt{4096}$ estimates this Monte Carlo standard error.

1
2
3
4
RNGkind("Mersenne-Twister","Inversion","Rejection"); set.seed(1901)
draw <- rgamma(4096L,shape=shape,rate=shape/mu)
print(c(mean=mean(draw),population_mean=mu,MCSE=sd(draw)/sqrt(length(draw)),
  variance=var(draw),population_variance=mu^2/shape))
1
2
               mean     population_mean                MCSE            variance population_variance 
         2.00634846          2.00000000          0.01833418          1.37683801          1.33333333 

The sample mean 2.00635 exceeds the specified mean by about 0.00635, less than one Monte Carlo standard error. The estimate 0.01833 in MCSE is $\sqrt{1.37684/4096}$, using the sample variance printed beside it. It describes the sampling variability of the mean across independent simulations of this size. The variance estimate 1.37684 itself describes the spread of the individual draws and can be compared directly with their population variance of $4/3$. The stats package provides the probability mass and density functions for these families and the gamma random generator.

A model gives each of ten trials the same success probability $p$. How much does the expected count change when the common linear predictor increases slightly? A one-to-one link function $g$ maps a conditional mean $\mu$ in the range allowed by the response distribution to a linear predictor $\eta=g(\mu)$. Its inverse takes a linear predictor in the image of $g$ back to the mean. Where $g$ is differentiable with nonzero slope, the two slopes satisfy

\[\frac{d\eta}{d\mu}=g'(\mu),\qquad \frac{d\mu}{d\eta}=\frac{1}{g'(\mu)}\quad\text{at }\mu=g^{-1}(\eta).\]

For one trial, the logit link function maps $0<p<1$ onto the real line. Its slope is $1/\lbrace p(1-p)\rbrace $. The inverse logit function takes any real $\eta$ to $p=e^\eta/(1+e^\eta)$, so $dp/d\eta=p(1-p)$. With ten trials, the mean count is $10p$, and its change per unit of linear predictor is ten times the slope for one trial.

Which link function puts the linear predictor on the natural parameter scale? For each of the six response distributions, the equation $\mu=b^{\prime}(\xi)$ relates the mean to the natural parameter $\xi$. Solving for $\xi$ gives the canonical link function. The normal cumulant function has derivative $\xi$, so the identity link function maps any real mean to itself. Bernoulli log odds give the logit link function for a single trial. For a count with a fixed positive trial total $m$ and mean $M=mp$, substituting $p=M/m$ gives $g(M)=\log\lbrace M/(m-M)\rbrace $ for $0<M<m$. The Poisson mean $e^\xi$ gives the log link function, mapping positive means onto the real line. For the gamma distribution, $\mu=-1/\xi$ gives $g(\mu)=-1/\mu$, with negative linear predictors and inverse $\mu=-1/\eta$. The default gamma link function in R, Gamma(link="inverse"), uses the positive reciprocal, which differs in sign from the natural parameter in the density written here. For the negative binomial count at fixed size $k$, differentiating its cumulant function and solving for $e^\xi$ gives

\[\mu=\frac{k e^\xi}{1-e^\xi},\qquad e^\xi=\frac{\mu}{k+\mu}.\]

Thus the canonical link function takes a positive mean to $\log\lbrace \mu/(k+\mu)\rbrace $, which is negative. Choosing $\log\mu$ for the same family allows any real linear predictor and gives the inverse $\mu=e^\eta$.

For a regression with $\eta=x^\top\beta$, let $x$ be the covariate vector and $\beta$ the coefficient vector. With the other design entries fixed, a one-unit increase in $x_j$ changes $\eta$ by $\beta_j$. Under the normal identity link this is an additive change in mean response; under the binomial logit link it is a change in per-trial log odds; under a Poisson or negative binomial log link it multiplies the mean count by $e^{\beta_j}$.

The derivative of the inverse link function determines how a response residual enters a regression update. For one of several independent observations, write $M=E(Y\mid\eta)$ and $v=\operatorname{Var}(Y\mid\eta)>0$ for the mean and variance on the recorded response scale. At unit observation weight, the usual variance function $V$ gives $v=\phi V(M)$ with dispersion $\phi$. At fixed dispersion, differentiating the row log likelihood $\ell$ in the natural parameter gives $(y-M)/a(\phi)$, while $dM/d\xi=b^{\prime\prime}(\xi)=v/a(\phi)$. Dividing gives $d\ell/dM=(y-M)/v$. Let a prime denote differentiation in $\eta$ and set $h=M^{\prime}/v$.

Multiplying $d\ell/dM$ by $M^{\prime}$ gives the derivative with respect to the linear predictor, $(y-M)h$. Multiplication by $x$ gives the row’s score vector. Differentiating $(y-M)h$ and reversing the sign gives the observed information on the scale of the linear predictor.

\[\nabla_\beta\ell=x(y-M)h,\qquad -\frac{d^2\ell}{d\eta^2}=\frac{(M')^2}{v}-(y-M)h'.\]

The observed information has two terms because both the residual and its multiplier can change with $\eta$. The residual has conditional expectation zero. The remaining term $w=(M^{\prime})^2/v$ is the working weight in iteratively reweighted least squares (IRLS). Each row contributes $wxx^\top$ to the expected information for $\beta$. For a binomial count with the logit link function, $M^{\prime}=mp(1-p)$ and $v=mp(1-p)$. Squaring the derivative of the mean count and dividing by the count variance therefore gives $w=mp(1-p)$.

Continue in the R session prepared in Section B.1. The imported resp_family() supports the normal, binomial and Poisson families. The following calculation compares inverse-link derivatives with central differences and computes the corresponding IRLS weights at three linear predictor values. The binomial call uses one trial, so its success probability $p$ is also the expected count.

1
2
3
4
5
6
7
8
9
10
11
12
eta <- c(-2,0,2)
mu <- exp(eta)
for (f in c("normal","binomial","poisson")) {
  family <- resp_family(f)
  mean <- family$linkinv(eta)
  derivative <- family$mu_eta(eta)
  variance <- family$variance(mean)
  h <- 1e-5
  print(data.frame(family=f,eta=eta,mean=mean,derivative=derivative,
    numerical=(family$linkinv(eta+h)-family$linkinv(eta-h))/(2*h),
    variance=variance,IRLS_weight=derivative^2/variance))
}
1
2
3
4
5
6
7
8
9
10
11
12
  family eta mean derivative numerical variance IRLS_weight
1 normal  -2   -2          1         1        1           1
2 normal   0    0          1         1        1           1
3 normal   2    2          1         1        1           1
    family eta      mean derivative numerical  variance IRLS_weight
1 binomial  -2 0.1192029  0.1049936 0.1049936 0.1049936   0.1049936
2 binomial   0 0.5000000  0.2500000 0.2500000 0.2500000   0.2500000
3 binomial   2 0.8807971  0.1049936 0.1049936 0.1049936   0.1049936
   family eta      mean derivative numerical  variance IRLS_weight
1 poisson  -2 0.1353353  0.1353353 0.1353353 0.1353353   0.1353353
2 poisson   0 1.0000000  1.0000000 1.0000000 1.0000000   1.0000000
3 poisson   2 7.3890561  7.3890561 7.3890561 7.3890561   7.3890561

Each family in the loop is the list returned by resp_family() (Section 1.1). Its support function tests whether an observation is among the possible response values; log_probability_or_density(y, eta) evaluates the log probability or log density at that observation. The list has no cumulative distribution function. In the loop, linkinv returns the mean used by the link function and mu_eta returns its derivative. Passing that mean to variance gives the conditional variance of the response.

This book function includes the supplied dispersion and trial count in variance; its return is not just the variance function $V(M)$ with those multipliers removed. For a binomial count, linkinv returns $p$, mu_eta returns $dp/d\eta$ and variance(p) returns $mp(1-p)$. With $m$ trials, the working weight therefore uses the derivative of the mean count, $m\,dp/d\eta$. In the displayed one-trial case, derivative^2/variance directly gives that weight.

The numerical column computes the change in the inverse-link value from eta-h to eta+h divided by 2*h. Here the R variable h is the central difference step size, distinct from the ratio $h=M^{\prime}/v$ in the score formula.

The derivative and numerical columns agree to the printed digits at all three linear predictor values for each family. At zero, the binomial probability is one half, so both the conditional variance and the derivative of the inverse link function are one quarter. The weight is therefore $0.25^2/0.25=0.25$. At $\eta=-2$ and $\eta=2$, the probability changes more slowly and the weight falls to 0.1049936. The normal identity link function has derivative 1 and this call uses default variance 1. For the Poisson log link function, $d\mu/d\eta=\mu$, so its working weights increase with the linear predictor.

The negative binomial example reuses these linear predictor values and size of 4 from Section B.1. The vector mu <- exp(eta) gives the means under the log link function. Differentiating its inverse $e^\eta$ gives $\mu$ analytically. Its square divided by the negative binomial variance gives the working weight in the final column.

\[w=\frac{\mu^2}{\mu+\mu^2/k}=\frac{\mu}{1+\mu/k}.\]
1
2
3
print(data.frame(family="NB",link_function="log",eta=eta,mean=mu,
  natural_parameter=log(mu/(mu+size)),
  derivative=mu,variance=mu+mu^2/size,IRLS_weight=mu/(1+mu/size)))
1
2
3
4
  family link_function eta      mean natural_parameter derivative   variance IRLS_weight
1     NB           log  -2 0.1353353        -3.4195684  0.1353353  0.1399142   0.1309062
2     NB           log   0 1.0000000        -1.6094379  1.0000000  1.2500000   0.8000000
3     NB           log   2 7.3890561        -0.4326529  7.3890561 21.0385936   2.5951426

The link_function label identifies the chosen log link function for all three rows. The natural_parameter column gives a value calculated separately at each mean. At $\eta=0$, the mean and slope are both 1, but the natural parameter at that mean is $\log(1/5)\approx-1.60944$. The Poisson and negative binomial rows at this value of the linear predictor have the same change in mean per unit change in the linear predictor. The negative binomial variance of 1.25 gives the count less weight, 0.8 compared with 1 for the Poisson count. The stats package provides identity, logit and log link functions for generalized linear models.

B.3 Cumulative and adjacent-category logits

Suppose a test item awards 0, 1, 2 or 3 points. At a given level of ability, how likely is an examinee to earn at least 2 points? How likely is a score of exactly 2 compared with a score of 1? Write $P_c(z)=\Pr(Y=c\mid z)$ for the probability of category $c$ at trait value $z$. The upper-tail probability $C_j(z)=\Pr(Y\ge j\mid z)$ includes every category from $j$ upward. Every response earns at least zero points and none earns four, so $C_0(z)=1$ and $C_4(z)=0$. A score of 3 therefore counts toward the first question but plays no part in the second. Both questions concern people at the same trait value.

The graded response model specifies the odds of reaching category $j$ or higher for each $j=1,2,3$. Let $b_1<b_2<b_3$ be the thresholds and $a>0$ the discrimination. The cumulative logit at boundary $j$ is $\log\lbrace C_j(z)/(1-C_j(z))\rbrace =a(z-b_j)$. At $z=b_j$, the chance of reaching category $j$ or higher is one half. The threshold is in trait units. With the thresholds fixed, a one-unit increase in $z$ raises each cumulative logit by $a$; this is not a constant increase in a single category probability. Raising the boundary lowers its upper-tail probability at fixed $z$. To isolate exactly $j$ points, remove everyone reaching $j+1$ from those reaching $j$. The first and last categories use the fixed endpoints, giving

\[P_0(z)=1-C_1(z),\qquad P_j(z)=C_j(z)-C_{j+1}(z)\quad (j=1,2),\qquad P_3(z)=C_3(z).\]

Adding the four differences cancels the three terms $C_1(z)$, $C_2(z)$ and $C_3(z)$. With discrimination one and thresholds $(-1,0,1)$, a score of 3 has probability $C_3(z)=\operatorname{logit}^{-1}(z-1)$. The log odds of earning at least 2 points equal $z$ because the second threshold is zero.

In the generalized partial credit model, a step parameter locates the trait value at which two neighboring categories are equally likely. Denote the steps by $\delta_1,\delta_2,\delta_3$. These values need not be increasing; each concerns a different pair of neighboring categories, whereas the graded-response thresholds must be ordered. Among responses in categories $j-1$ and $j$, the model gives category $j$ conditional probability $q_j=\operatorname{logit}^{-1}\lbrace a(z-\delta_j)\rbrace $. Since $q_j=P_j/(P_{j-1}+P_j)$, its odds are $P_j/P_{j-1}$. Taking logs gives the adjacent-category logit $a(z-\delta_j)$. With the steps fixed, the positive discrimination $a$ is the increase in this log ratio per trait unit. The step $\delta_j$ is on the trait scale and gives equal probabilities for that adjacent pair, without requiring either category to have probability one half among all four categories.

To recover all four probabilities, start with category zero and multiply successive odds until category $c$ is reached. The intermediate probabilities cancel. On the log scale the multiplication becomes addition. Let $L_0=0$ and write

\[L_c=\log\frac{P_c(z)}{P_0(z)} =\sum_{j=1}^{c}a(z-\delta_j),\qquad \log P_c(z)=L_c-\log\sum_{r=0}^{3}e^{L_r}.\]

The function logsumexp() (Section 1.3) computes the common log sum. Subtracting it from each value and exponentiating gives four probabilities that sum to one. With the same three numerical values as steps and $a=1$, the second adjacent log ratio is $z$. The log ratio of category 2 to category 0 also includes the first step, so it equals $(z+1)+z=2z+1$.

For a nominal response item, the numbers identify response options. Each option has its own slope $a_c$ and intercept $d_c$. The model gives $P_c(z)=\exp(a_c z+d_c)/\sum_{r=0}^3\exp(a_r z+d_r)$. Subtracting a common term from all four linear predictors leaves the probabilities unchanged, so use category 0 as the reference and set $a_0=d_0=0$. Then $d_c$ is the log probability ratio of option $c$ to option 0 at trait zero, and $a_c$ is its change per trait unit. Between any other pair of options, the corresponding intercept and slope are differences of their parameters.

In the example, the slopes are $(0,0.5,1,1.5)$ and the intercepts are $(0,-0.5,-1,-2)$. Taking a log ratio cancels the common denominator. Comparing option 2 with option 0 gives $z-1$, whereas comparing it with option 1 gives $0.5z-0.5$. The same slopes can be written $a_c=s\,t_c$ using category scores $t_c$, with the final score fixed at $t_{K-1}=K-1$ for $K=4$ categories. The last slope then sets the multiplier to $s=1.5/3=0.5$. If the final slope is zero, the book’s nominal response function can use the three nonreference slopes directly. These category scores describe slopes in this parameterization; they are not observed ordered test scores.

Use the R session prepared in Section B.1 to compare the three models at trait values $-1$, 0 and 1. The function irt_item() (Section 10.2) constructs each item. In the returned item object, cuts[j] is $b_j$ for the graded item and $\delta_j$ for the partial credit item. The graded-model argument a is the discrimination $a$; for a nominal item, a and d instead contain the category slopes and intercepts, including their zero reference entries. The graded and partial credit items both use the default discrimination of 1. For each item, irt_prob() (Section 10.2) returns a list. Its probability matrix has one row per trait value and one column per response category. R counts columns from one, so column 3 contains the probability of category 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
z <- c(-1,0,1)
models <- list(graded=irt_item("GRM",cuts=c(-1,0,1)),
  partial_credit=irt_item("GPCM",cuts=c(-1,0,1)),
  nominal=irt_item("nominal",a=c(0,.5,1,1.5),d=c(0,-.5,-1,-2)))
for (name in names(models)) {
  result <- irt_prob(models[[name]],z)
  probability <- result$probability
  print(data.frame(model=name,z=z,category_0=probability[,1],category_1=probability[,2],
    category_2=probability[,3],category_3=probability[,4],total=rowSums(probability),
    adjacent_log_ratio=log(probability[,3]/probability[,2]),
    cumulative_log_odds=qlogis(rowSums(probability[,3:4])),
    log_probability_ratio_2_to_0=log(probability[,3]/probability[,1])))
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   model  z category_0 category_1 category_2 category_3 total adjacent_log_ratio cumulative_log_odds
1 graded -1  0.5000000  0.2310586  0.1497385  0.1192029     1         -0.4337808                  -1
2 graded  0  0.2689414  0.2310586  0.2310586  0.2689414     1          0.0000000                   0
3 graded  1  0.1192029  0.1497385  0.2310586  0.5000000     1          0.4337808                   1
  log_probability_ratio_2_to_0
1                   -1.2057177
2                   -0.1518223
3                    0.6618440
           model  z category_0 category_1 category_2 category_3 total adjacent_log_ratio cumulative_log_odds
1 partial_credit -1 0.41362198  0.4136220  0.1521630 0.02059303     1                 -1       -1.566219e+00
2 partial_credit  0 0.13447071  0.3655293  0.3655293 0.13447071     1                  0        4.440892e-16
3 partial_credit  1 0.02059303  0.1521630  0.4136220 0.41362198     1                  1        1.566219e+00
  log_probability_ratio_2_to_0
1                           -1
2                            1
3                            3
    model  z category_0 category_1 category_2 category_3 total adjacent_log_ratio cumulative_log_odds
1 nominal -1  0.6521404  0.2399090 0.08825761 0.01969293     1               -1.0          -2.1118484
2 nominal  0  0.4739908  0.2874900 0.17437149 0.06414769     1               -0.5          -1.1608153
3 nominal  1  0.2772748  0.2772748 0.27727478 0.16817566     1                0.0          -0.2190702
  log_probability_ratio_2_to_0
1                           -2
2                           -1
3                            0

In each row the four probabilities, category_0 through category_3, sum to the printed total of 1. At $z=0$ the graded item gives $P_0=1-\operatorname{logit}^{-1}(1)\approx0.26894$. The partial credit steps give $(L_0,L_1,L_2,L_3)=(0,1,1,0)$, so $P_0=1/(2+2e)\approx0.13447$. The first graded threshold divides all responses into two groups. The first partial credit step fixes the odds between just two categories, and the other two categories enter the normalizing sum.

The columns adjacent_log_ratio, cumulative_log_odds and log_probability_ratio_2_to_0 give $\log(P_2/P_1)$, $\log\lbrace (P_2+P_3)/(P_0+P_1)\rbrace $ and $\log(P_2/P_0)$, respectively. At zero, the positive partial credit weights $e^{L_c}=P_c/P_0$ before normalization pair symmetrically, so categories 2 and 3 together have probability one half. The corresponding cumulative log odds are zero up to the rounding visible in 4.440892e-16.

Across the two unit intervals the graded log ratio of category 2 to category 0 increases by 1.05390 and 0.81367. The nominal cumulative log odds increase by 0.95103 and 0.94175. Each pair of unequal increments rules out a straight line through those three values. The graded adjacent log ratio increases by 0.43378 on both intervals. Equal increments at three points alone cannot establish linearity elsewhere. The graded cumulative logit for a score of 2 or higher equals $z$ for every trait value by its defining equation.

How would these probabilities enter an item update if examinees’ responses were available? In the maximization step (M step) of expectation-maximization, fix the expected number $n_{kc}$ of responses in category $c$ at trait node $z_k$. For a Rasch or two-parameter logistic item, the two counts give expected successes and failures. Their success probability is $p_k=\operatorname{logit}^{-1}(d+az_k)$: $d$ is the log odds at trait zero and $a$ is the log-odds increase per trait unit. With $a>0$, difficulty $-d/a$ is the trait value giving probability one half. With node total $n_k$ and success probability $p_k$, the weighted logistic regression update uses count residual $n_{k1}-n_kp_k$ and working weight $n_kp_k(1-p_k)$. The Rasch slope is fixed at one. The two-parameter model also updates the slope.

For a polytomous item, let $\theta$ contain the free parameters in the order returned by irt_item_pack(). For graded items, these are the discrimination and cumulative-logit intercepts $-ab_j$. For partial credit items, they are the discrimination and the intercepts $-a\sum_{j=1}^{c}\delta_j$ of the log ratios to category zero. The part of the expected complete-data log likelihood that depends on this item’s parameters is $Q(\theta)=\sum_{k,c}n_{kc}\log P_c(z_k;\theta)$.

The array entry irt_prob(item, z)$gradient[k, c + 1, j] gives the derivative of this category’s log probability with respect to free item parameter $\theta_j$. Multiply by $n_{kc}$ and sum over nodes and categories to obtain $\partial Q/\partial\theta_j$.

For example, increasing the nominal intercept $d_2$ changes the log numerator for category 2 at rate one and the log normalizing sum at rate $P_2(z_k)$. Category 2 thus contributes $n_{k2}\lbrace 1-P_2(z_k)\rbrace $ to $\partial Q/\partial d_2$ at that node. The other categories contribute $-n_{kc}P_2(z_k)$ apiece. Minimizing $-Q$ reverses the sign of their sum.

The separate field d_log_probability_d_trait measures change with the trait at fixed item parameters. The printed tables evaluate category probabilities at the supplied item parameters. The mirt package fits all three polytomous item models.

This post is licensed under CC BY-NC 4.0 by the author.