srchisq_custom | R Documentation |
The srchisq_custom()
function generates random samples from a Chi-squared Distribution using the STORS algorithm.
It employs an optimized proposal distribution around the mode and Adaptive Rejection Sampling (ARS) for the tails.
srchisq_custom(n = 1, x = NULL)
n |
Integer, length 1. Number of samples to draw. |
x |
(optional) Numeric vector of length |
The Chi-squared Distribution
The Chi-squared distribution has the probability density function (PDF):
f(x | k) = \frac{1}{2^{k/2} \Gamma(k/2)} x^{(k/2) - 1} \exp(-x/2), \quad x \geq 0,
where:
k
is the degrees of freedom (k > 0
), which determines the shape of the distribution.
The Chi-squared distribution is widely used in hypothesis testing and constructing confidence intervals, particularly in the context of variance estimation.
this function is sampling from proposal that has been constructed using srchisq_optimize
, using the STORS algorithm.
By default, srchisq_custom()
samples from Chi-squared Distribution df = 2
.
The proposal distribution is pre-optimized at package load time using srchisq_optimize()
with
steps = 4091
, creating a scalable proposal centred around the mode.
A numeric vector of length n
containing random samples from the Chi-squared distribution.
The degrees of freedom (df
) for the distribution are specified during the optimization process using srchisq_optimize()
.
NOTE: When the x
parameter is specified, it is updated in-place with the simulation for performance reasons.
This function is not scalable. Therefore, only the srchisq_custom()
version is available, which requires the proposal to be pre-optimized using srchisq_optimize()
before calling this function.
srchisq_optimize
to optimize the custom proposal.
# Genedf 10 samples from Chi-squared Distribution
samples <- srchisq_custom(10)
print(samples)
# Genedf 10 samples using a pre-allocated vector
x <- numeric(10)
srchisq_custom(10, x = x)
print(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.