Stepdown | R Documentation |
Stepdown class
Stepdown class
This R6 class represents a step function approximation to the non-increasing
function \rm{Pr}(A_u)
for u \in [0,1]
.
The object w
represents a unimodal weight function. It is
expected to contain several members:
log_c
: the logarithm of the value c, which is the mode of the
weight function.
roots(log_a)
: return the roots of the equation
\log w(x) - \rm{log_a} = 0
.
eval(x, log = TRUE)
: evaluate the function. Return the value
on the log-scale if log = TRUE
.
The object g
represents a base distribution. It is
expected to contain two member functions:
pr_interval(x1, x2)
: Return \rm{Pr}(x1 < X < x2)
under
distribution g.
r_truncated(n, x1, x2)
: Take n draws from distribution g
truncated to the open interval (x1, x2)
.
We make use of the fibonacci_heap
structure in the
datastructures
package to avoid repeated sorted when
small_rects
is used as the method of knot selection. This package is
not maintained on CRAN at the time this message is being written; therefore,
we make use of it as a suggested package, following the guidance in
https://cran.r-project.org/doc/manuals/R-exts.html#Suggested-packages.
I.e., all datastructures
function calls are proceeded with a
namespace and the package is not listed in Imports
or Depends
.
new()
Construct the step function
Stepdown$new( w, g, tol, N, method, priority_weight = 1/2, midpoint_type = "geometric" )
w
An object representing a weight function (see details).
g
An object representing a base distribution (see details).
tol
A small positive number used in search for u_L
and u_H
.
N
Number of knot points will be N+1.
method
Either equal_steps
or small_rects
(see details).
priority_weight
Experimental: An weight between 0 and 1. When closer
to 1, more priority is given in small_rects
to rectangle height. When
closer to 0, more priority is given to rectangle width.
midpoint_type
Type of midpoint function to use. Currently only
geometric
or arithmetic
are supported. geometric
is
preferred when the support of p(u)
is focused very close to zero.
get_cum_probs()
Get cumulative probabilities after normalizing the step function to a discrete distribution.
Stepdown$get_cum_probs()
get_norm_const()
The constant used to normalize the step function to a discrete distribution.
Stepdown$get_norm_const()
get_log_x_vals()
The knot values on which the approximation is based, returned on the log-scale.
Stepdown$get_log_x_vals()
get_log_h_vals()
Values of the approximation evaluated at the points
returned by get_log_x_vals
, given at the log-scale.
Stepdown$get_log_h_vals()
get_rects()
Rectangles used to bound the approximation: x and h
coordinates along with the area. Values are returned on the log-scale or
the original scale according to the log
argument.
Stepdown$get_rects(log = FALSE)
log
If TRUE
, return value on the log-scale.
get_knot_order()
Returns the order in which knot points were added to the
step function. Indices correspond to the points returned by
get_log_x_vals
.
Stepdown$get_knot_order()
get_log_p()
Evaluate the function \rm{Pr}(A_u)
on a given
point u (to be provided on the log-scale). The result is returned
on the log-scale.
Stepdown$get_log_p(log_u)
log_u
A value of u given at the log-scale.
get_priority_weight()
Returns the value of priority_weight
.
Stepdown$get_priority_weight()
add()
Update step function by adding a knot at the point u (given on the log-scale).
Stepdown$add(log_u)
log_u
A value of u given at the log-scale.
q()
Quantiles of the distribution based on the step function.
Stepdown$q(p, log = FALSE)
p
A probability to evaluate.
log
If TRUE
, return value on the log-scale.
r()
Draw from the distribution based on the step function.
Stepdown$r(n, log = TRUE)
n
Number of draws to generate.
log
If TRUE
, return value on the log-scale.
d()
Density of the distribution based on the step function.
Stepdown$d(log_x, log = FALSE, normalize = TRUE)
log_x
A vector of points to evaluate, provided on the log-scale.
log
If TRUE
, return value on the log-scale.
normalize
If TRUE
, normalize the result to be a density value.
p()
CDF of the distribution based on the step function.
Stepdown$p(log_x)
log_x
A vector of points to evaluate, provided on the log-scale.
clone()
The objects of this class are cloneable with this method.
Stepdown$clone(deep = FALSE)
deep
Whether to make a deep clone.
Simon Dirmeier, (2018). datastructures: An R package for organisation and storage of data . Journal of Open Source Software, 3(28), 910, https://doi.org/10.21105/joss.00910
Winston Chang (2020). R6: Encapsulated Classes with Reference Semantics. R package version 2.5.0. https://CRAN.R-project.org/package=R6
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.