Giter VIP home page Giter VIP logo

Comments (5)

RobSalGo avatar RobSalGo commented on August 24, 2024 1

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.

patrickbarks avatar patrickbarks commented on August 24, 2024

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.

RobSalGo avatar RobSalGo commented on August 24, 2024

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.

patrickbarks avatar patrickbarks commented on August 24, 2024

Well alright then! Now the challenge is to incorporate this idea into our functions (potentially including vitalRates, matrixElementPerturbation, vitalRatePerturbation, reprodStages, etc.).

from rage.

patrickbarks avatar patrickbarks commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.