Title: | Functions for Estimation and Inference of Selection in Age-Structured Populations |
---|---|
Description: | Provides methods for estimation and statistical inference on directional and fluctuating selection in age-structured populations. |
Authors: | Thomas Kvalnes |
Maintainer: | Thomas Kvalnes <[email protected]> |
License: | GPL-2 |
Version: | 1.2.1 |
Built: | 2024-10-31 22:14:28 UTC |
Source: | CRAN |
This R package estimates directional and fluctuating selection in age-structured populations and provides methods for statistical inference using the procedures developed by Engen et al. 2012. Also compatible with data without age-structure.
Package: | lmf |
Type: | Package |
Version: | 1.2 |
Date: | 2013-10-31 |
License: | GPL-2 |
LazyLoad: | yes |
Thomas Kvalnes, Centre for Biodiversity Dynamics, Norwegian University of Science and Technology, N-7491 Trondheim, Norway
Maintainer: Thomas Kvalnes <[email protected]>
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
Calculate the temporal mean coefficients of selection (alpha) corrected for sampling error, i.e. the best linear predictor (BLP) of alpha.
atCfn(aM, M, At, at)
atCfn(aM, M, At, at)
aM |
the estimated temporal mean selection coefficients. |
M |
the estimated temporal covariance matrix (fluctuating selection). |
At |
a list containing the named variance-covariance matrix for each year. Sorted by year. |
at |
a list containing the named vectors of the estimated selection coefficient for each year. Sorted by year. |
Further details are found in Engen et al. 2012.
Returns a vector with the named best linear predictors for the temporal mean coefficients of selection (alpha).
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract aM, M, At and at aM <- lmf.1$aM M <- lmf.1$M At <- lmf.1$At at <- lmf.1$at #Calculate Best Linear Predictor (BLP) atCfn(aM = aM, M = M, At = At, at = at)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract aM, M, At and at aM <- lmf.1$aM M <- lmf.1$M At <- lmf.1$At at <- lmf.1$at #Calculate Best Linear Predictor (BLP) atCfn(aM = aM, M = M, At = At, at = at)
Generates bootstrap replicates of the estimated parameters in a "lmf" model. Ordinary bootstrap is performed for the projection matrix, while both parametric and ordinary (non-parametric) resampling is available for the remaining parameters in the model. In addition, bootstrapping under any choosen null hypothesis is available for hypothesis testing.
boot.lmf(object, nboot = 1000, what = c("projection", "alpha", "H0", "all"), asim = c("ordinary", "parametric"), sig.dj = TRUE, H0exp = list(alpha = NULL, M = NULL), H0con = c("fs", "nfs", "ds", "nds"), method = c("BFGS"), control = list(maxit = 500, reltol = sqrt(.Machine$double.eps)), ...)
boot.lmf(object, nboot = 1000, what = c("projection", "alpha", "H0", "all"), asim = c("ordinary", "parametric"), sig.dj = TRUE, H0exp = list(alpha = NULL, M = NULL), H0con = c("fs", "nfs", "ds", "nds"), method = c("BFGS"), control = list(maxit = 500, reltol = sqrt(.Machine$double.eps)), ...)
object |
a fitted object of of class "lmf". |
nboot |
the number og bootstraps desired. |
what |
which set of parameters to bootstrap. Options are "projection" to
only resample projection matrix, growth rate |
asim |
the type of bootstrap for the parameters other than the projection matrix (which is always ordinary bootstrapped). Options are "parametric" (default) and "ordinary". |
sig.dj |
logical, |
H0exp |
a list with the first element a vector containing the expected temproal mean coefficients of selection (alpha) and the second element a matrix containing the elements of the expected temporal variance-covariance matrix (M) under the null hypothesis. This argument needs to be specified to perform hypothesis testing. |
H0con |
the conditions under which the null hypothesis should be tested. Options are "fs" to assume fluctuating selection, "nfs" to assume no fluctuating selection, "ds" to assume directional selection and "nds" to assume no directional selection. "nds" is not implemented due to increased risk of Type I error if the assumption is not correct, but is included here for completeness. |
method |
defines what optimalization algorithm to be used in the
maximization of the loglikelihood. Alternatives are: "Nelder-Mead",
"BFGS" (default), "CG", "L-BFGS-B" and "SANN". Not all are applicable here.
See |
control |
a list of control parameters for the maximization of the
likelihood. |
... |
additional arguments to be passed to optim for the maximization
of the loglikelihood. See |
The resampling procedures preserve the observed ratios of the different age classes during resampling of the projection matrix.
Ordinary bootstrap will often be subject to bias due to few years of data in most available data sets within biology (generally << 40), thus the parametric bootstrap is recomended for most purposes.
The bootstrap procedure is closely associated with the method deployed in
lmf
and further details can be found in Engen et al. 2012.
Different from Engen et al. 2012, the sigma2.dj is defined as independent gamma
distributed variables with shape = and
rate =
. Where X =
and
using the mean and variance from in the paper.
boot.lmf
returns a object of class "boot.lmf".
The function summary
is used to obtain and
print a summary of the bootstrap replicates and to print results from tests of
hypotheses. For construction of confidene intervals for the parameters the
function ci.boot.lmf
is used.
An object of class "boot.lmf" is a list containing at most the following components:
running.time |
the total time used for computation. |
optim.time |
the time used for maximation of the loglikelihood. |
call |
the matched call. |
asim |
the value specified of asim. |
nboot |
the number of bootstrap replicates generated. |
uage |
the unique age classes in the data set. |
nage |
the number of unique age classes in the data set. |
npar |
the number of parameters in the model. |
uyear |
the unique years in the data set. |
nyear |
the number of unique years in the data set. |
l |
the estimated projection matrix. |
lboot |
the bootstrap replicates of the projection matrix. |
lambda |
the deterministic multiplicative growth rate of the population. |
u |
the stable age distribution. |
v |
the vector of reproductive values for each age class. |
luvboot |
the bootstrap replicates of |
sigma2.dj |
a list containing the demographic variance for each age class. Sorted by age class. |
djboot |
the bootstrap replicates of |
sigma2.d |
the total demographic variance of the population. |
dboot |
the bootstrap replicates of |
Atboot |
the bootstrap replicates of the yearly variance-covariance
matrices. The unscaled variance-covariance matrices are kept constant, but
each set of yearly estimates are scaled by the bootstrapped |
atboot |
the bootstrap replicates of the yearly coefficients of selection. This can be performed "parametric"(default) or "ordinary". |
M |
the estimated temporal covariance matrix (fluctuating selection). |
aM |
the estimated temporal mean coefficients of selection. |
Mboot |
the bootstrap replicates of |
aMboot |
the bootstrap replicates of |
atCboot |
the bootstrap replicates of the best linear predictor for the estimated yearly coefficients of selection (i.e. corrected for sampling errors). |
Anf |
the estimated temporal covariance matrix assuming no fluctuating selection. |
anf |
the estimated temporal mean selection coefficients assuming no fluctuating selection. |
Anfboot |
the bootstrap replicates of |
anfboot |
the bootstrap replicates of |
sigma2.e |
the environmental variance of the population. |
eboot |
the bootstrap replicates of |
eCboot |
the bootstrap replicates of |
H0aMboot |
the bootstrap replicates of |
H0anfboot |
the bootstrap replicates of |
H0atnfboot |
the bootstrap replicates of |
H0Mnfboot |
the bootstrap replicates of |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Print b.1 #Summary summary(b.1) #View density plots plot(b.1) #Test of hypoteses b.2 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "H0", H0exp = list(rep(0, 3), matrix(0, ncol = 3, nrow = 3)), asim = "parametric") #Summary summary(b.2)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Print b.1 #Summary summary(b.1) #View density plots plot(b.1) #Test of hypoteses b.2 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "H0", H0exp = list(rep(0, 3), matrix(0, ncol = 3, nrow = 3)), asim = "parametric") #Summary summary(b.2)
Constructs confidence intervals (CIs) for the bootstrapped parameters in an object of class "boot.lmf".
ci.boot.lmf(x, clevel = 0.05)
ci.boot.lmf(x, clevel = 0.05)
x |
an object of class "boot.lmf". |
clevel |
the confidence level required. |
ci.boot.lmf
construct confidence intervals (CIs) from the quantiles of the
bootstrap replicates and uses the function quantile
.
See Engen et al. 2012 for details on the method for estimating and bootstrapping the parameters.
ci.boot.lmf
returns a list containing the following components:
call |
the matched call. |
nboot |
the number of bootstrap replicates generated. |
what |
which set of parameters which has been to bootstrapped. See
|
clevel |
the confidence level specified. |
uage |
the unique age classes in the data set. |
nage |
the number of unique age classes in the data set. |
l |
CI for the projection matrix. |
luv |
CI for |
sigma2.dj |
CI for the demographic variance for each age class. |
sigma2.d |
CI for the total demographic variance |
M |
CI for the estimated temporal covariance matrix. |
aM |
CI for the estimated temporal mean coefficients of selection |
sigma2.e |
CI for the environmental variance |
Anf |
CI for the estimated temporal covariance matrix assuming no fluctuating selection. |
anf |
CI for the estimated temporal mean selection coefficients assuming no fluctuating selection. |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Generate CI ci.boot.lmf(b.1)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Generate CI ci.boot.lmf(b.1)
Calculates the deterministic multiplicative growth rate (lambda), the stable age distribution (u) and the reproductive values (v) from a given projection matrix.
eigenl(pm)
eigenl(pm)
pm |
a projection matrix. For instance, the output from the function |
Given a projection matrix (l), this function calculates the real dominant eigenvalue (lambda), and the left (u) and right (v) eigenvectors, defined by l*u = lambda*u and v*l = lambda*v.
eigenl
returns a list containing the following components:
lambda |
the deterministic multiplicative growth rate of the population from which the projection matrix was estimated |
u |
the stable age distribution of the population from which the projection matrix was estimated |
u |
the reproductive values of the population from which the projection matrix was estimated |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #The uniue age classes unique.age <- unique(sparrowdata$age) #Estimate the projection matrix pro.comp <- procomp(a = sparrowdata, uage = unique.age) projection.matrix <- promat(pc = pro.comp, nage = length(unique.age)) #Estimate lambda, u and v eigenl(pm = projection.matrix)
#Data set from Engen et al. 2012 data(sparrowdata) #The uniue age classes unique.age <- unique(sparrowdata$age) #Estimate the projection matrix pro.comp <- procomp(a = sparrowdata, uage = unique.age) projection.matrix <- promat(pc = pro.comp, nage = length(unique.age)) #Estimate lambda, u and v eigenl(pm = projection.matrix)
fs
is a function which estimates the temporal covariance matrix (i.e.
fluctuating selection) and the temporal mean alpha coefficients (i.e. directional
selection) through a numerical maximization of a loglikelihood function.
fs(At, at, npar, nyear, method, control, ...)
fs(At, at, npar, nyear, method, control, ...)
At |
a list containing the named yearly variance-covariance matrices. Sorted by year. |
at |
a list containing the named yearly vectors of the estimated selection coefficients. Sorted by year. |
npar |
the number of parameters in the model for the estimates selection coefficients. |
nyear |
the number of years with estimates of selection. |
method |
defines what optimalization algorithm to be used in the maximization of the
loglikelihood. Alternatives are: "Nelder-Mead", "BFGS" (default), "CG",
"L-BFGS-B" and "SANN". Not all are applicable here. See |
control |
a list of control parameters for the maximization of the likelihood.
|
... |
additional arguments to be passed to optim for the maximization of the
loglikelihood. See |
fs
is used internally in lmf
when estimating temporal coefficients
of selection, but given the right data can be executed as a standalone. The input
to the arguments At and at are estimated within lmf
by correctly combining
estimates of coefficients and variance-covariance within each age class and year
to a estimate for each year.
fs
used optim
for the numerical maximization of the
log likelihood function lnL.M
. Problems of non-positive definite matrices
appearing as maximas, due to numerical rounding, are solved with nearPD
,
which implement the smallest possible numerical changes of some componets of the
matrices to achive positive definiteness. These changes does not affect the
results in any significant way.
Engen et al. 2012 describe the maximum likelihood method in details.
fs
returns a list containing the following components:
convergence |
"yes" indicates that the numerical maximation of the
likelihood successfully converged before reaching the iteration limit |
iterations |
the number of iterations of the function in the numerical maximation of the likelihood. |
M |
the estimated temporal covariance matrix (fluctuating selection). |
aM |
the estimated temporal mean selection coefficients. |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate temporal selection coefficients flusel <- fs(At = At, at = at, npar = 3, nyear = 7, method = "BFGS", control = list(maxit = 500, reltol = sqrt(.Machine$double.eps))) #View output str(flusel) flusel
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate temporal selection coefficients flusel <- fs(At = At, at = at, npar = 3, nyear = 7, method = "BFGS", control = list(maxit = 500, reltol = sqrt(.Machine$double.eps))) #View output str(flusel) flusel
Calculates the inverse of a symmetric positive definite matrix from its Cholesky composition.
inv(a)
inv(a)
a |
a symmetric positive definite matrix |
This is an interface to the LAPACK routine DPOTRI implemented in the function
chol2inv
. The function calculates cholesky decomposition of the given
matrix and inputs this into chol2inv
.
The inverse of the given matrix.
Thomas Kvalnes
Anderson. E. et al. 1999. LAPACK Users' Guide. Third Edition. SIAM [Available online at: http://www.netlib.org/lapack/lug/lapack_lug.html].
#Example matrix mat <- matrix(c(1, 0.5, -3, 0.5, 3, 0.5, -3, 0.5, 12), ncol = 3) #Show that it is positive definite eigen(mat)$values #Calculate inverse inv(mat)
#Example matrix mat <- matrix(c(1, 0.5, -3, 0.5, 3, 0.5, -3, 0.5, 12), ncol = 3) #Show that it is positive definite eigen(mat)$values #Calculate inverse inv(mat)
lm.extract
fit a linear model and extract coefficients,
unscaled covariance matrix, residual variance, fitted values, residuals, degrees of freedom, and
leverage and cook's distance for each data point.
lm.extract(formula, data, na.action = na.exclude)
lm.extract(formula, data, na.action = na.exclude)
formula |
an object of class "formula" (or one that can be coerced to that class): a
symbolic description of the model to be fitted on the format |
data |
a data set containing the variables in the model. |
na.action |
a function which indicate what should happend when the data contain NAs. The
default is |
lm.extract
works through calls to lm
, residuals
, predict
,
df.residuals
, deviance
, vcov
, lm.influence
and cooks.distance
.
Consult these functions for further details. The function was written for internal
use with lmf
, but can be executed as a standalone.
lm.extract
returns a list containing the following components:
ajt |
a named vector of coefficients |
res |
the residuals |
fit |
the fitted values |
dof |
the degrees of freedom |
sigma.djt |
the residual standard error |
Ajt.us |
a named unscaled variance-covariance matrix |
leverage |
the estimated leverage for each data point. I.e. a vector
containing the diagonal of the 'hat' matrix (see |
cook |
the estimated Cook's distance for each data point (see |
Thomas Kvalnes
#Simulated data xx <- rnorm(n = 100, mean = 10, sd = 2) yy <- xx + 10 + rnorm(n = 100, 0, 2) #Extract linear model components extract <- lm.extract(formula = yy ~ xx, data = data.frame(xx = xx, yy = yy)) str(extract) #Plot the xx-yy relation plot(xx, yy) abline(a = extract$ajt[1], b = extract$ajt[2])
#Simulated data xx <- rnorm(n = 100, mean = 10, sd = 2) yy <- xx + 10 + rnorm(n = 100, 0, 2) #Extract linear model components extract <- lm.extract(formula = yy ~ xx, data = data.frame(xx = xx, yy = yy)) str(extract) #Plot the xx-yy relation plot(xx, yy) abline(a = extract$ajt[1], b = extract$ajt[2])
lmf
fit linear models within each combination of year and age class and
estimates coefficients of selection using maximum likelihood procedures.
lmf
is compatible with populations without age-structure.
lmf(formula, age, year, data, na.action = na.exclude, method = c("BFGS"), control = list(maxit = 500, reltol = sqrt(.Machine$double.eps)), ...)
lmf(formula, age, year, data, na.action = na.exclude, method = c("BFGS"), control = list(maxit = 500, reltol = sqrt(.Machine$double.eps)), ...)
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted when estimating coefficients of selection. Format: response ~ terms. The detail of model specification are given under 'Details'. |
age |
used to define the name of the age column in the data set. Use NULL if no age data are available in the data set. |
year |
used to define the name of the year column in the data set. |
data |
data set with individual ids (optional), year of reproduction (year), maternal age (age; may be omitted if a model without age is desired), number of female offspring (recruits), survival to the next reproductive event (survival) and phenotypic measurements. Age classes should have a natural order of increasing age. E.g. 1, 2, 3, ... |
na.action |
a function which indicate what should happend when the data contain NAs. The
default is |
method |
defines what optimalization algorithm to be used in the maximization of the
loglikelihood. Alternatives are: "Nelder-Mead", "BFGS" (default), "CG",
"L-BFGS-B" and "SANN". Not all are applicable here. See |
control |
a list of control parameters for the maximization of the likelihood.
|
... |
additional arguments to be passed to optim for the maximization of the
loglikelihood. See |
lmf
use formulas for model specification. These should be formatted as
decribed under arguments. Note however that your response should be specified
as a two-column matrix with the columns recruits and survival. The first column
should give the number of recruits that an individual produced a given year and
the second column should contain information on whether the individual survived
or not (1 or 0) to the next breeding season. These two columns will be used to
calculate the individual reproductive values (Wj) which the model will substitute
for the response in the age and year specific linear regressions
(i.e. Wj ~ terms
).
lmf
returns an object of class "lmf".
The function summary
is used to obtain and
print a summary of the results. For construction of confidene intervals or
perform statistical inference on the parameters the function boot.lmf
is used.
An object of class "lmf" is a list containing the following components:
running.time |
the total time used for computation. |
optim.time |
the time used for maximation of the loglikelihood. |
call |
the matched call. |
npar |
the number of parameters in the model. |
uage |
the unique age classes in the data set. |
nage |
the number of unique age classes in the data set. |
maxage |
the final age class. |
l |
the estimated projection matrix. |
lambda |
the deterministic multiplicative growth rate of the population. |
u |
the stable age distribution. |
v |
the vector of reproductive values for each age class. |
uyear |
the unique years in the data set. |
nyear |
the number of unique years in the data set. |
nobs |
the number of observations (counting individual-year). |
nobs.age |
the number of observations per age class. |
indnr |
assigned individual numbers (1:nobs). |
ajt |
a list containing the named vectors of the estimated selection coefficient for each age class within each year. Sorted by age class and year. |
Ajt.us |
a list containing the named unscaled variance-covariance matrix for each age class within each year. Sorted by age class and year. |
sigma.djt |
a list containing the vectors of residual standard errors from the linear regression for each age class within each year. Sorted by age class and year. |
dof |
a list containing the vectors of degrees of freedom (dof) from the linear regression for each age class within each year. Sorted by age class and year. |
res |
a list containing the vectors of residuals from the linear regression for each age class within each year. Sorted by age class and year. |
fit |
a list containing the vectors of fitted values from the linear regression for each age class within each year. Sorted by age class and year. |
leverage |
a list containing the vectors of estimated leverage for each
data point from the linear regression for each age class within each year
(see |
cook |
a list containing the vectors of estimated Cook's distance for each
data point from the linear regression for each age class within each year
(see |
sigma2.dj |
a list containing the demographic variance for each age class. Sorted by age class. |
sigma2.dj.dof |
a list containing the degrees of freedom (dof) for the demographic variance for each age class. Sorted by age class. |
sigma2.dj.sd |
a list containing the standard deviation (sd) for the demographic variance for each age class. Sorted by age class. |
sigma2.d |
the total demographic variance of the population. |
sigma2.d.dof |
the degrees of freedom (dof) for the total demographic variance of the population. |
sigma2.d.sd |
the standard deviation (sd) for the total demographic variance of the population. |
Ajt |
a list containing the named variance-covariance matrix (scaled by sigma2.dj) for each age class within each year. Sorted by age class and year. |
at |
a list containing the named vectors of the estimated selection coefficient for each year. Sorted by year. |
At |
a list containing the named variance-covariance matrix (scaled by sigma2.dj) for each year. Sorted by year. |
convergence |
"yes" indicates that the numerical maximation of the
likelihood successfully converged before reaching the iteration limit |
iterations |
the number of iterations of the function in the numerical maximation of the likelihood. |
M |
the estimated temporal covariance matrix (fluctuating selection). |
aM |
the estimated temporal mean selection coefficients. |
atC |
the best linear predictor for the estimated yearly selection coefficients (i.e. corrected for sampling errors). |
Anf |
the estimated temporal covariance matrix assuming no fluctuating selection. |
anf |
the estimated temporal mean selection coefficients assuming no fluctuating selection. |
sigma2.e |
the environmental variance of the population. |
data.set |
the data set used in the analyses with a column of individual reproductive values addad |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
procomp
, promat
, eigenl
,
lm.extract
, fs
, atCfn
,
nfs
, boot.lmf
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #View diagnostic plots plot(lmf.1) #View output print(lmf.1) #Print summary summary(lmf.1)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #View diagnostic plots plot(lmf.1) #View output print(lmf.1) #Print summary summary(lmf.1)
lnL.M
calculates the loglikelihood of the maximum likelihood function for
temporal coefficients of selection from Engen et al. 2012. Returns the estimate
of alpha for a given temporal variance-covariance matrix (M) if desired.
lnL.M(D, At, at, npar, ret.alphas = FALSE)
lnL.M(D, At, at, npar, ret.alphas = FALSE)
D |
a vector with the non-zero elements of the upper triangular matrix of the Cholesky decomposition of a temporal variance-covariance matrix M. |
At |
a list containing the named yearly variance-covariance matrices. Sorted by year. |
at |
a list containing the named yearly vectors of the estimated selection coefficients. Sorted by year. |
npar |
the number of parameters in the model for the estimates selection coefficients. |
ret.alphas |
logical. If TRUE the function returns the vector with the estimates of the temporal mean selection coefficients (alpha) for the given temporal variance-covariance matrix M. FALSE (default) makes the function return the loglikelihood for the given M. |
The function was developed for internal use in fs
, but can be applied as
a standalone.
The upper triangular matrix (D) of the Cholesky decomposition of M is defined
as M = t(D)%*%D
.
Details of the method is provided in Engen et al. 2012.
lnL.M
returns the loglikelihood estimate (for ret.alpha = FALSE
)
or the temporal mean selection coefficients (for ret.alpha = TRUE
) for a
given temporal variance-covariance matrix M.
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate D D <- as.vector(chol((Reduce('+', At) / length(At)))) D <- D[D != 0] #Estimate loglikelihood lnL.M(D = D, At = At, at = at, npar = 3, ret.alphas = FALSE) #Estimate temporal mean selection coefficients lnL.M(D = D, At = At, at = at, npar = 3, ret.alphas = TRUE)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate D D <- as.vector(chol((Reduce('+', At) / length(At)))) D <- D[D != 0] #Estimate loglikelihood lnL.M(D = D, At = At, at = at, npar = 3, ret.alphas = FALSE) #Estimate temporal mean selection coefficients lnL.M(D = D, At = At, at = at, npar = 3, ret.alphas = TRUE)
Compute the nearest positive definite matrix to an approximate one, typically a correlation or variance-covariance matrix.
nearPD(x, corr = FALSE, keepDiag = FALSE, do2eigen = TRUE, doSym = FALSE, doDykstra = TRUE, only.values = FALSE, only.matrix = TRUE, eig.tol = 1e-06, conv.tol = 1e-07, posd.tol = 1e-08, maxit = 100, trace = FALSE)
nearPD(x, corr = FALSE, keepDiag = FALSE, do2eigen = TRUE, doSym = FALSE, doDykstra = TRUE, only.values = FALSE, only.matrix = TRUE, eig.tol = 1e-06, conv.tol = 1e-07, posd.tol = 1e-08, maxit = 100, trace = FALSE)
x |
numeric n * n approximately positive definite matrix, typically an approximation to a correlation or covariance matrix. |
corr |
logical indicating if the matrix should be a correlation matrix. |
keepDiag |
logical, generalizing |
do2eigen |
logical indicating if a |
doSym |
logical indicating if |
doDykstra |
logical indicating if Dykstra's correction should be used;
true by default. If false, the algorithm is basically the direct fixpoint
iteration |
only.values |
logical; if |
only.matrix |
logical indicating if only the matrix should be returned. |
eig.tol |
defines relative positiveness of eigenvalues compared to
largest one, |
conv.tol |
convergence tolerance for Higham algorithm. |
posd.tol |
tolerance for enforcing positive definiteness (in the
final |
maxit |
maximum number of iterations allowed. |
trace |
logical or integer specifying if convergence monitoring should be traced. |
This function is identical to nearPD
in package Matrix as
far as the algorithmic method is concerned, but has an addition of the argument
only.matrix
to ease its application within the function fs
,
has lost the argument ensureSymmetry
and have a small change in the
list returned when only.matrix = FALSE
.
Please see nearPD
in package Matrix for further details.
nearPD
returns a numeric vector of eigen values of
the approximating matrix if only.values = TRUE
, returns the computed
positive definite matrix if only.matrix = TRUE
and else returns a list
with the following componets:
mat |
matrix of class "dpoMatrix", the computed positive-definite matrix. |
eigenvalues |
numeric vector of eigenvalues of |
corr |
logical, just the argument |
normF |
the Frobenius norm ( |
iterations |
number of iterations needed. |
converged |
logical indicating if iterations converged. |
Jens Oehlschlaegel donated a first version. Subsequent changes by the Matrix package authors and present modifications by Thomas Kvalnes.
Cheng, S.H. and Higham, N. 1998. A Modified Cholesky Algorithm Based on a Symmetric Indefinite Factorization. SIAM Journal on Matrix Analysis and Applications, 19, 1097-1110.
Knol, D.L. and ten Berge, J.M.F. 1989. Least-squares approximation of an improper correlation matrix by a proper one. Psychometrika, 54, 53-61.
Higham, N. 2002. Computing the nearest correlation matrix - a problem from finance. IMA Journal of Numerical Analysis, 22, 329-343.
#Simulated non-positive definite (PD) matrix nonPD <- matrix(c(2.04e-03, 3.54e-05, 7.52e-03, 3.54e-05, 6.15e-07, 1.30e-04, 7.52e-03, 1.30e-04, 2.76e-02), ncol = 3) #View eigenvalues (PD = only positive eigenvalues) eigen(nonPD) #Calculate PD matrix PD <- nearPD(nonPD, only.matrix = TRUE) PD #View eigenvalues eigen(PD) #More thorough examples are given in the help pages for nearPD #in the Matrix package.
#Simulated non-positive definite (PD) matrix nonPD <- matrix(c(2.04e-03, 3.54e-05, 7.52e-03, 3.54e-05, 6.15e-07, 1.30e-04, 7.52e-03, 1.30e-04, 2.76e-02), ncol = 3) #View eigenvalues (PD = only positive eigenvalues) eigen(nonPD) #Calculate PD matrix PD <- nearPD(nonPD, only.matrix = TRUE) PD #View eigenvalues eigen(PD) #More thorough examples are given in the help pages for nearPD #in the Matrix package.
nfs
is a function which estimates the temporal covariance matrix
and the temporal mean alpha coefficients (i.e. directional
selection) under the assumption of no fluctuating selection.
nfs(At, at, npar, nyear)
nfs(At, at, npar, nyear)
At |
a list containing the named yearly variance-covariance matrices. Sorted by year. |
at |
a list containing the named yearly vectors of the estimated selection coefficients. Sorted by year. |
npar |
the number of parameters in the model for the estimates selection coefficients. |
nyear |
the number of years with estimates of selection. |
nfs
is used internally in lmf
when estimating temporal mean
coefficients of selection under the assumption of no fluctuating selection, but
given the right data can be executed as a standalone. The input to the
arguments At and at are estimated within lmf
by correctly combining
estimates of coefficients and variance-covariance within each age class and year
to a estimate for each year.
Engen et al. 2012 describe the method in details.
nfs
returns a list containing the following components:
Anf |
the estimated temporal covariance matrix under the assumption of no flucutating selection. |
anf |
the estimated temporal mean selection coefficients under the assumption of no fluctuating selection. |
Thomas Kvalnes
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate temporal selection coefficients under the assumption of no #fluctuating selection noflusel <- nfs(At = At, at = at, npar = 3, nyear = 7) #View output str(noflusel) noflusel
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Extract At and at At <- lmf.1$At at <- lmf.1$at #Estimate temporal selection coefficients under the assumption of no #fluctuating selection noflusel <- nfs(At = At, at = at, npar = 3, nyear = 7) #View output str(noflusel) noflusel
Plots density plots for bootstrap replicates of parameters from objects of class "lmf".
## S3 method for class 'boot.lmf' ## S3 method for class 'boot.lmf' plot(x, what = c("all"), ...)
## S3 method for class 'boot.lmf' ## S3 method for class 'boot.lmf' plot(x, what = c("all"), ...)
x |
an object of class "boot.lmf". |
what |
what parameters is to be plotted. Options are "projection", "alpha" and "all". |
... |
additional arguments to be passed to methods, such as
graphical parameters (see |
Density of parameters is calculated using the function density
.
Thomas Kvalnes
boot.lmf
, density
, plot.default
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Density plot plot(b.1)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Density plot plot(b.1)
Plots four diagnostic plots for objects of class "lmf": a plot of residuals against fitted values, a Normal Q-Q plot, a Scale-Location plot of the square root of standardized residuals against fitted values and a plot of standardized residuals against leverage with indications of cooks distance.
## S3 method for class 'lmf' ## S3 method for class 'lmf' plot(x, what = "total", ...)
## S3 method for class 'lmf' ## S3 method for class 'lmf' plot(x, what = "total", ...)
x |
an object of class "lmf". |
what |
the part of the model for which diagnostic plots should be generated. Options are 'total' (default) for the overall plots and 'age-year' for plots for each separate linear regression for each age within each year. |
... |
additional arguments to be passed through to plotting functions. |
The function is constructed partly from modifications of script
from the plot.lm
function in package stats. See ?plot.lm
for details on the plots provided.
Thomas Kvalnes
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Diagnostic plots across all age classes and years par(mfrow = c(2, 2)) plot(lmf.1) #Diagnostic plots for each age class within each year (the #actual linear regressions) par(mfrow = c(2, 2)) plot(lmf.1, what = "age-year")
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Diagnostic plots across all age classes and years par(mfrow = c(2, 2)) plot(lmf.1) #Diagnostic plots for each age class within each year (the #actual linear regressions) par(mfrow = c(2, 2)) plot(lmf.1, what = "age-year")
Estimates the components of the projection matrix and constructs the matrix given data on fecundity and survival in a age-structured population.
procomp(a, uage) promat(pc, nage)
procomp(a, uage) promat(pc, nage)
a |
a data set with fecundity and survival of individuals with known age over several years. Each individual can be represented once a year. |
uage |
the unique age classes in the data set. |
pc |
a matrix with columns age, fecundity and survival, i.e. the output from
running the function |
nage |
the number of unique age classes in the data set. |
This function was made for internal use in lmf
, but can be applied as a
standalone.
The data set needs to contain the columns recruits (number of female offspring), survival (1 if the individual survives to the next reproductive event and 0 if it dies) and age.
The contruction of the projection matrix is divided into two functions for ease of storing and handling the estimates.
procomp
returns a matrix with the components of the projection matrix having
columns age, fecundity and survival, while promat
takes the output from
procomp
and returns the projection matrix.
Thomas Kvalnes
Caswell, H. 2000. Matrix Population Models, 2nd edn. Sinauer, Sunderland, Massachusetts. Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #The uniue age classes unique.age <- unique(sparrowdata$age) #Estimate the components of the projection matrix projection.components <- procomp(a = sparrowdata, uage = unique.age) #View components projection.components #Set up the projection matrix promat(pc = projection.components, nage = length(unique.age))
#Data set from Engen et al. 2012 data(sparrowdata) #The uniue age classes unique.age <- unique(sparrowdata$age) #Estimate the components of the projection matrix projection.components <- procomp(a = sparrowdata, uage = unique.age) #View components projection.components #Set up the projection matrix promat(pc = projection.components, nage = length(unique.age))
rmnorm
generate random numbers from a multivariate normal distribution.
rmnorm(n = 1, mean = rep(0, d), varcov)
rmnorm(n = 1, mean = rep(0, d), varcov)
n |
the number of random vectors to be generated. |
mean |
a vector with means of length d. |
varcov |
a variance-covariance matrix with dimentions d * d. |
This is a modification of the function rmnorm
provided in mnormt.
The function works around problems of non-positive definite
variance-covariance matrices due to numerical rounding by use of the
function nearPD
. Furthermore, when only a single random vector
is generated, the function now returns a named random vector with names
inherited from the colum names of the variance-covariance matrix.
For n > 1 rmnorm
returns a matrix of n
rows of random vectors,
while for n = 1 rmnorm
returns a named random vector.
Fortran code of SADMVN and most auxiliary functions by Alan Genz, some additional auxiliary functions by people referred to within his program. Porting to R and additional R code by Adelchi Azzalini, with current modifications by Thomas Kvalnes.
Genz, A. 1992. Numerical Computation of Multivariate Normal Probabilities. Journal of Computational and Graphical Statiststics, 1, 141-149.
Genz, A. 1993. Comparison of methods for the computation of multivariate normal probabilities. Computing Science and Statistics, 25, 400-405.
Genz, A.: Fortran code available at http://www.math.wsu.edu/math/faculty/genz/software/fort77/mvn.f
#Variance-covariance matrix varcov <- matrix(c(2.047737e-03, 3.540039e-05, 0.0075178920, 3.540039e-05, 6.122832e-07, 0.0001299661, 7.517892e-03, 1.299661e-04, 0.0276005740), ncol = 3) #Set names nam <- c("a", "b", "c") dimnames(varcov) <- list(nam, nam) #Check positive definiteness (all positive eigenvalues = positive definite) eigen(varcov) $values #Mean mean <- c(1, 0.3, 0.5) #Generate n = 1 random vector rmnorm(n = 1, mean = mean, varcov = varcov) #Generate n = 10 random vectors rmnorm(n = 10, mean = mean, varcov = varcov) #Generate n = 1 random vectors when varcov is non-positive definite #Non-positive definite varcov matrix varcov2 <- matrix(c(2.04e-03, 3.54e-05, 7.52e-03, 3.54e-05, 6.15e-07, 1.30e-04, 7.52e-03, 1.30e-04, 2.76e-02), ncol = 3) dimnames(varcov2) <- dimnames(varcov) eigen(varcov2) #Random vector rmnorm(n = 1, mean = mean, varcov = varcov2)
#Variance-covariance matrix varcov <- matrix(c(2.047737e-03, 3.540039e-05, 0.0075178920, 3.540039e-05, 6.122832e-07, 0.0001299661, 7.517892e-03, 1.299661e-04, 0.0276005740), ncol = 3) #Set names nam <- c("a", "b", "c") dimnames(varcov) <- list(nam, nam) #Check positive definiteness (all positive eigenvalues = positive definite) eigen(varcov) $values #Mean mean <- c(1, 0.3, 0.5) #Generate n = 1 random vector rmnorm(n = 1, mean = mean, varcov = varcov) #Generate n = 10 random vectors rmnorm(n = 10, mean = mean, varcov = varcov) #Generate n = 1 random vectors when varcov is non-positive definite #Non-positive definite varcov matrix varcov2 <- matrix(c(2.04e-03, 3.54e-05, 7.52e-03, 3.54e-05, 6.15e-07, 1.30e-04, 7.52e-03, 1.30e-04, 2.76e-02), ncol = 3) dimnames(varcov2) <- dimnames(varcov) eigen(varcov2) #Random vector rmnorm(n = 1, mean = mean, varcov = varcov2)
Calculates the standard error of the values in x
se(x, na.rm = FALSE)
se(x, na.rm = FALSE)
x |
a numeric vector. |
na.rm |
a logical value indicating whether |
The standard error of a length one vector is NA
and if x
is not
a vector an error will be printed.
The standard error is defined as:
The standard error of x
is returned.
Thomas Kvalnes
#The standard error of samples with the same mean and standard deviation, but #of different sizes. se(rnorm(n = 10, mean = 5, sd = 1)) se(rnorm(n = 100, mean = 5, sd = 1)) se(rnorm(n = 1000, mean = 5, sd = 1)) se(rnorm(n = 10000, mean = 5, sd = 1))
#The standard error of samples with the same mean and standard deviation, but #of different sizes. se(rnorm(n = 10, mean = 5, sd = 1)) se(rnorm(n = 100, mean = 5, sd = 1)) se(rnorm(n = 1000, mean = 5, sd = 1)) se(rnorm(n = 10000, mean = 5, sd = 1))
A data set on a wild population of house sparrow Passer domesticus.
data(sparrowdata)
data(sparrowdata)
A data frame with 116 observations on the following 7 variables.
id
unique individual identifier
year
the year of breeding
age
the age of the individual
survival
equals 1 if the individual survives, otherwise 0
recruits
the number of recruits produced, i.e. offspring that survives to the next breeding season
weight
the body mass of the individuals at fledgling, i.e. when the bird was ready to leave the nest
tars
the tarsus length of the individuals at fledgling, i.e. when the bird was ready to leave the nest
Further details on the data set is provided by Engen et al. 2012.
Engen, S., Saether, B.-E., Kvalnes, T. and Jensen, H. 2012. Estimating fluctuating selection in age-structured populations. Journal of Evolutionary Biology, 25, 1487-1499.
#Data set from Engen et al. 2012 data(sparrowdata) #View data str(sparrowdata) head(sparrowdata, 10)
#Data set from Engen et al. 2012 data(sparrowdata) #View data str(sparrowdata) head(sparrowdata, 10)
summary
method for class "boot.lmf".
## S3 method for class 'boot.lmf' summary(object, ret.bootstraps = FALSE, ...) ## S3 method for class 'summary.boot.lmf' print(x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...)
## S3 method for class 'boot.lmf' summary(object, ret.bootstraps = FALSE, ...) ## S3 method for class 'summary.boot.lmf' print(x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...)
object |
an object of class "boot.lmf". empty |
ret.bootstraps |
logical. If |
x |
an object of class "summary.boot.lmf". empty |
digits |
the number of significant digits to use when printing. empty |
signif.stars |
logical. If |
... |
further arguments passed to or from other methods. |
summary.boot.lmf
formats bootstrap replicates in a user-friendly way,
and formats the temporal coefficients and variance-covariance matrix into
easily read tables for hypothesis tests.
The function summary.boot.lmf
computes and returns a list of summary
statistics of the bootstrap replicates of a fitted lmf
model given
in object
.
An object of class "summary.boot.lmf" is a list containing at most the following components:
call |
the matched call. |
nboot |
the number of bootstrap replicates generated. |
lest |
the estimated projection matrix. |
lboot.mean |
the bootstrap mean projection matrix. |
lbias |
the bootstrap bias of the components of the projection matrix. |
lboot.sd |
the boostrap standard deviation of the components of the projection matrix. |
luv |
the estimate, bootstrap mean, bias and standard deviation of the
deterministic multiplicative growth rate of the population |
sigma2.e |
the estimate, bootstrap mean, bias and standard deviation of the environmental variance of the population. |
sigma2.dd |
the estimate, bootstrap mean, bias and standard deviation of the demographic variances (by age class and in total). |
aM |
the estimate, bootstrap mean, bias and standard deviation of the estimated temporal mean selection coefficients. |
Mest |
the estimated temporal variance-covariance matrix (M). |
Mboot.mean |
the bootstrap mean temporal variance-covariance matrix. |
Mbias |
the bootstrap bias of the components of the temporal variance-covariance matrix. |
Mboot.sd |
the boostrap standard deviation of the components of the temporal variance-covariance matrix. |
anf |
the estimate, bootstrap mean, bias and standard deviation of the estimated temporal mean selection coefficients under the assumption of no fluctuating selection. |
Anfest |
the estimated temporal variance-covariance matrix under the assumtion of no fluctuating selection. |
Anfboot.mean |
the bootstrap mean temporal variance-covariance matrix under the assumption of no fluctuating selection. |
Anfbias |
the bootstrap bias of the components of the temporal variance-covariance matrix under the assumption of no fluctuating selection. |
Anfboot.sd |
the boostrap standard deviation of the components of the temporal variance-covariance matrix under the assumption of no fluctuating selection. |
coefficients.aH0aMboot |
the estimated temporal mean selection
coefficients, with bootstrapped standard errors, number of
successes with regard to the null hypothesis and associated p-values. All
under the specified null hypothesis |
coefficients.aH0anfboot |
the estimated temporal mean selection
coefficients under the assumtion of no fluctuating selection, with
bootstrapped standard errors, number of successes with regard to the null
hypothesis and associated p-values. All under the specified null hypothesis
|
coefficients.aH0Mnfboot |
the estimated temporal components of the
variance-covariance matrix, with bootstrapped standard errors, number of
successes with regard to the null hypothesis and associated p-values. All
under the specified null hypothesis |
lluvboot |
the bootstrap replicates of the projection matrix (columns f (fecundity) and s (survial)), lambda, the stable age distribution (u) and the reproductive values (v). Numbers in the column names indicate age class. |
deboot |
the bootstrap replicates of the demographic and environmental variances. Numbers in the column names indicate age class. |
atAboot |
the bootstrap replicates of the yearly coefficients of selection (at) and variance-covariance matrix (At). The first column indicate boostrap number and the second the boostrapped year. The subsequent columns contain coefficients (where (Intercept) (at) is the first coefficient), and components of the variance-covariance matrix (where (Intercept)-(Intercept) (At) is the first component (from the diagonal) of the matrix) |
aMMboot |
the bootstrap replicates of the temporal mean coefficients of selection (aM) and variance-covariance matrix (M). The first columns contain coefficients (where (Intercept) (a(M)) is the first coefficient), and subsequent columns contain the components of the variance-covariance matrix (where (Intercept)-(Intercept) (M) is the first component (from the diagonal) of the matrix) |
atCboot |
the bootstrap replicates of the yearly coefficients of selection (atC) corrected for sampling error. The first column indicate boostrap number, the second the boostrapped year and the subsequent columns contain the boostrapped coefficients. |
anfAboot |
the bootstrap replicates of the temporal mean coefficients of selection (anf) and variance-covariance matrix under the assumption of no fluctuating selection. The first columns contain coefficients (where (Intercept) (a(M=0)) is the first coefficient), and subsequent columns contain the components of the variance-covariance matrix (where (Intercept)-(Intercept) (At(M=0)) is the first component (from the diagonal) of the matrix) |
H0aMboot |
the bootstrap replicates of |
H0anfboot |
the bootstrap replicates of |
H0atnfboot |
the bootstrap replicates of |
H0Mnfboot |
the bootstrap replicates of |
Thomas Kvalnes
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Summary summary(b.1)
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Bootstrap parameters b.1 <- boot.lmf(object = lmf.1, nboot = 10, sig.dj = TRUE, what = "all", asim = "parametric") #Summary summary(b.1)
summary
method for class "lmf".
## S3 method for class 'lmf' summary(object, what.level = c("age", "year", "total"), ...) ## S3 method for class 'summary.lmf' print(x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...)
## S3 method for class 'lmf' summary(object, what.level = c("age", "year", "total"), ...) ## S3 method for class 'summary.lmf' print(x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ...)
object |
an object of class "lmf". |
what.level |
the lowest level of organisation at which parameters should be summarized. Options are "age" to summarize from the level of specific age classes, "year" to summarize from the level of years and "total" (default) to summarize the temporal parameters. |
x |
an object of class "summary.lmf". |
digits |
the number of significant digits to use when printing. |
signif.stars |
logical. If |
... |
further arguments passed to or from other methods. |
print.summary.lmf
formats the coefficients, standard errors and
variance-covariance matrices into easily read tables. The tests of significance
of the coefficients of selection should be considered as suggestive and should
be interpreted with caution. For tests of signifcanse a robust approach is
provided through the function boot.lmf
.
The function summary.lmf
computes and returns a list of summary
statistics of the fitted lmf
model given in object
.
An object of class "summary.lmf" is a list containing at most the following components:
call |
the matched call. |
what.level |
the lowest level of organisation at which parameters should be summarized. |
uage |
the unique age classes in the data set. |
nage |
the number of unique age classes in the data set. |
uyear |
the unique years in the data set. |
nyear |
the number of unique years in the data set. |
l |
the estimated projection matrix. |
lambda |
the deterministic multiplicative growth rate of the population. |
u |
the stable age distribution. |
v |
the vector of reproductive values for each age class. |
sigma2.e |
the environmental variance of the population. |
sigma2.dj |
a list containing the demographic variance for each age class. Sorted by age class. |
sigma2.dj.dof |
a list containing the degrees of freedom (dof) for the demographic variance for each age class. Sorted by age class. |
sigma2.dj.sd |
a list containing the standard deviation (sd) for the demographic variance for each age class. Sorted by age class. |
sigma2.d |
the total demographic variance of the population. |
sigma2.d.dof |
the degrees of freedom (dof) for the total demographic variance of the population. |
sigma2.d.sd |
the standard deviation (sd) for the total demographic variance of the population. |
coefficients.ajt |
the estimated selection coefficients for each age class within each year, with standard errors, t values and p-values. |
Ajt |
a list containing the named variance-covariance matrix for each age class within each year. Sorted by age class and year. |
coefficients.at |
the estimated selection coefficients within each year, with standard errors, t values and p-values. |
At |
a list containing the named variance-covariance matrix for each year. Sorted by year. |
coefficients.atC |
the estimated selection coefficients within each year corrected for sampling error, with standard errors, t values and p-values. |
coefficients.aM |
the estimated temporal mean selection coefficients, with standard errors, t values and p-values. |
M |
the estimated temporal covariance matrix (fluctuating selection). |
coefficients.anf |
the estimated temporal mean selection coefficients under the assumtion of no fluctuating selection, with standard errors, t values and p-values. |
Anf |
the estimated temporal covariance matrix assuming no fluctuating selection. |
Thomas Kvalnes
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Summary summary(lmf.1) #Summary from within years summary(lmf.1, what.level = "year") #Summary from within age classes summary(lmf.1, what.level = "age")
#Data set from Engen et al. 2012 data(sparrowdata) #Fit model lmf.1 <- lmf(formula = cbind(recruits, survival) ~ weight + tars, age = age, year = year, data = sparrowdata) #Summary summary(lmf.1) #Summary from within years summary(lmf.1, what.level = "year") #Summary from within age classes summary(lmf.1, what.level = "age")