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

Updates to standardize and simplify #34

Merged
merged 24 commits into from
Sep 12, 2018
Merged

Updates to standardize and simplify #34

merged 24 commits into from
Sep 12, 2018

Conversation

patrickbarks
Copy link
Collaborator

Updates primarily to standardize code and documentation, and simplify or split complicated functions.

Resolves the following issues: #7, #13, #16, #19, #23, #24, #25, #26, #27, #28, #29, #30, #31, #32, #33; and partly addresses #12 (I believe Iain is handling the rest of that one). Also pulls matrix-level functions from Rcompadre into Rage, as per jonesor/Rcompadre#28.

…t each return a single scalar value, and modify longevity so that 'initPop' argument becomes 'lxCrit' as per #16
…), update documentation of collapseMatrix (closes #24), change 'collapse' argument of collapseMatrix and output of reprodStages to list format (closes #25), and remove 'post' argument from reprodStages (closes #29)
…calculate per-generation growth rate (closes #27)
…move scalar elements R0 and Tc, as per #12, and re-formatted 'return' section of documentation.
…ent instead of matF and/or matC (R0 has already been updated, so this closes #19). Also includes edits toward standardizing documentation.
…ts to code for readability, added some input validation checks, and made edits toward standardizing documentation
… edits to code for readability, and made edits toward standardizing documentation
…nged default pert parameter to 1e-6, and made small edits to improve code readability and standardize documentation
…rmat (closes #33), and made small edits toward standardizing documentation
…a and stable stage dist, respectively (closes #26)
@patrickbarks
Copy link
Collaborator Author

@RobSalGo I added a new version of vitalRatePerturbation based on the version you sent. This version has two main updates corresponding to two 'tricky' scenarios:

(1) Fecundity or clonality in a stage from which there is no survival

If a given stage has positive fecundity or clonality but no survival, the previous version would zero out the sensitivities to fecundity/clonality as it pulled out the (nonexistent) survival component of those vital rates. This version retains those sensitivities — e.g. if there is fecundity but no survival in a given column, the 'full sensitivity' of a fecundity transition is attributed to the fecundity vital rate (and likewise for clonality).

(2) Age-based transition in matU (i.e. when a column of matU contains only 1 nonzero element)

The previous version would return nonzero sensitivites to growth for age-only models, because it effectively assumed that diagonal elements of matU were never structural zeros. This version treats all zeros as structural and assumes that, if a given column of matU has only 1 nonzero element, the only vital rate within that column is survival (no growth or shrinkage).

 
If an MPM doesn't have either of the above properties, this version of the fn gives the same result as the previous version. Here's an example that has both scenarios described above, with matching sensitivities from popbio for comparison:

# specify vital rates of survival and fecundity for age-only model
s1 <- 0.5
s2 <- 0.6
f <- 1.4

# specify matrices for Rage
matU <- rbind(c(0,  0,  0),
              c(s1, 0,  0),
              c(0,  s2, 0))

matF <- rbind(c(0,  0,  f),
              c(0,  0,  0),
              c(0,  0,  0))

# specify matA in expression form for popbio
matA_exp <- expression(
  0,   0,   f,
  s1,  0,   0,
  0,   s2,  0
)

# vital rate list for popbio
vital_rates_l <- list(s1 = s1, s2 = s2, f = f)

# perturbation with popbio
popbio::vitalsens(matA_exp, vital_rates_l)

# perturbation with new vitalRatePerturbation
vitalRatePerturbation(matU, matF)
# sensitivity to growth is zero, sensitivity to fecundity is positive
# with previous version, those are reversed

I don't mean to 'push through' changes that are still being debated. I'm happy to update the PR with recommended edits :)

@jonesor
Copy link
Owner

jonesor commented Sep 12, 2018

I will merge this pull request. I am in favour of implementing all these changes even though they may (will!) result in some backward compatibility issues. The changes could cause some headaches for workshops (take note @RobSalGo!) if we use existing materials, but since we plan on revamping the materials, and turning them into within-package vignettes I think we will cope.
Overall, the benefits of these improvements outweigh the minor headaches that might occur in my opinion.
If major problems DO emerge, then we can either roll back some specific changes, or adapt the code to cope with them perhaps. But fingers crossed that that is not necessary.

@RobSalGo
Copy link
Collaborator

dully noted and agreedo @jonesor & @patrickbarks

@jonesor jonesor merged commit 54cdbd6 into jonesor:devel Sep 12, 2018
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

Successfully merging this pull request may close these issues.

3 participants