3
$\begingroup$

I run a null binomial generalized additive models (gam) using mgcv and it gives negative deviance explained! As far as I know deviance explained is analogue of R^2 so it should be between 0 and 1. So is this negative deviance explained occurred by the package error? If so, then how can I manually estimate deviance explained?

My code is given below

library(mgcv)
x1 = rnorm(100)
x2 = rnorm(100)
y = rbinom(100, 1, 0.5)
Data = data.frame(y, x1, x2)
model = gam(y ~ 1, data=Data, family=binomial)
summary(model)$dev.expl

output:

[1] -2.050785e-16
$\endgroup$

1 Answer 1

3
$\begingroup$

A number like -2.050785e-16 is R’s way of telling you the answer is zero. When you fit an intercept-only model like you do here, the model really does explain zero percent of the deviance, so this is correct behavior. Getting a value with a minus sign out in front could be because the inner workings of the optimization algorithm is slightly different from what happens when the total deviance is calculated, but this is not so concerning to me.

$\endgroup$
1
  • $\begingroup$ @Lost Use zero for what? $\endgroup$
    – Dave
    Commented Apr 13, 2023 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.