Creates the input necessary to run Pyrate, based on a data.frame with fossil ages (as derived e.g. from clean_fossils) and a vector of the extinction status for each sample. Creates files in the working directory!
write_pyrate(
x,
status,
fname,
taxon = "accepted_name",
min_age = "min_ma",
max_age = "max_ma",
trait = NULL,
path = getwd(),
replicates = 1,
cutoff = NULL,
random = TRUE
)
data.frame. Containing fossil records with taxon names, ages, and geographic coordinates.
a vector of character strings of length nrow(x)
.
Indicating for each record “extinct” or “extant”.
a character string. The prefix to use for the output files.
character string. The column with the taxon name. Default = “accepted_name”.
character string. The column with the minimum age. Default = “min_ma”.
character string. The column with the maximum age. Default = “max_ma”.
a numeric vector of length nrow(x)
. Indicating trait
values for each record. Optional. Default = NULL.
a character string. giving the absolute path to write the output files. Default is the working directory.
a numerical. The number of replicates for the randomized age generation. See details. Default = 1.
a numerical. Specify a threshold to exclude fossil occurrences with a high temporal uncertainty, i.e. with a wide temporal range between min_age and max_age. Examples: cutoff=NULL (default; all occurrences are kept in the data set) cutoff=5 (all occurrences with a temporal range of 5 Myr or higher are excluded from the data set)
logical. Specify whether to take a random age (between MinT and MaxT) for each occurrence or the midpoint age. Note that this option defaults to TRUE if several replicates are generated (i.e. replicates > 1). Examples: random = TRUE (default) random = FALSE (use midpoint ages)
PyRate input files in the working directory.
The replicate option allows the user to generate several replicates of the data set in a single input file, each time re-drawing the ages of the occurrences at random from uniform distributions with boundaries MinT and MaxT. The replicates can be analysed in different runs (see PyRate command -j) and combining the results of these replicates is a way to account for the uncertainty of the true ages of the fossil occurrences. Examples: replicates=1 (default, generates 1 data set), replicates=10 (generates 10 random replicates of the data set).
See https://github.com/dsilvestro/PyRate/wiki for more details and tutorials on PyRate and PyRate input.
minages <- runif(250, 0, 65)
exmpl <- data.frame(accepted_name = sample(letters, size = 250, replace = TRUE),
lng = runif(250, min = 42, max = 51),
lat = runif(250, min = -26, max = -11),
min_ma = minages,
max_ma = minages + runif(250, 0.1, 65))
#a vector with the status for each record,
#make sure species are only classified as either extinct or extant,
#otherwise the function will drop an error
status <- sample(c("extinct", "extant"), size = nrow(exmpl), replace = TRUE)
#or from a list of species
status <- sample(c("extinct", "extant"), size = length(letters), replace = TRUE)
names(status) <- letters
status <- status[exmpl$accepted_name]
if (FALSE) {
write_pyrate(x = exmpl,fname = "test", status = status)
}