After a short exchange with the original questioner, I wrote the following
function to calculate the elasticities of lower level variables in population
transition matrices (Leslie matrices etc.) Perhaps it will be of use to others.
There is no error-checking, so use with care. Users should consult Caswell
(2001) for reference.
Cheers,
Simon.
# example values to construct leslie matrix
vl <- list(f1=1, f2=4, s0=.6, s=.4, v=.9, sigma=.5)
# Expressions for each matrix element
F1 <- expression(sigma*s0*f1)
F2 <- expression(sigma*s0*f2)
S <- expression(s)
V <- expression(v)
el <- c(F1, F2, S, V)
elas.var <- function (elements, varlist) {
# elements should be a vector of expressions corresponding to the elements
# of the leslie matrix, in terms of the variables in varlist
require(demogR)
res <- vector("list", length(varlist))
deriv.funcs <- sapply(elements, deriv, namevec=names(varlist),
function.arg=TRUE)
devs <- lapply(deriv.funcs, function (x) do.call(x, varlist))
leslie.mat <- matrix(as.numeric(devs), nrow=sqrt(length(elements)),
byrow=TRUE)
eig <- eigen.analysis(leslie.mat)
for (i in 1:length(varlist)) {
derivs <- matrix( as.numeric(lapply(devs, function (x)
[EMAIL PROTECTED])), nrow=sqrt(length(elements)), byrow=TRUE)
res[[i]] <- varlist[[i]]/eig$lambda1*sum(derivs*eig$sensitivities)
names(res)[i] <- names(varlist)[i]
}
res
}
# example output
> elas.var(el, vl)
$f1
[1] 0.06671376
$f2
[1] 0.2346064
$s0
[1] 0.3013201
$s
[1] 0.2346064
$v
[1] 0.4640735
$sigma
[1] 0.3013201
Simon Blomberg, BSc (Hons), PhD, MAppStat.
Lecturer and Consultant Statistician
Faculty of Biological and Chemical Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au
Policies:
1. I will NOT analyse your data for you.
2. Your deadline is your problem.
The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer can
be extracted from a given body of data. - John Tukey.
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.