Title: | PEcAn Functions Used to Estimate Priors from Data |
---|---|
Description: | Functions to estimate priors from data. |
Authors: | David LeBauer [aut, cre], University of Illinois, NCSA [cph] |
Maintainer: | David LeBauer <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 1.7.3.9000 |
Built: | 2025-03-11 03:29:57 UTC |
Source: | https://github.com/PecanProject/pecan |
Returns a data frame from stats::density
function
create.density.df( samps = NULL, zero.bounded = FALSE, distribution = NULL, n = 1000, ... )
create.density.df( samps = NULL, zero.bounded = FALSE, distribution = NULL, n = 1000, ... )
samps |
a vector of samples from a distribution |
zero.bounded |
logical: Restrict density distribution to nonnegative values? |
distribution |
list with elements distn, parama, paramb,
e.g. |
n |
number of points at which to estimate density |
... |
additional arguments, passed on to |
data frame with x and y = dens(x)
David LeBauer
prior.df <- create.density.df(distribution = list('norm',0,1)) plot(prior.df) samp.df <- create.density.df(samps = rnorm(100)) lines(samp.df)
prior.df <- create.density.df(distribution = list('norm',0,1)) plot(prior.df) samp.df <- create.density.df(samps = rnorm(100)) lines(samp.df)
Fit a distribution to data
fit.dist( trait.data, trait = colnames(trait.data), dists = c("weibull", "lognormal", "gamma"), n = NULL )
fit.dist( trait.data, trait = colnames(trait.data), dists = c("weibull", "lognormal", "gamma"), n = NULL )
trait.data |
data for distribution |
trait |
name of trait to fit. One of "tt", "sla", "rrr", "q" |
dists |
list of distribution names |
n |
only used in return value |
best fit distribution
David LeBauer
Finds quantiles on a density data frame
get.quantiles.from.density(density.df, quantiles = c(0.025, 0.5, 0.975))
get.quantiles.from.density(density.df, quantiles = c(0.025, 0.5, 0.975))
density.df |
density dataframe generated by |
quantiles |
default is the median and 95% CI; |
David LeBauer
prior.df <- create.density.df(distribution = list('norm',0,1)) get.quantiles.from.density(prior.df) samp.df <- create.density.df(samps = rnorm(100)) get.quantiles.from.density(samp.df)
prior.df <- create.density.df(distribution = list('norm',0,1)) get.quantiles.from.density(prior.df) samp.df <- create.density.df(samps = rnorm(100)) get.quantiles.from.density(samp.df)
Take n random samples from prior
get.sample(prior, n = NULL, p = NULL)
get.sample(prior, n = NULL, p = NULL)
prior |
data.frame with distn, parama, and optionally paramb. |
n |
number of samples to return from a random sample of the rdistn family of functions (e.g. rnorm) |
p |
vector of quantiles from which to sample the distribution; typically pre-generated upstream in the workflow to be used by the qdistn family of functions (e.g. qnorm) |
Similar to the prior sample function pr.samp, except 1) it takes the prior as a named dataframe or list and it can return either a random sample of length n OR a sample from a quantile specified as p
vector with n random samples from prior
## Not run: # return 1st through 99th quantile of standard normal distribution: PEcAn.priors::get.sample( prior = data.frame(distn = 'norm', parama = 0, paramb = 1), p = 1:99/100) # return 100 random samples from standard normal distribution: PEcAn.priors::get.sample( prior = data.frame(distn = 'norm', parama = 0, paramb = 1), n = 100) ## End(Not run)
## Not run: # return 1st through 99th quantile of standard normal distribution: PEcAn.priors::get.sample( prior = data.frame(distn = 'norm', parama = 0, paramb = 1), p = 1:99/100) # return 100 random samples from standard normal distribution: PEcAn.priors::get.sample( prior = data.frame(distn = 'norm', parama = 0, paramb = 1), n = 100) ## End(Not run)
Plot probability density and data
plot_densities(density.plot_inputs, outdir, ...)
plot_densities(density.plot_inputs, outdir, ...)
density.plot_inputs |
list containing trait.samples and trait.df |
outdir |
directory in which to generate figure as pdf |
... |
passed on to plot_density |
outputs plots in outdir/sensitivity.analysis.pdf file
David LeBauer
Add posterior density to a plot
plot_posterior.density(posterior.density, base.plot = NULL)
plot_posterior.density(posterior.density, base.plot = NULL)
posterior.density |
data frame containing columns x and y |
base.plot |
a ggplot object (grob), created if none provided |
plot with posterior density line added
David LeBauer
Plots a prior density from a parameterized probability distribution
plot_prior.density(prior.density, base.plot = NULL, prior.color = "black")
plot_prior.density(prior.density, base.plot = NULL, prior.color = "black")
prior.density |
data frame containing columns x and y |
base.plot |
a ggplot object (grob), created if none provided |
prior.color |
color of line to be plotted |
plot with prior density added
David LeBauer
## Not run: plot_prior.density(pr.dens('norm', 0, 1)) ## End(Not run)
## Not run: plot_prior.density(pr.dens('norm', 0, 1)) ## End(Not run)
Plot trait density and data
plot_trait( trait, prior = NULL, posterior.sample = NULL, trait.df = NULL, fontsize = list(title = 18, axis = 14), x.lim = NULL, y.lim = NULL, logx = FALSE )
plot_trait( trait, prior = NULL, posterior.sample = NULL, trait.df = NULL, fontsize = list(title = 18, axis = 14), x.lim = NULL, y.lim = NULL, logx = FALSE )
trait |
dataframe with id, figid and units of the trait to be plotted |
prior |
named distribution with parameters |
posterior.sample |
samples from posterior distribution whose density should be plotted |
trait.df |
data to be plotted, in a format accepted by
|
fontsize , x.lim , y.lim , logx
|
passed on to ggplot |
plot (grob) object
David LeBauer
## Not run: prior1 <- data.frame(distn = 'norm', parama = 20, paramb = 5) data1 <- data.frame(Y = c(19, 21), se = c(1,1)) trait1 <- data.frame(id = 'Vcmax', figid = 'Vcmax', units = 'umol CO2 m-2 s-1') plot_trait(trait = trait1, prior = prior1, trait.df = data1) ## End(Not run)
## Not run: prior1 <- data.frame(distn = 'norm', parama = 20, paramb = 5) data1 <- data.frame(Y = c(19, 21), se = c(1,1)) trait1 <- data.frame(id = 'Vcmax', figid = 'Vcmax', units = 'umol CO2 m-2 s-1') plot_trait(trait = trait1, prior = prior1, trait.df = data1) ## End(Not run)
Calculates density at n points across the range of a parameter
pr.dens(distn, parama, paramb, n = 1000, alpha = 0.001)
pr.dens(distn, parama, paramb, n = 1000, alpha = 0.001)
distn |
distribution |
parama |
parameter |
paramb |
parameter |
n |
length of vector to be returned |
alpha |
sets range at which the distribution will be evaluated (e.g. from alpha to 1-alpha) |
For a distribution and parameters, return the density for values ranging from alpha to 1-alpha
dataframe with equally spaced x values and the corresponding densities
David LeBauer
Take n random samples from prior
pr.samp(distn, parama, paramb, n)
pr.samp(distn, parama, paramb, n)
distn |
name of distribution, e.g. "norm", "pois" |
parama |
first parameter for distn call |
paramb |
second parameter for distn call |
n |
number of samples to return |
vector with n random samples from prior
Prior fitting function for optimization
prior.fn(parms, x, alpha, distn, central.tendency = NULL, trait = NULL)
prior.fn(parms, x, alpha, distn, central.tendency = NULL, trait = NULL)
parms |
target for optimization |
x |
vector with c(lcl, ucl, ct) lcl / ucl = confidence limits, ct = entral tendency |
alpha |
quantile at which lcl/ucl are estimated (e.g. for a 95% CI, alpha = 0.5) |
distn |
named distribution, one of 'lnorm', 'gamma', 'weibull', 'beta'; support for other distributions not currently implemented |
central.tendency |
one of 'mode', 'median', and 'mean' |
trait |
name of trait, can be used for exceptions (currently used for trait == 'q') |
This function is used within 'DEoptim' to parameterize a distribution to the central tendency and confidence interval of a parameter. This function is not very robust; currently it needs to be tweaked when distributions require starting values (e.g. beta, f)
parms
David LeBauer
## Not run: DEoptim(fn = prior.fn, lower = c(0, 0), upper = c(1000, 1000), x=c(2, 6, 3.3), alpha = 0.05, distn = 'lnorm')$optim$bestmem ## End(Not run)
## Not run: DEoptim(fn = prior.fn, lower = c(0, 0), upper = c(1000, 1000), x=c(2, 6, 3.3), alpha = 0.05, distn = 'lnorm')$optim$bestmem ## End(Not run)
Plot prior density and data
priorfig( priordata = NA, priordensity = NA, trait = NA, xlim = "auto", fontsize = 18 )
priorfig( priordata = NA, priordensity = NA, trait = NA, xlim = "auto", fontsize = 18 )
priordata |
observations to be plotted as points |
priordensity |
density of prior distribution, calculated by |
trait |
dataframe with id, figid and units of the trait |
xlim |
limits for x axis |
fontsize |
passed to ggplot to set text size |
plot / grob of prior distribution with data used to inform the distribution
David LeBauer