Part II Stage Structured Matrix Models: Measuring the Intrinsic Rate of Increase in PopBio, R

Woohoo- I am officially done with my lab work for the population genetics study on the two biological control agents (Neochetina bruchi and N. eichhorniae) of the invasive water hyacinth. I will post a blog updating you on the how-to’s and my results soon! Finally – I am done driving back and forth to the Bay Area- and currently just working on data analysis and writing up everything here in LA. Stay tuned!

phd053104s

In the mean time…

As I promised, here is the Part II to my recent blog:  How-To: Stage-Structured Matrix Models. 

In this last blog, I discussed the importance of stage-structured matrix models in calculating the intrinsic rate of increase of organisms with developmental stages (such as the weevils!) and detailed how to construct a stage-structured matrix models in excel. Again here is that file: Julies_tutorial_example_matrix_for_popbio

So now that you have your matrix.. what do you do next?

1st: Convert your matrix into a csv file such as the one I created below based on the excel file above. Just remember- don’t include the headers or row names. I am unable to upload, so I am pasting a picture of the matrix in excel below. Screenshot 2018-01-29 11.24.16

2nd: Save this file as a csv to your working directory that you use in the R statistical program. If you haven’t used R before, then go to the R website to download the program, and refer to the below links on how to set up R, your working directory, and how to import files:

1) http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/R/R1_GettingStarted/R1_GettingStarted8.html

2) http://www.r-tutor.com/r-introduction/data-frame/data-import

Also I highly recommend downloading R studio before you start as well -makes everything a lot easier- download R studio here

3rd: Install the ‘popbio’ package. You can read about this package here.

4th: Run the below code!

#below tutorial on getting a matrix model into R and analyzing with pop bio
library(popbio)
library(popdemo)
help(popbio) #this provides more information on this package
tutorial.mm=read.table(file=”tutorial_matrix_pop_bio.csv”, sep=”,”, header=FALSE)
tutorial.mm
tutorial.L=lambda(tutorial.mm)
tutorial.L
intrinsic=log(tutorial.L)
intrinsic

#You should obtain an intrinsic rate of increase of  0.0217994

5th: If you want to analyze the stable stages, reproductive values, net reproductive rate , generation time,and conduct an eigen analysis…. Then you will also need to do the following: 

#below to get more information:
###############NEED TO FIRST LIST STAGES
stages<-c(“egg”,”1st_2nd_larvae”,”3rd_larvae”, “pupae”,”pre_rep”, “adult”)
colnames(tutorial.mm)<-stages
rownames(tutorial.mm)<-stages
tutorial.matrix=as.matrix(tutorial.mm)
tutorial.matrix
stable.stage(tutorial.matrix)
reproductive.value(tutorial.matrix)
eigen.analysis(tutorial.matrix)
fundamental.matrix(tutorial.matrix)
net.reproductive.rate(tutorial.matrix)
generation.time(tutorial.matrix)

#Congratulations! You did it!