runehaubo / ordinal

R package ordinal: Regression Models for Ordinal Data
Other
33 stars 12 forks source link

Difference in Fitted (predicted values) and Somers Delta between ordinal and mgcv package #44

Closed influence-of-canopy-on-temperature closed 1 year ago

influence-of-canopy-on-temperature commented 3 years ago

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, and I noted that comparing models with different loglikelihood in ordinal package, sometimes a model with low loglikelihood would have higher Somers Delta, which does not make so much sense to me. However, with mgcv package, the models with higher loglikelihood were more coherent having higher Somers Delta index. 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)

runehaubo commented 1 year ago

Just cleaning up on an old issue here. The presumption in this post seems to be that the gam model is equivalent to the clm model, but as far as I can tell they are not. Whatever difference there may be in an index such as Somer's Delta is therefore not an indication that something is wrong with clm. I'm therefore closing the issue here.