[R-sig-ME] Comparing AIC of a model and its logit -transformed version

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Fri Feb 23 01:32:32 CET 2024


   This is not actually a mixed-model question -- it would be better on 
stats.stackexchange.com -- but here we go:

  A clear description of the calculation is here:

https://stats.stackexchange.com/a/100671/2126

  We need -2 * sum(log( d( log(x/(1-x)), "x" )))

Being super-lazy and using sympy

from sympy import *
x = Symbol("x")
simplify(diff(log(x/(1-x)), x))
## -1/(x*(x-1)) = 1/(x*(1-x))

taking -2*log() of this we get

2*sum(log(x*(1-x)))


seedrates <- data.frame(rate = c(50, 75, 100, 125, 150),
                            grain = c(21.2, 19.9, 19.2, 18.4, 17.9)) |>
    transform(pgrain = grain/100, logit_grain = qlogis(grain/100))

m0 <- lm(pgrain~1, data=seedrates)
m1 <- lm(logit_grain ~ 1, data = seedrates)

AIC(m0)
with(seedrates, AIC(m1) + 2*sum(log(pgrain*(1-pgrain))))

These are actually slightly different because of Jensen's inequality 
(the predicted values mean(pgrain) and plogis(mean(logit_grain)) are not 
quite the same), but close enough that I think the computation is done 
correctly.

On 2024-02-22 9:13 a.m., Boby Mathew wrote:
> Hello All,
> I would like to compare a model to its logit transformation using the AIC
> values.
> 
> As a toy example
> library(car)
> 
> seedrates <- data.frame(rate = c(50, 75, 100, 125, 150),
>                          grain = c(21.2, 19.9, 19.2, 18.4, 17.9))
> lm <- lm(grain~rate, data=seedrates)
> logit.lm <- lm(logit(grain)~rate,data=seedrates)
> 
> AIC(lm, logit.lm )
> 
> In order to compare these two models using AIC we need to take into account
> the JAcobian of the logit transformation.
> 
> 
> Here
> https://stats.stackexchange.com/questions/61332/comparing-aic-of-a-model-and-its-log-transformed-version
> 
> Prof. Ben Bolker mentioned how we can adjust the AIC in the presence of log
> transformation by the multiplication of the likelihood by the corresponding
> Jacobian to the AIC ... for the case of log{y(n)+1}, it is −2 ⋅∑log{y(n)+1}
> 
> I was wondering in the case of logit transformation can I adjust the AIC by
> multiplying the likelihood by logit{y(n)+1}.
> 
> Any help is greatly appreciated.
> 
> Kind regards,
> 
> Boby  Mathew
>



More information about the R-sig-mixed-models mailing list