View source: R/OUT_GET_get.traits.R
get.post.traits | R Documentation |
This function samples (or extracts previously-sampled) trait values at tips
or internal nodes (a form of stochastic ancestral state reconstruction) given
an evorates_fit
object.
get.post.traits(
fit,
select = seq_len(Ntip(fit) + Nnode(fit)),
type = c("chains", "quantiles", "means", "diagnostics"),
extra.select = NULL,
simplify = TRUE,
store.in.fit = FALSE,
force.resample = FALSE
)
fit |
An object of class " |
select |
A numeric vector specifying node indices in |
type |
A string specifying whether to extract posterior samples (" |
extra.select |
A numeric, integer, or character vector specifying the specific samples/
quantiles/diagnostics to extract, depending on |
simplify |
|
store.in.fit |
(new in 0.1.1) |
force.resample |
(new in 0.1.1) |
The tip and node indices of fit$call$tree
can be viewed by running:
plot(fit$call$tree); tiplabels(); nodelabels()
.
Note that this function does random sampling internally, so you will get different results
every time you run it unless you use a consistent seed (e.g., using set.seed()
) or
store sampled trait values.
If store.in.fit
is FALSE
: an array of class "param_block
" with a
param_type
set to whatever
type
is. The dimension of these arrays will generally go in the order of
iterations/quantiles/diagnostics, then parameters, then chains. Any dimensions of length 1 are
collapsed and stored as attributes if simplify
is TRUE
.
If store.in.fit
is TRUE
: an evorates_fit
object including extra parameters corresponding
to trait values. Parameters go by the
name <trait.name>_i
, where i
is the label or index of the corresponding tip or internal
node, respectively, in fit$call$tree
. The trait name
corresponds to the column name of fit$call$trait.data
, which is "X1" if not provided in the
original input to fit.evorates()
or input.evorates()
.
Other parameter extraction functions:
get.R()
,
get.bg.rate()
,
remove.trend()
#get whale/dolphin evorates fit
data("cet_fit")
#get posterior samples of all trait values
x <- get.post.traits(cet_fit)
#let's say we want to get some trait values towards the root
plot(cet_fit$call$tree); nodelabels()
#select particular edges
x <- get.post.traits(cet_fit, select = c(89, 90, 94, 103, 104, 105))
#maybe specific samples too?
x <- get.post.traits(cet_fit, select = c(89, 90, 94, 103, 104, 105),
extra.select=c(1, 23, 47))
#this may be a more common way to get node indices; say we want to look at the genus Mesoplodon
edges <- get.clade.edges(cet_fit$call$tree, "Mesoplodon")
nodes <- unique(as.vector(cet_fit$call$tree$edge[edges,]))
Meso.x <- get.post.traits(cet_fit, select = nodes)
#or at everything EXCEPT Mesoplodon
notMeso.x <- get.post.traits(cet_fit, select = -nodes)
#you could also rely on string matching if you're interested in the tips only
Meso.tips.x <- get.post.traits(cet_fit, select = "Mesoplodon")
#could also look at quantiles, means, or diagnostics
med.x <- get.post.traits(cet_fit, select = nodes,
type = "quantiles",
extra.select = 0.5)
mean.x <- get.post.traits(cet_fit, select = nodes,
type = "means")
init.x <- get.post.traits(cet_fit, select = nodes,
type = "diagnostics",
extra.select = c("inits", "ess"))
#here's an example of what happens when you don't simplify the result
med.x <- get.R(cet_fit, select = nodes,
type = "quantiles",
extra.select = 0.5,
simplify = FALSE)
#note that, depending on your goals, it may be more efficient to do things like this instead
x <- get.post.traits(cet_fit)
med.Meso.x <- x %quantiles% list(nodes, 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.