Fixes the inability to map parameters#1406
Conversation
|
According to Google the difference between
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1406 +/- ##
==========================================
+ Coverage 82.97% 89.20% +6.23%
==========================================
Files 54 83 +29
Lines 2214 8590 +6376
Branches 579 583 +4
==========================================
+ Hits 1837 7663 +5826
- Misses 279 895 +616
+ Partials 98 32 -66 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| # Number of rows for derived quantities: based on the difference | ||
| # between the total number of rows in std and the length of parameter_names. | ||
| derived_quantity_nrow <- nrow(std) - length(parameter_names) | ||
| derived_quantity_nrow <- nrow(std) - n_fixed_parameters |
There was a problem hiding this comment.
It does not look like the code here is set up to handle random effects models.
I would use instead: ‘derived_quantity_nrow <- summary(std, “report”) |> nrow()’
Then:
‘random_nrow <- summary(std, “random”) |> row()’
| ) | ||
| FIMS::set_fixed(opt$par) | ||
| expanded_fixed <- obj[["env"]]$parList(opt[["par"]])[["p"]] | ||
| FIMS::set_fixed(expanded_fixed) |
There was a problem hiding this comment.
I don’t understand the purpose of set_fixed. It looks like it is only used just before sdreport, but that function defines par within the function, so par is being redefined by sdreport. I am also very uncomfortable giving users the ability to overwrite info->fixed_effects_parameters and info->random_effects_parameters. It seems like doing so could cause a lot of unintended consequences in optimization an SE calculation. TMB’s obj manages parameter updates the parameters in obj should point to info->fixed_effects_parameters and info->random_effects_parameters
|
When map is invoked, I think we need to fix the mismatch between obj$par and info->fixed_effects_parameters and info->random_effects_parameters immediately after MakeADFun because any run with cause a mismatch in parameters here which will cause errors. Also the model will be trying to optimize parameters that are not linked to anything in the model, which will lead to convergence errors. I think we should pull out map IDs from obj somehow and use these to update fixed and random effects vectors in info before doing anything else. We will still need to track what has been mapped to link back up with obj$env$parList(). |
I dug into this a bit more and wanted to correct my comment above. When using the map argument, TMB does not modify the length of |
c9112fe to
aa8e413
Compare
What is the feature?
TMB::MakeADFun()set_fixed()is not the same length as what is expected because before R would crash.How have you implemented the solution?
obj[["env"]]$parList(opt[["par"]])[["p"]]instead ofopt[["par"]]Does the PR impact any other area of the project, maybe another repo?
Instructions for code reviewer
👋Hello reviewer👋, thank you for taking the time to review this PR!
nit:(for nitpicking) as the comment type. For example,nit:I prefer using adata.frame()instead of amatrixbecause ...This PR is now ready to be merged.Checklist