Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AICc for fitspecaccum object #250

Closed
NivDeMalach opened this issue Aug 27, 2017 · 11 comments
Closed

AICc for fitspecaccum object #250

NivDeMalach opened this issue Aug 27, 2017 · 11 comments

Comments

@NivDeMalach
Copy link

Hi,
I try to apply model selection approach for different models using the 'fitspecaccum' function.
When I apply AIC it works. but when I try AICc I get the following error message

Error in UseMethod("logLik") :
no applicable method for 'logLik' applied to an object of class "c('fitspecaccum', 'specaccum')"

Thanks,
Niv

@jarioksa
Copy link
Contributor

jarioksa commented Aug 27, 2017

When I try AICc, I get this message:

> AICc(mods)
Error: could not find function "AICc"

So it looks like R does not have function AICc in base or stats. I guess AICc is in some add-on package, and nobody has written a method to access fitspecaccum results for that package. However, judging from your error message it could be sufficient to write a logLik method for fitspecaccum. It seems to me that writing that logLik method is very simple, but I am not sure if this is sufficient: for that I would need to know in which package you have the AICc function.

The logLik looks this simple:

`logLik.fitspecaccum` <-
    function(object, ...)
{
    sapply(object$models, logLik, ...)
}

I don't know if this sufficient, and I don't know what would you do with this.

@jarioksa
Copy link
Contributor

jarioksa commented Aug 27, 2017

Please note that fitspecaccum models are not nested which means that you cannot use AIC or AICc to select between them. People do so, but it is not correct.

@NivDeMalach
Copy link
Author

Thanks a lot for your help,

Indeed AICc comes from the "MuMIn' package...
After adding this logLik function I get a new error message 'Error in nobs.default(object) : no 'nobs' method is available'. Do you have another suggestions?

P.S. The assertion that AICc cannot be used for non-nested models is very controversial( but common among R users since it was proposed by Ripley). I believe that most of the experts in the field would disagree (see example below). Are you aware of any other method for comparing nonlinear models that can be used for 'fitspecaccum' (BIC also doesn't work...)

https://sites.warnercnr.colostate.edu/anderson/wp-content/uploads/sites/26/2016/11/AIC-Myths-and-Misunderstandings.pdf

@jarioksa
Copy link
Contributor

jarioksa commented Aug 28, 2017

I assumed that mere logLik.fitspecaccum would not suffice. Obviously you also need a nobs method:

nobs.fitspecaccum <-
    function(object, ...)
{
    sapply(object$models, nobs, ...)
}

Once we get a list of all needed method functions, I'll add them to vegan.

@NivDeMalach
Copy link
Author

Thanks again!
Now, I don't get an error message anymore but something else is wrong I get the value
"numeric(0)"

@jarioksa
Copy link
Contributor

It seems that we need the following functions:

`logLik.fitspecaccum` <-
    function(object, ...)
{
    out <- sapply(object$models, logLik, ...)
    ## sapply() strips attributes: get'em back
    attr(out, "df") <- 1L + length(coef(object$models[[1]]))
    attr(out, "nobs") <- nobs(object$models[[1]])
    class(out) <- "logLik"
    out
}

`nobs.fitspecaccum` <-
    function(object, ...)
{
    sapply(object$models, nobs, ...)
}

@NivDeMalach
Copy link
Author

It works!

Thanks a lot

@jarioksa
Copy link
Contributor

Fine! Now I can give an easier way of doing the same:

## mod is a fitspecaccum result object
sapply(mod$models, AICc)

This does not need any new vegan functions. I didn't want to give that at once because I wanted someone to test that the new functions also work and are sufficient...

jarioksa pushed a commit that referenced this issue Aug 28, 2017
These allow some external functions and packages to work with
the result objects. See github issue #250
@jarioksa
Copy link
Contributor

Closed with commit 4759e1f

@gavinsimpson
Copy link
Contributor

@jarioksa

Please note that fitspecaccum models are not nested which means that you cannot use AIC or AICc to select between them. People do so, but it is not correct.

I hear both sides of this.

Reading Simon Wood's new 2nd Edition of Generalized Additive Models: an Introduction with R, he claims that comparing models via AIC doesn't require the models to be nested, but if they are some terms in the approximation of the expected K-L divergence cancel.

@jarioksa
Copy link
Contributor

It is just the same for me how you do if you are aware of what you do.

jarioksa pushed a commit that referenced this issue Nov 20, 2017
These allow some external functions and packages to work with
the result objects. See github issue #250

(cherry picked from commit 7ced202)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants