

Dear Rusers,
I would like to calculate elasticities and sensitivities of each parameters involved in the following transition matrix:
A < matrix(c(
sigma*s0*f1, sigma*s0*f2,
s, v
), nrow=2, byrow=TRUE,dimnames=list(stage,stage))
The command "eigen.analysis" avaliable in package "popbio" provides sensibility matrix and elasticity matrix (same dimension than A). I would like to know if there is a way to calculate separetely the elasticity of sigma, s0, f1, f2, s and v ?
Thanks and regards,
privalan


> I would like to calculate elasticities and sensitivities of each parameters
> involved in the following transition matrix:
>
> A < matrix(c(
> sigma*s0*f1, sigma*s0*f2,
> s, v
> ), nrow=2, byrow=TRUE,dimnames=list(stage,stage))
>
> The command "eigen.analysis" avaliable in package "popbio" provides
> sensibility matrix and elasticity matrix (same dimension than A). I would
> like to know if there is a way to calculate separetely the elasticity of
> sigma, s0, f1, f2, s and v ?
>
If you want the eigenvalue second derivatives, check the secder and fullsecder
functions in the demogR package (also elassens for partial derivatives of the
eigenvalue elasticities). A description of that package is also found in the
recent special issue of Ecology in R in Journal of Statistical Software.
Chris
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Mon, 20071022 at 06:24 0700, privalan wrote:
> Dear Rusers,
>
> I would like to calculate elasticities and sensitivities of each parameters
> involved in the following transition matrix:
>
> A < matrix(c(
> sigma*s0*f1, sigma*s0*f2,
> s, v
> ), nrow=2, byrow=TRUE,dimnames=list(stage,stage))
>
>
> The command "eigen.analysis" avaliable in package "popbio" provides
> sensibility matrix and elasticity matrix (same dimension than A). I would
> like to know if there is a way to calculate separetely the elasticity of
> sigma, s0, f1, f2, s and v ?
You should first calculate the matrix element sensitivities, then
calculate the derivatives of the elements of your matrix with respect to
the parameter of interest. Then for each element in the matrix, the
sensitivity of the parameter is just the product of the derivative and
the appropriate element sensitivity, by the chain rule. Then add up all
the sensitivities, multiply by your parameter and divide by lambda. ie
plot(1:10, 1:10, type="n")
text(5,6, expression(e[s[0]] == over(s[0],
lambda)~sum(~over(paste(partialdiff,~lambda),paste(partialdiff,~a[ij]))
%.% over(paste(partialdiff, ~a[ij]), paste(partialdiff, ~s[0])), ij)),
cex=2)
Be aware that these elasticities will in general not sum to unity, and
cannot be interpreted as "contributions" to lambda. See Caswell (2001),
page 232.
Cheers,
Simon.
>
> Thanks and regards,
>
> privalan

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
Room 320 Goddard Building (8)
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.
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 errorchecking, 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)
x@gradient[i])), 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]]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Sorry, I didn't think carefully about your question on my first reply, so please ignore it.
Chapter 9 in Morris and Doak (2002) cover vital rate elasticities and sensitivities (see Box 9.1 for Matlab code http://www.sinauer.com/PVA/vitalsens.m). Simon, thanks for posting your code, I will add a function called vitalsens to the next release of the popbio package and output both sensitivities and elasiticities.
Here's the example for the emperor goose vital rates in chapter 9.
vl<list( Ss0=0.1357, Ss1=0.8926, Sf2=0.6388, Sf3= 0.8943)
el<expression(
0, 0, Sf2*Ss1,Sf3*Ss1,
Ss0,0, 0, 0,
0, Ss1,0, 0,
0, 0, Ss1, Ss1)
## and the matching elasticities in table 9.1
elas.var(el, vl)
$Ss0
[1] 0.0797
$Ss1
[1] 0.92
$Sf2
[1] 0.00569
$Sf3
[1] 0.074
Also, the expression el should be formatted so this command returns the projection matrix.
matrix(sapply(el, eval, vl), nrow=4, byrow=TRUE)
Thanks,
Chris
Simon Blomberg4 wrote
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 errorchecking, 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)
x@gradient[i])), 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]]
______________________________________________
Rhelp@rproject.org mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


This post has NOT been accepted by the mailing list yet.
Now I have the same question: I want to calculate the elasticity of lower level variables in matrix model.
When I tried to solve the problem using your source code, I found the "demogR" package was no longer available. Therefore, I failed.
I want to ask is there any modified source code to solve this problem.
Looking forward to hear from you.
Zhang Zhixin


This post has NOT been accepted by the mailing list yet.
Hi, Zhang Zhixin
I have same problem, but there is no answers on your question.
Maybe you already have found any solution.
If you have, please, share it here
Thanks

