pophist.aggregate: Aggregate a pophist object into genetic populations

View source: R/aggregate.R

pophist.aggregateR Documentation

Aggregate a pophist object into genetic populations

Description

Combines grid cells from the forward-time demographic simulation into a smaller number of cells for coalescent simulation.

Usage

pophist.aggregate(ph, gmap = NULL)

Arguments

ph

the output from forward time sim, includes a pophist object (output by getpophist2.cells())

gmap

data frame that maps forward time populations to genetic populations (output by make.gmap())

Details

This function takes a fine-grained spatio-temporal history of a species generated by holoSimCells forward-time simulator and aggregates demographic populations into genetic populations that can be simulated more tractably. The colonization history of component cells in the coarse grid is used to model proportional colonization from multiple source cells.

Value

Returned object includes the following named components:

  • pophist a data frame with population ID, cell row, cell column, timing of colonization, and source population associated with colonists.

  • Nvecs a data frame with number of generations columns and number of (aggregated) populations rows that provides population size through time from the forward demographic simulation.

  • tmat a matrix of pairwise migration rates between (aggregated) populations, used in subsequent coalescent simulations.

  • struct a vector summarizing the structure of the simulated landscape from the forward simulation, x and y dimensions of the grid, number of generations, disperal parameters, etc.

  • hab_suit a matrix with number of generations rows and number of (aggregated) populations columns that provides habitat suitability through time.

  • coalhist a data frame specifying historical events for the coalescent simulation, includes time of event (time), source (src) and sink (snk) IDs, and fractional colonization (prop).

  • popslst a list object with one element per grid cell from the forward-time demographic simulation. Each element includes information on location on the landscape, colonization time, source populations, and population size through time.

  • old_landscape original landscape from the forward-time demographic simulation.

  • old_tmat original migration matrix from the forward-time demographic simulation.

  • gmap gmap object that maps cells from the demographic simulation to a coarser grid for coalescent simulations.

See Also

make.gmap, doesGmapCombine, getpophist2.cells, run_FSC_step_agg3, http://cmpg.unibe.ch/software/fastsimcoal26/man/fastsimcoal26.pdf

Examples

library(holoSimCell)

parms <- drawParms(control = system.file("extdata/ashpaper","Ash_priors.csv",package="holoSimCell"))
load(file=paste0(system.file(package="holoSimCell"),"/extdata/landscapes/",pollenPulls[[1]]$file))
refpops <- pollenPulls[[1]]$refs
avgCellsz <- mean(c(res(landscape$sumrast)))

ph = getpophist2.cells(h = landscape$details$ncells, xdim = landscape$details$x.dim, ydim = landscape$details$y.dim,
                       landscape=landscape,
                       refs=refpops,  
                       refsz=parms$ref_Ne,
                       lambda=parms$lambda,
                       mix=parms$mix,  
                       shortscale=parms$shortscale*avgCellsz,  
                       shortshape=parms$shortshape, 
                       longmean=parms$longmean*avgCellsz,  
                       ysz=res(landscape$sumrast)[2], 
                       xsz=res(landscape$sumrast)[1], 
                       K = parms$Ne) 

gmap=make.gmap(ph$pophist,
               xnum=2, 
               ynum=2) 

ph2 <- pophist.aggregate(ph,gmap=gmap)


stranda/holoSimCell documentation built on Aug. 4, 2023, 1:12 p.m.