Comments (5)
Hi @patrickbarks,
I agree with keeping the functionality within collapseMatrix to let the author collapse non-contiguous classes, but I also note that letting the authors re-arrange the matrices is a valuable thing per se - some times authors do not follow an ever-increasing level of comlplexity in stages from left to right, and that leads to the probabilities of retrogression being incorrectly calculated unless re-arranged
from rage.
That makes sense, I'll leave rearrangeMatrix
.
I think there are a few MPMs where inter-reproductive stages are legitimate, and appropriately ordered by the author (e.g. doi.org/10.2307/3061069), in which case moving them to the right inappropriately swaps growth and retrogression. Perhaps we can just add a warning to the documentation to this effect.
(Side note: I think there are other scenarios where the distinction between growth/retrogression is tricky, such as when an MPM includes a dormant stage, or when the MPM incorporates additional states such as sex, management status, disease status, etc. Still thinking about how to deal with some these — particularly dormancy.)
from rage.
That's a good point, but luckily a rather easy one to take care of. See what I've done here, where dorm is:
dorm <- which(compadre$matrixClass[[i]]$MatrixClassOrganized=="dorm")
one could do the same thing about seedbank dynamics as I do with going into, staying dormant and awakening from dormancy (below), but going into, staying in seedbank, and germinating from seedbank w something like:
propdorm <- which(compadre$matrixClass[[i]]$MatrixClassOrganized=="prop")
vitalRate <- function(matU, matF, matC, dorm){
matU[is.na(matU)]=0
matF[is.na(matF)]=0
matC[is.na(matC)]=0
matA=matU+matF+matC
matDim=dim(matA)[1]
dorm=dorm
out = data.frame("Survival"=NA,"Progression"=NA,"Retrogression"=NA,"Reproduction"=NA,"Clonality"=NA,"GoDorm"=NA,"StayDorm"=NA,"Awake"=NA,
"SurvivalSSD"=NA,"ProgressionSSD"=NA,"RetrogressionSSD"=NA,"ReproductionSSD"=NA,"ClonalitySSD"=NA,"GoDormSSD"=NA,"StayDormSSD"=NA,"AwakeSSD"=NA)
#Extracting SSD corrected vital rate values
SSD=eigen.analysis(matA)$stable.stage
f=colSums(matF)
out$Reproduction=mean(f)
out$ReproductionSSD=mean(f*SSD)
c=colSums(matC)
out$Clonality=mean(c)
out$ClonalitySSD=mean(c*SSD)
#Preparing survival-independent matrix to calculate survival and dormancy
uDistrib=matrix(NA,ncol=matDim,nrow=matDim)
u=colSums(matU)
out$Survival=mean(u[which(!(1:matDim)%in%dorm)])
out$SurvivalSSD=mean((u[which(!(1:matDim)%in%dorm)])*SSD[which(!(1:matDim)%in%dorm)])
if (length(dorm)>0) {
out$StayDorm=mean(u[dorm])
out$StayDormSSD=mean((u[dorm])*(SSD[dorm]))
}
#Making matrix for transitions conditional on survival
for (j in which(u>0)) uDistrib[,j]=matU[,j]/u[j]
UPrime=uDistrib
UPrime[is.na(UPrime)]=0
#Extracting proxy to individual progressive growth rate
UPrimeGrowth=UPrime
UPrimeGrowth[upper.tri(UPrime, diag = T)]=NA
UPrimeGrowth[matDim,matDim]=UPrime[matDim,matDim] #Putting back the last element of stasis bc there is likely growth on the top of class
out$Progression=mean(colSums(UPrimeGrowth,na.rm=T)[which(!(1:matDim)%in%dorm)])
out$ProgressionSSD=mean(colSums(UPrimeGrowth,na.rm=T)[which(!(1:matDim)%in%dorm)]*(SSD[which(!(1:matDim)%in%dorm)]))
#Extracting proxy to individual retrogressive growth rate
UPrimeShrinkage=UPrime
UPrimeShrinkage[lower.tri(UPrime, diag = T)]=NA
out$Retrogression=mean(colSums(UPrimeShrinkage,na.rm=T)[which(!(1:matDim)%in%dorm)])
out$RetrogressionSSD=mean((colSums(UPrimeShrinkage,na.rm=T)[which(!(1:matDim)%in%dorm)])*(SSD[which(!(1:matDim)%in%dorm)]))
if (length(dorm)>0) {
#Extracting proxy to going into dormancy
UPrimeGoDorm=UPrime
UPrimeGoDorm[upper.tri(UPrime, diag = T)]=NA
UPrimeGoDorm[matDim,matDim]=UPrime[matDim,matDim] #Putting back the last element of stasis bc there is likely growth on the top of class
out$GoDorm=mean(colSums(UPrimeGrowth,na.rm=T)[dorm])
out$GoDormSSD=mean(colSums(UPrimeGrowth,na.rm=T)[dorm]*(SSD[dorm]))
#Extracting proxy to awaking from dormancy
UPrimeAwake=UPrime
UPrimeAwake[lower.tri(UPrime, diag = T)]=NA
out$Awake=mean(colSums(UPrimeAwake,na.rm=T)[dorm])
out$AwakeSSD=mean((colSums(UPrimeAwake,na.rm=T)[dorm])*(SSD[dorm]))
}
return(out)
}
from rage.
Well alright then! Now the challenge is to incorporate this idea into our functions (potentially including vitalRates
, matrixElementPerturbation
, vitalRatePerturbation
, reprodStages
, etc.).
from rage.
In addition to converting the 'collapse' argument of collapseMatrix
to a list, I suggest we correspondingly convert the output of reprodStages
to a list, e.g.:
list(propStages = propStage,
preRepStages = preRep,
repStages = Rep,
postRepStages = postRep)
This would allow the output of reprodStages
to be directly input into collapseMatrix
.
(This idea is already suggested within reprodStages
as a #FIXME
note attributed to Rob)
from rage.
Related Issues (20)
- Add unit tests for the new life_expect functions (life_expect_mean and life_expect_var)
- Tidy up the Life History vignette ready for publication HOT 1
- Change name of vitalRates function to vital_rates for consistency HOT 1
- Clarify in relevant functions what the units are HOT 1
- Formatting of "#' @section Warning: " in d_entropy function HOT 1
- Packages in Suggests should be used conditionally HOT 2
- Fix Ternary Plots vignette (it is currently removed).
- mpm_collapse bug - NaN column in output
- Standardise life table column names and terminology HOT 1
- Standardise the default lx_crit value across functions HOT 1
- Remove dependency on popbio HOT 1
- plot_life_cycle - remove excess white space from around diagram
- Add space ("\n\n") to warnings/messages HOT 1
- Allow entropy functions to use matrices as inputs directly (rather than first having to calculate lx/mx trajectories). HOT 1
- Standardise use of matR, matF and matC.
- Allow plot_life_cycle to work with NA values?
- Add generation time calculation methods
- entropy_d is calculating the wrong formula HOT 1
- update R CMD check GitHub Actions to latest versions
- Errors in life_expect_var() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rage.