<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/adjacent-categories-and-continuation-ratio-logit-models-for-ordinal-outcomes/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://statcompute.wordpress.com/2018/08/26/adjacent-categories-and-continuation-ratio-logit-models-for-ordinal-outcomes/"> S+/R – Yet Another Blog in Statistical Computing</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>ï»¿In the previous post (<a rel="nofollow" href="https://statcompute.wordpress.com/2018/01/28/modeling-lgd-with-proportional-odds-model" target="_blank">https://statcompute.wordpress.com/2018/01/28/modeling-lgd-with-proportional-odds-model</a>), I’ve shown how to estimate a standard Cumulative Logit model with the ordinal::clm function and its use case in credit risk models. To better a better illustration of the underlying logic, an example is also provided below, showing how to estimate a Cumulative Logit model by specifying the log likelihood function. </p>
<pre>
pkgs &lt;- list(&quot;maxLik&quot;, &quot;VGAM&quot;)
sapply(pkgs, require, character.only = T)
df &lt;- read.csv(&quot;Downloads/lgd.csv&quot;)
df$lgd_cat &lt;- ifelse(round(1 - df[2], 4) == 0, &quot;L&quot;,
                ifelse(round(1 - df[2], 4) == 1, &quot;H&quot;, &quot;M&quot;))

### DEFINE LOGLIKELIHOOD FUNCTION OF CUMULATIVE LOGIT MODEL ###
# BELOW IS THE SIMPLER EQUIVALENT:
# vglm(sapply(c(&quot;L&quot;, &quot;M&quot;, &quot;H&quot;), function(x) df$lgd_cat == x) ~ LTV, data = df, family = cumulative(parallel = T))

ll01 &lt;- function(param) {
  a1 &lt;- param[1]
  a2 &lt;- param[2]
  b1 &lt;- param[3]
  xb_L &lt;- a1 - df$LTV * b1
  xb_M &lt;- a2 - df$LTV * b1
  prob_L &lt;- exp(xb_L) / (1 + exp(xb_L))
  prob_M &lt;- exp(xb_M) / (1 + exp(xb_M)) - prob_L
  prob_H &lt;- 1 - prob_M - prob_L
  CAT &lt;- data.frame(sapply(c(&quot;L&quot;, &quot;M&quot;, &quot;H&quot;), function(x) assign(x, df$lgd_cat == x)))
  LH &lt;- with(CAT, (prob_L ^ L) * (prob_M ^ M) * (prob_H ^ H))
  return(sum(log(LH)))
}
</pre>
<p>Instead of modeling the cumulative probability of each ordered category such that Log(Prob &lt;=Y_i / (1 – Prob &lt;=Y_i)) = Alpha_i – XB, we could also have alternative ways to estimate the categorical probabilities by using Adjacent-Categories Logit and Continuation-Ratio Logit models. </p>
<p>In an Adjacent-Categories Logit model, the functional form can be expressed as Log(Prob = Y_i / Prob = Y_j) = Alpha_i – XB with j = i + 1. The corresponding log likelihood function is given in the code snippet below. </p>
<pre>
### DEFINE LOGLIKELIHOOD FUNCTION OF ADJACENT-CATEGORIES LOGIT MODEL ###
# BELOW IS THE SIMPLER EQUIVALENT:
# vglm(sapply(c(&quot;L&quot;, &quot;M&quot;, &quot;H&quot;), function(x) df$lgd_cat == x) ~ LTV, data = df, family = acat(parallel = T, reverse = T))

ll02 &lt;- function(param) {
  a1 &lt;- param[1]
  a2 &lt;- param[2]
  b1 &lt;- param[3]
  xb_L &lt;- a1 - df$LTV * b1
  xb_M &lt;- a2 - df$LTV * b1
  prob_H &lt;- 1 / (1 + exp(xb_M) + exp(xb_M + xb_L))
  prob_M &lt;- exp(xb_M) * prob_H
  prob_L &lt;- 1 - prob_H - prob_M
  CAT &lt;- data.frame(sapply(c(&quot;L&quot;, &quot;M&quot;, &quot;H&quot;), function(x) assign(x, df$lgd_cat == x)))
  LH &lt;- with(CAT, (prob_L ^ L) * (prob_M ^ M) * (prob_H ^ H))
  return(sum(log(LH)))
}
</pre>
<p>If we take the probability (Prob = Y_i) from the Adjacent-Categories Logit and the probability (Prob > Y_i) from the Cumulative Logit, then we can have the functional form of a Continuation-Ratio Logit model, expressed as Log(Prob = Y_i / Prob > Y_i) = Alpha_i – XB. The log likelihood function is also provided. </p>
<pre>
ll03 &lt;- function(param) {
  a1 &lt;- param[1]
  a2 &lt;- param[2]
  b1 &lt;- param[3]
  xb_L &lt;- a1 - df$LTV * b1
  xb_M &lt;- a2 - df$LTV * b1
  prob_L &lt;- 1 / (1 + exp(-xb_L))
  prob_M &lt;- 1 / (1 + exp(-xb_M)) * (1 - prob_L)
  prob_H &lt;- 1 - prob_L - prob_M
  CAT &lt;- data.frame(sapply(c(&quot;L&quot;, &quot;M&quot;, &quot;H&quot;), function(x) assign(x, df$lgd_cat == x)))
  LH &lt;- with(CAT, (prob_L ^ L) * (prob_M ^ M) * (prob_H ^ H))
  return(sum(log(LH)))
}
</pre>
<p>After specifying log likelihood functions for aforementioned models, we can use the maxLik::maxLik() function to calculate parameter estimates. It is also shown that, in this particular example, the Cumulative Logit is slightly better than the other alternatives in terms of AIC. </p>
<pre>
# start = c(a1 = 0.1, a2 = 0.2, b1 = 1.0)
# lapply(list(ll01, ll02, ll03), (function(x) summary(maxLik(x, start = start))))

[[1]]
--------------------------------------------
Estimates:
   Estimate Std. error t value  Pr(t)    
a1  0.38134    0.08578   4.446 8.76e-06 ***
a2  4.50145    0.14251  31.587  &lt; 2e-16 ***
b1  2.07768    0.12506  16.613  &lt; 2e-16 ***
--------------------------------------------
[[2]]
--------------------------------------------
Estimates:
   Estimate Std. error t value  Pr(t)    
a1  0.32611    0.08106   4.023 5.74e-05 ***
a2  4.05859    0.14827  27.373  &lt; 2e-16 ***
b1  1.88466    0.11942  15.781  &lt; 2e-16 ***
--------------------------------------------
[[3]]
--------------------------------------------
Estimates:
   Estimate Std. error t value  Pr(t)    
a1  0.30830    0.08506   3.625 0.000289 ***
a2  4.14021    0.15024  27.558  &lt; 2e-16 ***
b1  1.95643    0.12444  15.722  &lt; 2e-16 ***
--------------------------------------------

# sapply(list(ll01, ll02, ll03), (function(x) AIC(maxLik(x, start = start))))
3764.110 3767.415 3771.373
</pre>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://statcompute.wordpress.com/2018/08/26/adjacent-categories-and-continuation-ratio-logit-models-for-ordinal-outcomes/"> S+/R – Yet Another Blog in Statistical Computing</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/na7Z2fESMkE" height="1"></a></div>