srchisq_custom {stors} | R Documentation |
Sampling from Chi-squared Distribution
Description
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.
Usage
srchisq_custom(n = 1, x = NULL)
Arguments
n |
Integer, length 1. Number of samples to draw. |
x |
(optional) Numeric vector of length |
Details
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.
Value
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.
Note
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.
See Also
srchisq_optimize
to optimize the custom proposal.
Examples
# 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)