pfmc-assessments / indexwc

Estimate indices of abundance for west coast fish species
2 stars 1 forks source link

[BUG]: AIC calcuation #20

Closed okenk closed 1 year ago

okenk commented 1 year ago

Is there an existing issue for this?

Current Behavior

Current AIC values reported in aic_nll.txt are negative. AIC be positive though since NLL is positive. Formula is 2 n_pars - 2 loglikelihood

Note -2 loglikelihood. If using NLL (from optimization) formula is 2 n_pars PLUS 2 NLL

Expected Behavior

AIC should generally be positive.

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

kellijohnson-NOAA commented 1 year ago

I am just using what {sdmTMB} reports. Here is the code

extractAIC.sdmTMB <- function(fit, scale, k = 2, ...) {
  L <- logLik(fit)
  edf <- attr(L, "df")
  return(c(edf, c(-2 * L + k * edf)))
}

which can be found here.

kellijohnson-NOAA commented 1 year ago

Ahh, I see the problem. It is my fault 😮‍💨 . I am labeling the log likelihood as the "NLL" or negative log likelihood, which is incorrect. @okenk would you prefer that I fix the label or fix the value?

kellijohnson-NOAA commented 1 year ago

I changed the value to match the NLL label. Please feel free to reopen the issue if you would like the log likelihood to be saved instead.