rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
402 stars 90 forks source link

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

Closed influence-of-canopy-on-temperature closed 3 years 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. 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)

aronatkins commented 3 years ago

This issue is not against packrat and was also filed here: https://github.com/runehaubo/ordinal/issues/44