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

Default behavior for determining nobs #34

Open
stouffer opened this issue Apr 14, 2023 · 2 comments
Open

Default behavior for determining nobs #34

stouffer opened this issue Apr 14, 2023 · 2 comments

Comments

@stouffer
Copy link
Contributor

I'm a huge fan of leveraging mle2 for fitting complex models. However, I have run into multiple instances where I obtain values for downstream quantities like AICc which don't make sense.

Approximately 99 times out of 100, this is because the value being determined internally for nobs is incorrect. Because the object passed to the function using the argument data could hypothetically take just about any form, it seems to me that the assumption inherent in the following line of code is only sometimes guaranteed to be correct.

bbmle/R/mle.R

Line 587 in 918d335

if (!missing(data)) attr(m,"nobs") = length(data[[1]])

@bbolker
Copy link
Owner

bbolker commented Nov 24, 2023

Very late to this party, but what do you recommend in this situation?

@stouffer
Copy link
Contributor Author

stouffer commented Jul 1, 2024

My turn to be excessively belated. Not sure how I missed this!

Off the top of my head, I would say that the only time when nobs can confidently be determined internally is when the user passes a formula and not a function as the first argument.

In any other case, the code is beholden to a user knowing that their first item in data must be of appropriate length when it could just as easily be a scalar, character, or anything else under the sun. Therefore it would seem like, when the first argument is a function, the safest route is for the user to be forced to include nobs either as a named object within data (which feels weird, since data in theory is just information need to calculate the nll) or as an additional argument to mle2() itself.

Or maybe just the line in question gets amended to include a warning telling the user what has to date been happening silently within the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants