Created
April 8, 2018 14:40
-
-
Save atyre2/6630cfbc6c2d1ee9453e32dd013af555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' # Lake Ontario Cormorant matrix | |
cormorant_post_pop <- function(S = c(0.5, 0.87, 0.88, 0.89), | |
B = c(0, 0.5, 0.99), | |
F_ = c(0, 1.6, 2.4), | |
R = 0.5){ | |
A <- matrix(0, nrow=3, ncol=3) | |
A[2,1] <- S[1] | |
A[3,2:3] <- S[2:3] # ends up slightly different than pre-breeding matrix | |
A[1,] <- B*F_*S[2:4]*R | |
A | |
} | |
#' This is the **pre-breeding** matrix that Blackwell et al. calculated. Note that it doesn't match the | |
#' values given in their Table 1. Careful reading of the text and captions of Table 2 is needed to figure | |
#' out the parameters. | |
cormorant_blackwell <- function(S = c(0.5, 0.87, 0.88, 0.89), | |
B = c(0, 0.5, 0.99), | |
F_ = c(0, 1.6, 2.4), | |
R = 0.5){ | |
A <- matrix(0, nrow=3, ncol=3) | |
A[2,1] <- S[2] | |
A[3,2:3] <- S[3:4] | |
A[1,] <- B*F_*S[1] | |
A | |
} | |
A_blackwell <- cormorant_blackwell() | |
A_blackwell | |
A <- cormorant_post_pop() | |
popbio::lambda(A) | |
S <- popbio::sensitivity(A, zero=TRUE) | |
S | |
A_blackwell <- matrix(c(0, 0.2, 0.5940, | |
0.87, 0, 0, | |
0, 0.881, 0.89), nrow=3, byrow=TRUE) | |
popbio::lambda(A_blackwell) | |
#' # 4, 5 if we were interested in the effect of the sex ratio R | |
#' Calculate the matrix of *partial derivatives* with respect to R | |
#' Any element without R is 0 | |
#' Any element with R is just the other parameters | |
P <- c(0.5, 0.87, 0.88, 0.89) | |
B <- c(0, 0.5, 0.99) | |
F_ <- c(0, 1.6, 2.4) | |
R <- 0.5 | |
pd_R <- matrix(c(0, B[2]*F_[2]*P[2], B[3]*F_[3]*P[3], | |
0, 0, 0, | |
0, 0, 0), nrow = 3, ncol = 3, byrow = TRUE) | |
pd_R | |
#' Now we multiply each element here by the same element of the sensitivity matrix, and sum. | |
#' | |
sum(pd_R * S) # This is the sensitivity of lambda to changes in the sex ratio (towards more females) | |
#' Here is an example of the code to produce q 6 plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment