rbiased: Generate a biased sample using...

View source: R/rbiased.R

rbiasedR Documentation

Generate a biased sample using \insertCiteneumann1951;textualWData acceptance-rejection method

Description

This function generates a biased sample of size n using \insertCiteneumann1951;textualWData acceptance-rejection method. The generated sample is biased according to the provided bias function w, with respect to the unbiased density function fx.

Usage

rbiased(
  n,
  w = function(y) {
     ifelse(y >= 0, y, NA)
 },
  fx,
  lim = 0.01,
  plot = TRUE,
  stop = TRUE,
  shape1,
  shape2,
  location,
  scale,
  df,
  ncp,
  rate,
  df1,
  df2,
  shape,
  meanlog,
  sdlog,
  min,
  max,
  mgshape,
  mgscale,
  mgweight,
  pro,
  mean,
  sd
)

Arguments

n

Sample size.

w

A function representing the bias function applied to the data points. It must be evaluable and positive in each point of the sample y. By default, it is set to the length-biased function.

fx

Unbiased density function. Values allowed are Beta (beta), Cauchy (cauchy), Chi-Square (chisq), Exponential (exp), F (f), Gamma (gamma), Logistic (logis), Log Normal (lnorm), Normal (norm), Student t (t), Continuous Uniform (unif), Weibull (weibull), Mixture of gaussian distributions (mixnorm) and Mixture of gamma distributions (weighted sum of gamma densities).

lim

Lower and upper limits for the range where the bias is significant and, hence, where c = \max_{y\in \mathbb{R}}w(y)/\mu_w > 0 must be searched.

plot

Logical value indicating whether to generate a plot of the biased sample. Default is TRUE.

stop

Logical value indicating whether to stop when bias function can not be evaluated in a generated value. Default is TRUE. If FALSE value is discarded and a new one is generated.

shape1, shape2

Additional arguments to be passed to the unbiased density function fx when set to the beta distribution.

df, ncp

Additional arguments to be passed to the unbiased density function fx when set to the chisq and t distributions.

df1, df2

Additional arguments to be passed to the unbiased density function fx when set to the f distribution.

shape, rate, scale, location

Additional arguments to be passed to the unbiased density function fx when set to the cauchy, logis, exp, gamma and weibull distributions.

min, max

Additional arguments to be passed to the unbiased density function fx when set to the unif distribution.

mgshape, mgscale, mgweight

Shape, scale, and mixing weights for the gamma components when fx = "mgamma". If mgweight is omitted, equal weights are used.

mean, sd, pro, meanlog, sdlog

Additional arguments to be passed to the unbiased density function fx when set to the norm, mixnorm and lnorm distributions.

Details

This function implements \insertCiteneumann1951;textualWData acceptance-rejection method to generate a biased sample given an unbiased density function fx and a bias function w.

Value

A numeric vector containing a biased sample from density fx and bias function w.

References

\insertAllCited

Examples

# Generate a length-biased sample of size 100 from an exponential distribution
rbiased(n = 100, fx = "exp", rate = 2, plot = FALSE)

# Generate a length-biased sample from a gamma distribution
rbiased(n = 100, fx = "gamma", rate = 1.5^2, shape = 1.5)

# Generate a biased sample from a gaussian distribution
custom_bias <- function(y) {
  y^2
}
rbiased(n = 100, w = custom_bias, fx = "norm", mean = 3, sd = 10, plot = TRUE)

# Generate a biased sample from a mixture of gaussian distributions
custom_bias <- function(y) {
  sqrt(abs(y)) + 5
}
rbiased(
  n = 100, w = custom_bias, fx = "mixnorm", pro = rep(1 / 3, 3), mean = c(0.25, 0.5, 0.75),
  sd = rep(0.075, 3)
)

WData documentation built on Nov. 2, 2026, 1:10 a.m.