Learn R Programming

gsg (version 2.0)

fitness.landscape: A function to estimate fitness landscapes, i.e. the relationship between popualtion mean fitness and population mean phenotype.

Description

fitness.landscape() takes a fitness function, i.e., the relationship between fitness and indivdiual phenotype, as characterized using the function gam() from the package mgcv, and calculates a corresponding fitness landscape in one or two dimensions

Usage

fitness.landscape(mod, phenotype, covariates = NULL, points = NULL, plt.density = 25, PI.method = "boot.para", PI.interval = c(0.25, 0.75), n.boot = 50, refit.smooth = FALSE, parallel = "no", ncpus = 1)

Arguments

mod
a gam object. Must include predictor variables specified by phenotype
phenotype
a vector of one or two character strings specifying predictor variables in mod that are the phenotypic traits with respect to which the fitness landscape is to be calculated
covariates
a character vector listing any covariates in the model mod to be excluded from chanracterization of the fitness landscape
points
(optional) a matrix, array, or data frame with traits in columns and points in rows, specifying the series of points at which to evaluate the estimated fitness landscape. If missing, the fitness landscape is evaluated at points from one standard deviation below, to one standard deviation above the mean values, at as many points as specified by plt.density
plt.density
(optional) the number of points (per phenotypic trait) at which to evaluate the fitness landscape. only used if points is NULL
PI.method
the method by which to obtain a prediction interval for the fitness landscape. Options are 'n' for none, 'boot.para' for parametric bootstrapping, and 'boot.case' for case bootstrapping.
PI.interval
the upper and lower bounds of the prediction interval. Defaults to c(0.5, 0.75) in order to generate a prediction interval that is interpretable similarly to a standard error.
n.boot
number of bootstrap replicates for evaluating the prediction interval of the fitness landscape
refit.smooth
whether or not to re-estiamte smoothing parameters when gam objects are refitted in bootstrapping and permutation algorithms
parallel
whether or not to use parallel processing to speed up computation of bootstrap prediction intervals. Default in 'no' for no parallel computing. Under linux only, parallel='multicore' allows parallel processing, using the number of processors specified by ncpus
ncpus
the number of cpus to be used for parallel processing of bootstrap prediction intervals. Only used under linux.

Value

$points
the points at which the fitness landscape was evaluated
$Wbar
population mean absolute fitness at points
$WbarPI
bounds of the prediction interval of Wbar at points

References

M.B. Morrissey and K. Sakrejda. 2013. Unification of regression-based methods for the analysis of natural selection. Evolution 67: 2094-2100.

See Also

gam.gradients,moments.differentials,gam

Examples

Run this code
# simulated data (stabilizing selection)
z<-rnorm(200,0,2)
W<-rpois(200,exp(1-1*z^2))
d<-as.data.frame(list(W=W,z=z))

# characterize the fitness function
library(mgcv)
ff<-gam(W~s(z),family='poisson',data=d)

# characterize fitness landscape
fl<-fitness.landscape(mod=ff,phenotype="z",PI.method='n')

# (not run) plotting
# plot(fl$points[,1],fl$Wbar,type='l')
# lines(fl$points[,1],fl$WbarPI[1,],lty='dashed')
# lines(fl$points[,1],fl$WbarPI[2,],lty='dashed')

Run the code above in your browser using DataLab