I was comparing the results of the cumulative link model results from mgcv and ordinal package. For analogous models, every result (coefficients and AIC) seems to be almost the same, except for the fitted (or predicted) values. I found it when I was trying to calculate Somers Delta as a goodness of fit index for the models, using DescTools package. I will share here some code that I have been testing.
load packages
library(mgcv)
library(ordinal)
library(DescTools)
Simulate some ordered categorical data...
set.seed(3);n<-400
dat <- gamSim(1,n=n)
dat$f <- dat$f - mean(dat$f)
alpha <- c(-Inf,-1,0,5,Inf)
R <- length(alpha)-1
y <- dat$f
u <- runif(n)
u <- dat$f + log(u/(1-u))
for (i in 1:R) {
y[u > alpha[i]&u <= alpha[i+1]] <- i
}
dat$y <- y
I was comparing the results of the cumulative link model results from mgcv and ordinal package. For analogous models, every result (coefficients and AIC) seems to be almost the same, except for the fitted (or predicted) values. I found it when I was trying to calculate Somers Delta as a goodness of fit index for the models, using DescTools package. I will share here some code that I have been testing.
load packages
library(mgcv) library(ordinal) library(DescTools)
Simulate some ordered categorical data...
set.seed(3);n<-400 dat <- gamSim(1,n=n) dat$f <- dat$f - mean(dat$f) alpha <- c(-Inf,-1,0,5,Inf) R <- length(alpha)-1 y <- dat$f u <- runif(n) u <- dat$f + log(u/(1-u)) for (i in 1:R) { y[u > alpha[i]&u <= alpha[i+1]] <- i } dat$y <- y
Fit with mgcv
b <- gam(y~x0+x1+x2+x3,family=ocat(R=R),data=dat) summary(b) AIC(b) SomersDelta(x=b$fitted.values, y=dat$y, conf.level = 0.95) # 0.58
Fit with ordinal
b2<-clm(as.factor(y)~x0+x1+x2+x3,data=dat,link="logit",threshold="flexible") summary(b2) AIC(b2) SomersDelta(x=b2$fitted.values, y=dat$y, conf.level = 0.95) # -0.27
plot(x=b$fitted.values,y=dat$y) plot(x=b2$fitted.values,y=dat$y) plot(x=b$fitted.values,y=b2$fitted.values)