### example for event type data
## setup
# using water depth as gradient
t = scenarioA$t_myr
wd = scenarioA$wd_m[,"8km"]
gc = approxfun(t, wd)
plot(t, gc(t), type = "l", xlab = "Time", ylab = "water depth [m]",
main = "gradient change with time")
# define niche
# preferred wd 10 m, tolerant to intermediate wd changes (standard deviation 10 m), non-terrestrial
niche_def = snd_niche(opt = 10, tol = 10, cutoff_val = 0)
plot(seq(-1, 50, by = 0.5), niche_def(seq(-1, 50, by = 0.5)), type = "l",
xlab = "water depth", ylab = "collection probability", main = "Niche def")
# niche pref with time
plot(t, niche_def(gc(t)), type = "l", xlab = "time",
ylab = "collection probability", main = "collection probability with time")
## simulate fossil occurrences
foss_occ = p3(rate = 100, from = 0, to = max(t))
# foss occ without niche pref
hist(foss_occ, xlab = "time")
foss_occ_niche = apply_niche(foss_occ, niche_def, gc)
# fossil occurrences with niche preference
hist(foss_occ_niche, xlab = "time")
# see also
#vignette("event_data")
# for a detailed example on niche modeling for event type data
### example for pre_paleoTS objects
# we reuse the niche definition and gradient change from above!
x = stasis_sl(seq(0, max(t), length.out = 10))
plot(reduce_to_paleoTS(x), main = "Trait evolution before niche modeling")
y = apply_niche(x, niche_def, gc)
plot(reduce_to_paleoTS(y), main = "Trait evolution after niche modeling")
# note that there are fewer sampling sites
# bc the taxon does not appear everywhere
# and there are fewer specimens per sampling site
### example for fossils objects
# we reuse the niche definition and gradient change from above
# simulate tree
t = ape::rlineage(birth = 2, death = 0, Tmax = 2)
# create fossils object
f = FossilSim::sim.fossils.poisson(rate = 2, tree = t)
# plot fossils along tree before niche model is applied
FossilSim:::plot.fossils(f, tree = t)
# introduce niche model
f_mod = apply_niche(f, niche_def, gc)
# plot fossils along tree after introduction of niche model
FossilSim:::plot.fossils(f_mod, tree = t)
# note how only fossils in the interval where environmental conditions are suitable are preserved
Run the code above in your browser using DataLab