| Title: | Random Number Generators and Utilities |
|---|---|
| Description: | Provides a collection of random number generators for common and custom distributions, along with utility functions for sampling and simulation. |
| Authors: | Manos Papadakis [aut, cre, cph], Michail Tsagris [ctb], Omar Alzeley [ctb] |
| Maintainer: | Manos Papadakis <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.1 |
| Built: | 2026-09-10 12:10:57 UTC |
| Source: | https://github.com/manospapadakis95/rangen |
Provides a collection of random number generators for common and custom distributions, along with utility functions for sampling and simulation.
| Package: | rangen |
| Type: | Package |
| Version: | 0.0.1 |
| Date: | 2026-03-09 |
| License: | GPL-3 |
Manos Papadakis <[email protected]>
Manos Papadakis <[email protected]>
Michail Tsagris <[email protected]>
Angular central Gaussian random values simulation.
racg(n, sigma, seed = rangen::new.seed())racg(n, sigma, seed = rangen::new.seed())
n |
The sample size, a numerical value. |
sigma |
The covariance matrix in |
seed |
If you want the same to be generated again use a seed for the generator, an integer number. |
The algorithm uses univariate normal random values and transforms them to multivariate via a spectral decomposition. The vectors are then scaled to have unit length.
A matrix with the simulated data.
Michail Tsagris
R implementation and documentation: Michail Tsagris <[email protected]>
Tyler D. E. (1987). Statistical analysis for the angular central Gaussian distribution on the sphere. Biometrika 74(3): 579-589.
acg.mle, rmvnorm, rmvlaplace, rmvt
s <- cov( iris[, 1:4] ) #x <- racg(100, s) #res<-acg.mle(x) #res<-vmf.mle(x) ## the concentration parameter, kappa, is very low, close to zero, as expected.s <- cov( iris[, 1:4] ) #x <- racg(100, s) #res<-acg.mle(x) #res<-vmf.mle(x) ## the concentration parameter, kappa, is very low, close to zero, as expected.
Multivariate Laplace random values simulation.
rmvlaplace(n, lam, mu, G, seed = rangen::new.seed())rmvlaplace(n, lam, mu, G, seed = rangen::new.seed())
n |
The sample size, a numerical value. |
lam |
The the parameter of the exponential distribution, a positive number. |
mu |
The mean vector. |
G |
A |
seed |
If you want the same to be generated again use a seed for the generator, an integer number. |
The algorithm uses univariate normal random values and transforms them to multivariate via a spectral decomposition.
A matrix with the simulated data.
Michail Tsagris
R implementation and documentation: Michail Tsagris <[email protected]>
Eltoft T., Kim T., and Lee T.W. (2006). On the multivariate laplace distribution. Signal Processing Letters, IEEE, 13(5):300-303.
m <- colMeans(as.matrix(iris[, 1:4])) s <- cov(iris[, 1:4]) s <- s / det(s)^0.25 lam <- 3 x <- rmvlaplace(100, lam, m, s)m <- colMeans(as.matrix(iris[, 1:4])) s <- cov(iris[, 1:4]) s <- s / det(s)^0.25 lam <- 3 x <- rmvlaplace(100, lam, m, s)
Multivariate normal and t random values simulation.
rmvnorm(n, mu, sigma, seed = rangen::new.seed()) rmvt(n, mu, sigma, v, seed = rangen::new.seed())rmvnorm(n, mu, sigma, seed = rangen::new.seed()) rmvt(n, mu, sigma, v, seed = rangen::new.seed())
n |
The sample size, a numerical value. |
mu |
The mean vector in |
sigma |
The covariance matrix in |
v |
The degrees of freedom. |
seed |
If you want the same to be generated again use a seed for the generator, an integer number. |
The algorithm uses univariate normal random values and transforms them to multivariate via a spectral decomposition. It is faster than the command "mvrnorm" available from MASS, and it allows for singular covariance matrices.
A matrix with the simulated data.
Michail Tsagris
R implementation and documentation: Michail Tsagris <[email protected]>
Aitchison J. (1986). The statistical analysis of compositional data. Chapman & Hall.
x <- as.matrix(iris[, 1:4]) m <- colMeans(x) s <- cov(x) y <- rmvnorm(1000, m, s) res <- colMeans(y) res <- cov(y) y <- NULLx <- as.matrix(iris[, 1:4]) m <- colMeans(x) s <- cov(x) y <- rmvnorm(1000, m, s) res <- colMeans(y) res <- cov(y) y <- NULL
Random integer values simulation.
Sample.int(n, size = n, replace = FALSE, seed = new.seed()) Sample(x, size = length(x), replace = FALSE, seed = new.seed()) colSample(x, size = rep_len(nrow(x), ncol(x)), replace = rep_len(FALSE, ncol(x)), parallel = FALSE, cores = 0, seed = new.seed()) rowSample(x, size = rep_len(ncol(x), nrow(x)), replace = rep_len(FALSE, nrow(x)), parallel = FALSE, cores = 0, seed = new.seed())Sample.int(n, size = n, replace = FALSE, seed = new.seed()) Sample(x, size = length(x), replace = FALSE, seed = new.seed()) colSample(x, size = rep_len(nrow(x), ncol(x)), replace = rep_len(FALSE, ncol(x)), parallel = FALSE, cores = 0, seed = new.seed()) rowSample(x, size = rep_len(ncol(x), nrow(x)), replace = rep_len(FALSE, nrow(x)), parallel = FALSE, cores = 0, seed = new.seed())
x |
A numeric vector for sampling or a matrix for column-row sampling. |
n |
This must be an integer value. The function will then draw random integer values from 1:n. |
size |
The number of integer values to sample. |
replace |
Do you want to sample with replacement? If yes, set this equal to TRUE. |
parallel |
Do you want to do it in parallel, for column - row major, in C++? TRUE or FALSE. |
cores |
Number of cores to use for parallelism. Valid only when argument parallel is set to TRUE. Default value is 0, which uses the OpenMP default number of threads.. |
seed |
A seed object created by |
These functions provide flexible sampling utilities similar in purpose to R's base functions sample.int and sample. Each function operates on a different structure:
Sample.int: Generates a random sample of integers from 1 to n.
Sample: Samples elements from the vector x.
colSample: Performs column-wise sampling on a matrix or data frame, selecting size[i] elements from each column i.
rowSample: Performs row-wise sampling on a matrix or data frame, selecting size[i] elements from each row i.
All functions support sampling with or without replacement. Parallel versions do not support seeding.
Sample.int, Sample
|
A vector of sampled values. |
colSample, rowSample
|
A matrix or data frame containing the sampled elements. |
R implementation and documentation: Manos Papadakis <[email protected]>.
# Sample integers from 1 to 10 with replacement (faster than base::sample.int) x <- Sample.int(10, 1000, replace = TRUE) # Sample from the vector 'x' (faster than base::sample) xs <- Sample(x) # Create a matrix and perform column-wise sampling # 'size' must have the same length as the number of columns mat <- matrix(1:20, nrow = 5, ncol = 4) colSample(mat, size = rep(5, ncol(mat)), replace = rep(TRUE, ncol(mat))) # Create a matrix and perform row-wise sampling # 'size' must have the same length as the number of rows rowSample(mat, size = rep(4, nrow(mat)), replace = rep(FALSE, nrow(mat)))# Sample integers from 1 to 10 with replacement (faster than base::sample.int) x <- Sample.int(10, 1000, replace = TRUE) # Sample from the vector 'x' (faster than base::sample) xs <- Sample(x) # Create a matrix and perform column-wise sampling # 'size' must have the same length as the number of columns mat <- matrix(1:20, nrow = 5, ncol = 4) colSample(mat, size = rep(5, ncol(mat)), replace = rep(TRUE, ncol(mat))) # Create a matrix and perform row-wise sampling # 'size' must have the same length as the number of rows rowSample(mat, size = rep(4, nrow(mat)), replace = rep(FALSE, nrow(mat)))
Functions to simulate random values from different probability distributions: uniform, beta, exponential, chi-squared, gamma, Cauchy, t-distribution, and geometric.
Runif(n, min = 0, max = 1, seed = new.seed()) Rbeta(n, alpha, beta, seed = new.seed()) Rexp(n, rate = 1, seed = new.seed()) Rchisq(n, df, seed = new.seed()) Rgamma(n, shape, rate = 1, seed = new.seed()) Rcauchy(n, location = 0, scale = 1, seed = new.seed()) Rt(n, df, ncp, seed = new.seed()) Rgeom(n, prob, seed = new.seed()) Rpareto(n, shape = 1, scale = 1, seed = new.seed()) Rfrechet(n, lambda = 1, mu = 0, sigma = 1, seed = new.seed()) Rlaplace(n, mu = 0, sigma = 1, seed = new.seed()) Rgumbel(n, mu = 0, sigma = 1, seed = new.seed()) Rarcsine(n, min = 0, max = 1, seed = new.seed()) Rnorm(n, mean = 0, sd = 1, seed = new.seed()) Runif.mat(nrow, ncol, min = 0, max = 1, seed = new.seed()) Rbeta.mat(nrow, ncol, alpha, beta, seed = new.seed()) Rexp.mat(nrow, ncol, rate = 1, seed = new.seed()) Rchisq.mat(nrow, ncol, df, seed = new.seed()) Rgamma.mat(nrow, ncol, shape, rate = 1, seed = new.seed()) Rcauchy.mat(nrow, ncol, location = 0, scale = 1, seed = new.seed()) Rt.mat(nrow, ncol, df, ncp, seed = new.seed()) Rgeom.mat(nrow, ncol, prob, seed = new.seed()) Rpareto.mat(nrow, ncol, shape = 1, scale = 1, seed = new.seed()) Rfrechet.mat(nrow, ncol, lambda = 1, mu = 0, sigma = 1, seed = new.seed()) Rlaplace.mat(nrow, ncol, mu = 0, sigma = 1, seed = new.seed()) Rgumbel.mat(nrow, ncol, mu = 0, sigma = 1, seed = new.seed()) Rarcsine.mat(nrow, ncol, min = 0, max = 1, seed = new.seed()) Rnorm.mat(nrow, ncol, mean = 0, sd = 1, seed = new.seed()) colRunif(nrow, ncol, min = rep_len(0, ncol), max = rep_len(1, ncol), seed = new.seed(), parallel = FALSE, cores = 0) colRbeta(nrow, ncol, alpha, beta, seed = new.seed()) colRexp(nrow, ncol, rate = rep_len(1, ncol), seed = new.seed()) colRchisq(nrow, ncol, df, seed = new.seed()) colRgamma(nrow, ncol, shape, rate = rep_len(1, ncol), seed = new.seed()) colRgeom(nrow, ncol, prob, seed = new.seed()) colRcauchy(nrow, ncol, location = rep_len(0, ncol), scale = rep_len(1, ncol), seed = new.seed()) colRt(nrow, ncol, df, ncp, seed = new.seed()) colRpareto(nrow, ncol, shape = rep_len(1, ncol), scale = rep_len(1, ncol), seed = new.seed()) colRfrechet(nrow, ncol, lambda = rep_len(1, ncol), mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRlaplace(nrow, ncol, mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRgumbel(nrow, ncol, mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRarcsine(nrow, ncol, min = rep_len(0, ncol), max = rep_len(1, ncol), seed = new.seed()) colRnorm(nrow, ncol, mean = rep_len(0, ncol), sd = rep_len(1, ncol), seed = new.seed()) new.seed(seed = nanoTime())Runif(n, min = 0, max = 1, seed = new.seed()) Rbeta(n, alpha, beta, seed = new.seed()) Rexp(n, rate = 1, seed = new.seed()) Rchisq(n, df, seed = new.seed()) Rgamma(n, shape, rate = 1, seed = new.seed()) Rcauchy(n, location = 0, scale = 1, seed = new.seed()) Rt(n, df, ncp, seed = new.seed()) Rgeom(n, prob, seed = new.seed()) Rpareto(n, shape = 1, scale = 1, seed = new.seed()) Rfrechet(n, lambda = 1, mu = 0, sigma = 1, seed = new.seed()) Rlaplace(n, mu = 0, sigma = 1, seed = new.seed()) Rgumbel(n, mu = 0, sigma = 1, seed = new.seed()) Rarcsine(n, min = 0, max = 1, seed = new.seed()) Rnorm(n, mean = 0, sd = 1, seed = new.seed()) Runif.mat(nrow, ncol, min = 0, max = 1, seed = new.seed()) Rbeta.mat(nrow, ncol, alpha, beta, seed = new.seed()) Rexp.mat(nrow, ncol, rate = 1, seed = new.seed()) Rchisq.mat(nrow, ncol, df, seed = new.seed()) Rgamma.mat(nrow, ncol, shape, rate = 1, seed = new.seed()) Rcauchy.mat(nrow, ncol, location = 0, scale = 1, seed = new.seed()) Rt.mat(nrow, ncol, df, ncp, seed = new.seed()) Rgeom.mat(nrow, ncol, prob, seed = new.seed()) Rpareto.mat(nrow, ncol, shape = 1, scale = 1, seed = new.seed()) Rfrechet.mat(nrow, ncol, lambda = 1, mu = 0, sigma = 1, seed = new.seed()) Rlaplace.mat(nrow, ncol, mu = 0, sigma = 1, seed = new.seed()) Rgumbel.mat(nrow, ncol, mu = 0, sigma = 1, seed = new.seed()) Rarcsine.mat(nrow, ncol, min = 0, max = 1, seed = new.seed()) Rnorm.mat(nrow, ncol, mean = 0, sd = 1, seed = new.seed()) colRunif(nrow, ncol, min = rep_len(0, ncol), max = rep_len(1, ncol), seed = new.seed(), parallel = FALSE, cores = 0) colRbeta(nrow, ncol, alpha, beta, seed = new.seed()) colRexp(nrow, ncol, rate = rep_len(1, ncol), seed = new.seed()) colRchisq(nrow, ncol, df, seed = new.seed()) colRgamma(nrow, ncol, shape, rate = rep_len(1, ncol), seed = new.seed()) colRgeom(nrow, ncol, prob, seed = new.seed()) colRcauchy(nrow, ncol, location = rep_len(0, ncol), scale = rep_len(1, ncol), seed = new.seed()) colRt(nrow, ncol, df, ncp, seed = new.seed()) colRpareto(nrow, ncol, shape = rep_len(1, ncol), scale = rep_len(1, ncol), seed = new.seed()) colRfrechet(nrow, ncol, lambda = rep_len(1, ncol), mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRlaplace(nrow, ncol, mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRgumbel(nrow, ncol, mu = rep_len(0, ncol), sigma = rep_len(1, ncol), seed = new.seed()) colRarcsine(nrow, ncol, min = rep_len(0, ncol), max = rep_len(1, ncol), seed = new.seed()) colRnorm(nrow, ncol, mean = rep_len(0, ncol), sd = rep_len(1, ncol), seed = new.seed()) new.seed(seed = nanoTime())
n |
The number of values to generate. |
nrow |
The number of rows. |
ncol |
The number of columns. |
min |
The lower value. |
max |
The upper value. |
alpha |
The shape parameter alpha. |
beta |
The shape parameter beta. |
rate |
|
df |
|
lambda, shape
|
The shape parameter. |
location, mu
|
The location parameter. |
scale, sigma
|
The scale parameter. |
ncp |
The non-centrality parameter. |
prob |
The probability of success on each trial. |
seed |
For |
parallel |
|
cores |
|
mean |
Vector of means. |
sd |
Vector of standard deviations. |
Runif, Runif.mat, colRunif: generates random values from the uniform distribution, similar to R's built-in runif function. The type used is , where U is a uniform random variable in the interval (0, 1).
Rbeta, Rbeta.mat, colRbeta: generates random values from the beta distribution with parameters alpha and beta. The type used involves generating two gamma-distributed variables \( X_1 \) and \( X_2 \), and returning , where \( X_1 \) and \( X_2 \) have the shape parameters alpha and beta, respectively.
Rexp, Rexp.mat, colRexp: generates random values from the exponential distribution with the specified rate parameter. The type used is , where U is a uniform random variable in the interval (0, 1).
Rchisq, Rchisq.mat, colRchisq: generates random values from the chi-squared distribution with df degrees of freedom. The type used is the sum of the squares of df independent standard normal random variables, i.e., , where each \( Y_i \) is a standard normal random variable.
Rgamma, Rgamma.mat, colRgamma: generates random values from the gamma distribution with shape and rate parameters. The type used for shape greater than or equal to 1 is the Marsaglia and Tsang method, which involves generating a variable \( V \) and returning , where \( d \) is a function of the shape and \( V \) is derived from a normal random variable. For shape less than 1, a combination of the uniform and exponential distributions is used, involving an acceptance-rejection method.
Rcauchy, Rcauchy.mat, colRcauchy: generates random values from the Cauchy distribution with specified location and scale parameters. The type used for this is , where U is a uniform random variable.
Rt, Rt.mat, colRt: generates random values from the t-distribution with specified df degrees of freedom and an optional non-centrality parameter ncp. The type used is , where Z is a standard normal random variable and Y is a chi-squared random variable. If ncp is provided, the type used is .
Rgeom, Rgeom.mat, colRgeom: generates random values from the geometric distribution with the specified probability prob. The type used is , where U is a uniform random variable.
Rpareto, Rpareto.mat, colRpareto: generates random values from the Pareto distribution with parameters shape and scale. The type used is , where U is a uniform random variable in the interval (0, 1).
Rfrechet, Rfrechet.mat, colRfrechet: generates random values from the Frechet distribution with parameters shape, mu, and scale. The type used is , where U is a uniform random variable in (0, 1).
Rlaplace, Rlaplace.mat, colRlaplace: generates random values from the Laplace distribution with location parameter mu and scale parameter sigma. The type used is , where U is a uniform random variable in (0, 1).
Rgumbel, Rgumbel.mat, colRgumbel: generates random values from the Gumbel (type I extreme value) distribution with parameters mu and sigma. The type used is , where U is a uniform random variable in (0, 1).
Rarcsine, Rarcsine.mat, colRarcsine: generates random values from the arcsine distribution over the interval [min, max]. The type used is , where U is a uniform random variable in (0, 1).
new.seed: creates and returns a seed object of class "seed" that holds
the generator state. Its fields initialState and state can be read and
set with $. Seeding is not supported by the parallel versions of column and row sampling.
Each function, for example Runif, returns a vector with simulated values from the respective distribution.
Each function.mat, for example Runif.mat, returns a matrix with simulated values from the respective distribution.
Each colFunction, for example colRunif, returns a matrix with column major simulated values from the respective distribution.
new.seed returns an object of class "seed".
R implementation and documentation: Manos Papadakis <[email protected]>.
runif, rbeta, rexp, rchisq, rgamma, rcauchy, rt, rgeom
# Scalar draws x_unif <- Runif(5, 0, 1) x_beta <- Rbeta(5, 2, 5) x_exp <- Rexp(5, 1.5) x_chisq <- Rchisq(5, 4) x_gamma <- Rgamma(5, 2, 2) x_cauchy <- Rcauchy(5, 0, 1) x_t <- Rt(5, df = 5, ncp = 2) x_geom <- Rgeom(5, 0.5) x_pareto <- Rpareto(5, shape = 2, scale = 1) x_frechet <- Rfrechet(5, lambda = 1, mu = 0, sigma = 1) x_laplace <- Rlaplace(5, mu = 0, sigma = 1) x_gumbelt <- Rgumbel(5, mu = 0, sigma = 1) x_arcsine <- Rarcsine(5, min = 0, max = 1) x_norm <- Rnorm(5) #matrices x_unif <- Runif.mat(5,2, 0, 1) x_beta <- Rbeta.mat(5,2, 2, 5) x_exp <- Rexp.mat(5,2, 1.5) x_chisq <- Rchisq.mat(5,2, 4) x_gamma <- Rgamma.mat(5,2, 2, 2) x_cauchy <- Rcauchy.mat(5,2, 0, 1) x_t <- Rt.mat(5,2, df = 5, ncp = 2) x_geom <- Rgeom.mat(5,2, 0.5) x_pareto <- Rpareto.mat(5,2, shape = 2, scale = 1) x_frechet <- Rfrechet.mat(5,2, lambda = 1, mu = 0, sigma = 1) x_laplace <- Rlaplace.mat(5,2, mu = 0, sigma = 1) x_gumbelt <- Rgumbel.mat(5,2, mu = 0, sigma = 1) x_arcsine <- Rarcsine.mat(5,2, min = 0, max = 1) x_norm <- Rnorm.mat(5,2) # Column-wise (vectorized by column) draws x_col_unif <- colRunif(5, 2, min = c(0, 1), max = c(1, 2)) x_col_beta <- colRbeta(5, 2, alpha = c(2, 5), beta = c(5, 2)) x_col_exp <- colRexp(5, 2, rate = c(1.5, 2.0)) x_col_chisq <- colRchisq(5, 2, df = c(4, 5)) x_col_gamma <- colRgamma(5, 2, shape = c(2, 3), rate = c(2, 1)) x_col_cauchy <- colRcauchy(5, 2, location = c(0, 1), scale = c(1, 2)) x_col_t <- colRt(5, 2, df = c(5, 6), ncp = c(2, 1)) x_col_geom <- colRgeom(5, 2, prob = c(0.5, 0.3)) x_col_pareto <- colRpareto(5, 2, shape = c(2, 3), scale = c(1, 1)) x_col_frechet <- colRfrechet(5, 2, lambda = c(1, 2), mu = c(0, 0), sigma = c(1, 1)) x_col_laplace <- colRlaplace(5, 2, mu = c(0, 1), sigma = c(1, 2)) x_col_gumbel <- colRgumbel(5, 2, mu = c(0, 1), sigma = c(1, 2)) x_col_arcsine <- colRarcsine(5, 2, min = c(0, 0.5), max = c(1, 1.5)) x_col_norm <- colRnorm(5, 2)# Scalar draws x_unif <- Runif(5, 0, 1) x_beta <- Rbeta(5, 2, 5) x_exp <- Rexp(5, 1.5) x_chisq <- Rchisq(5, 4) x_gamma <- Rgamma(5, 2, 2) x_cauchy <- Rcauchy(5, 0, 1) x_t <- Rt(5, df = 5, ncp = 2) x_geom <- Rgeom(5, 0.5) x_pareto <- Rpareto(5, shape = 2, scale = 1) x_frechet <- Rfrechet(5, lambda = 1, mu = 0, sigma = 1) x_laplace <- Rlaplace(5, mu = 0, sigma = 1) x_gumbelt <- Rgumbel(5, mu = 0, sigma = 1) x_arcsine <- Rarcsine(5, min = 0, max = 1) x_norm <- Rnorm(5) #matrices x_unif <- Runif.mat(5,2, 0, 1) x_beta <- Rbeta.mat(5,2, 2, 5) x_exp <- Rexp.mat(5,2, 1.5) x_chisq <- Rchisq.mat(5,2, 4) x_gamma <- Rgamma.mat(5,2, 2, 2) x_cauchy <- Rcauchy.mat(5,2, 0, 1) x_t <- Rt.mat(5,2, df = 5, ncp = 2) x_geom <- Rgeom.mat(5,2, 0.5) x_pareto <- Rpareto.mat(5,2, shape = 2, scale = 1) x_frechet <- Rfrechet.mat(5,2, lambda = 1, mu = 0, sigma = 1) x_laplace <- Rlaplace.mat(5,2, mu = 0, sigma = 1) x_gumbelt <- Rgumbel.mat(5,2, mu = 0, sigma = 1) x_arcsine <- Rarcsine.mat(5,2, min = 0, max = 1) x_norm <- Rnorm.mat(5,2) # Column-wise (vectorized by column) draws x_col_unif <- colRunif(5, 2, min = c(0, 1), max = c(1, 2)) x_col_beta <- colRbeta(5, 2, alpha = c(2, 5), beta = c(5, 2)) x_col_exp <- colRexp(5, 2, rate = c(1.5, 2.0)) x_col_chisq <- colRchisq(5, 2, df = c(4, 5)) x_col_gamma <- colRgamma(5, 2, shape = c(2, 3), rate = c(2, 1)) x_col_cauchy <- colRcauchy(5, 2, location = c(0, 1), scale = c(1, 2)) x_col_t <- colRt(5, 2, df = c(5, 6), ncp = c(2, 1)) x_col_geom <- colRgeom(5, 2, prob = c(0.5, 0.3)) x_col_pareto <- colRpareto(5, 2, shape = c(2, 3), scale = c(1, 1)) x_col_frechet <- colRfrechet(5, 2, lambda = c(1, 2), mu = c(0, 0), sigma = c(1, 1)) x_col_laplace <- colRlaplace(5, 2, mu = c(0, 1), sigma = c(1, 2)) x_col_gumbel <- colRgumbel(5, 2, mu = c(0, 1), sigma = c(1, 2)) x_col_arcsine <- colRarcsine(5, 2, min = c(0, 0.5), max = c(1, 1.5)) x_col_norm <- colRnorm(5, 2)
Simulates random values from a Dirichlet distribution.
rdiri(n, a, b = rep(1, length(a)), seed = new.seed())rdiri(n, a, b = rep(1, length(a)), seed = new.seed())
n |
The number of observations (rows) to generate. |
a |
A numeric vector of positive concentration parameters, one per component. |
b |
A numeric vector of positive rate parameters for the underlying gamma draws, one per component. |
seed |
A seed object created by |
For each row, independent values are drawn and divided by their sum.
With the default b, the result follows a Dirichlet(a) distribution. Unequal values
in b give a scaled Dirichlet distribution, not a Dirichlet.
A matrix with n rows and length(a) columns. Each row sums to 1.
Manos Papadakis <[email protected]>.
x <- rdiri(10, c(2, 3, 5)) rowSums(x)x <- rdiri(10, c(2, 3, 5)) rowSums(x)
Simulation from a Bingham distribution using the code suggested by Kent et al. (2013).
rbing(n, lam)rbing(n, lam)
n |
Sample size. |
lam |
Eigenvalues of the diagonal symmetric matrix of the Bingham distribution. See details for more information on this. |
The user must have calculated the eigenvalues of the diagonal symmetric matrix of the Bingham distribution. The function accepts the q-1 eigenvalues only. This means, that the user must have subtracted the lowest eigenvalue from the rest and give the non zero ones. The function uses rejection sampling.
A matrix with the simulated data.
Michail Tsagris
R implementation and documentation: Michail Tsagris <[email protected]> and Manos Papadakis <[email protected]>
Kent J.T., Ganeiber A.M. and Mardia K.V. (2013). A new method to simulate the Bingham and related distributions in directional data analysis with applications. http://arxiv.org/pdf/1310.8110v1.pdf
C.J. Fallaize and T. Kypraios (2014). Exact Bayesian Inference for the Bingham Distribution. Statistics and Computing (No volum assigned yet). http://arxiv.org/pdf/1401.2894v1.pdf
x <- rbing( 100, c(1, 0.6, 0.1) ) xx <- rbing( 100, c(1, 0.6, 0.1) ) x
Simulation of random values from a Bingham distribution with any symmetric matrix.
rbingham(n, A)rbingham(n, A)
n |
Sample size. |
A |
A symmetric matrix. |
The eigenvalues of the q x q symmetric matrix A are calculated and the smallest of
them is subtracted from the rest. The q - 1 non zero eiqenvalues are then passed to
rbing. The generated data are then right multiplied by , where
V is the matrix of eigenvectors of the matrix A.
A matrix with the simulated data.
Michail Tsagris
R implementation and documentation: Michail Tsagris <[email protected]> and Manos Papadakis <[email protected]>
Kent J.T., Ganeiber A.M. and Mardia K.V. (2013). A new method to simulate the Bingham and related distributions in directional data analysis with applications. http://arxiv.org/pdf/1310.8110v1.pdf
C.J. Fallaize and T. Kypraios (2014). Exact Bayesian Inference for the Bingham Distribution. Statistics and Computing (No volum assigned yet). http://arxiv.org/pdf/1401.2894v1.pdf
A <- cov( iris[, 1:4] ) x <- rbingham(100, A) xA <- cov( iris[, 1:4] ) x <- rbingham(100, A) x
Functions to get the current time in different units.
nanoTime()nanoTime()
nanoTime: The current nanoseconds of the system.
Each function returns a numeric value.
Manos Papadakis <[email protected]>.
runif, rbeta, rexp, rchisq, rgamma, rcauchy, rt, rgeom
x <- nanoTime()x <- nanoTime()