nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
160 stars 24 forks source link

rewrite buildMCEM and associated tools and documentation #1428

Closed perrydv closed 5 months ago

perrydv commented 8 months ago

This contains a nearly complete rewrite of buildMCEM. This includes:

One thing I did not do (but could) is create a new predefined nimbleList class for results from MCEM. This would be useful, but I'm wondering if it's not really that important right now.

There is a very extensive roxygen draft entry. The User Manual section has been revised and shortened.

perrydv commented 7 months ago

@paciorek @danielturek It would be good to some other eyes on this at some point, even at least the documentation and API and names of user-facing things.

paciorek commented 6 months ago

Ok, I looked through some but not enough to really do code review of the algorithm details.

I'm not following the distinction in the testing between cases with calcNodesOther and without.

A couple minor things:

I'd prefer to just use our standard messageIfVerbose pattern in setup code rather than having a distinct verboseUse. If you really want the latter, I would like it to be named verbose and not verboseUse.

In findMLE we have "[Warning]" followed by stop. Given that, it's not a warning, so let's just omit " [Warning]" from the error message.

danielturek commented 6 months ago

@perrydv

To be consistent with the method name findMLE, would it make more sense to have the covariance-finding method be called findCov, rather than the current name vcov ?

How big a deal (from the package standpoint) is adding the addition Suggests for the mcmcse package, in DESCRIPTION? I know we try to keep the Imports to the minimum, so I'm wondering about Suggests. I guess it's unavoidable though? And is merely making it a Suggests field sufficient, being that the nimbleRcall to mcse is necessary for the algorithm?

What exactly happens in the case of discrete latent states (random effects)? In addition to emitting a warning in setupMargNodes, will something error out later? Or do we just remove them, and things continue, everything "works" in some sense? Just giving a warning that "this is likely to cause problems" feels unsatisfactory. Can we expand this, to state that discrete random effects will be omitted, and therefore the whole algorithm is being executed as though they are not in the model - and the results may not be what a user wants? (if that's correct).

I, as well, did not inspect the algorithm carefully.

I read through the roxygen for buildMCEM, and truthfully, it read pretty well, and I have no serious suggestions.

Line 592 of MCEM_build.R, I think "override" is a word in of itself (no hyphen required).

Lines 697 - 698, it wasn't clear to me on first reading what "is created by the same call with \code{config} instead of ..." meant. Looking at the code (how config is used) I now understand what this means, but without looking at the relevant code, I didn't understand this.

How would you feel about changing the continue argument (with default FALSE) to instead be reset (with default TRUE)?

Missing a period at the very end of line 353 in chapter_OtherAlgorithms.Rmd.

perrydv commented 5 months ago

Thanks @paciorek @danielturek. These will be mostly clarifications and some minor changes. I am on another branch as I write this so I'll post the comment and make the changes later.

paciorek commented 5 months ago

I'm fine with continue for the reasons you give.

danielturek commented 5 months ago

Sounds good to me.

perrydv commented 5 months ago

Moved documentation notes and typos to #1434 so I can look at merge conflicts and merge this for @paciorek 's workflow.

perrydv commented 5 months ago

@paciorek Lots of test failures here are due to not having package mcmcse. I thought I had added it for testing by adding it to the list in install_requirements.R. Am I doing that wrong?

paciorek commented 5 months ago

It needs to be in Suggests in DESCRIPTION plus you'll probably need a requireNamespace("mcmcse") before you use the mcmcse function.

I'm happy to just deal with this all - how about you leave it for me to merge in.

paciorek commented 5 months ago

@perrydv I see you added @export for some new, undocumented functions for MCEM. Are you sure they need to be exported?

paciorek commented 5 months ago

The mcmcse-related test failure seems to have occurred because mcmcse failed to install on the runner. I'm playing with the install script.

perrydv commented 5 months ago

Just MCEM_mcse? That could get documentation to just say "see buildMCEM". Its purpose is to calculate the Monte Carlo standard error from an MCMC sample.

paciorek commented 5 months ago

It looks like we may need to only export MCEM_mcse, so that is what I am exporting now. I guess because that is called by a nimbleRcall?

perrydv commented 5 months ago

Yes, we call it from C++ and it needs to be findable in the global environment. I tell users in the documentation that they can provide a new MCMC_mcse in the global environment if they want to change methods.

paciorek commented 5 months ago

We now have an MCEM test failure on Windows only. It's a bit hard to tell if the issue is the lack of /usr/bin/time or an actual failure because the testing if printing out a ton of stuff and it's hard to see in the CI output.

It looks like @perrydv had not yet re-enabled our usual flags about verbosity and whatnot, nor reset the MCEM gold file (it's actually gone completely from new-MCEM). I can work on that and see if that leads me to determine the test failure is a non-issue or something to be dealt with.

perrydv commented 5 months ago

I did end up with a non-gold-file new MCEM testing system, IIRC. I will have to look. I don't know why numerical results would differ on Windows. Is the /usr/bin/time from run_tests.R ?

paciorek commented 5 months ago

Ok, I am in the middle of generating one. We should talk about this before you make any commits as I've been making changes to the branch and have some stuff in progress.

I don't think we want as much being printed to the screen as is currently happening because you left out the various preamble stuff (setting verbosity, no MCMC progress, sink, etc.) we have in many of our numerically-focused test files. Which to me implies we want to sink to a gold file.

paciorek commented 5 months ago

I will look into the timing thing as needed. I am suspecting the Windows error is a red herring.

perrydv commented 5 months ago

Sorry about the verbosity. We could also try to turn that back down with various settings.

paciorek commented 5 months ago

Canceling workflow given issues with the new mcem goldfile. I will hopefully look at this more tomorrow.

My inclination is that verbosity is fine (even good) provided in a gold file.

paciorek commented 5 months ago

Error appears to be a minor thing in gold file that I am fixing. I am merging this in rather than waiting for CI to run.