Learn R Programming

decisionSupport (version 1.114)

random.estimate: Generate random numbers for an estimate.

Description

This function generates random numbers for general multivariate distributions that are defined as an estimate.

Usage

# S3 method for estimate
random(rho, n, method = "calculate", relativeTolerance = 0.05, ...)

Arguments

rho

estimate: multivariate distribution to be randomly sampled.

n

integer:Number of observations to be generated.

method

character: Particular method to be used for random number generation.

relativeTolerance

numeric: the relative tolerance level of deviation of the generated confidence interval from the specified interval. If this deviation is greater than relativeTolerance a warning is given.

...

Optional arguments to be passed to the particular random number generating function.

Details

Generation of uncorrelated components

Implementation: random.estimate1d

Generation of correlated components

Implementation: rmvnorm90ci_exact

See Also

estimate, random.estimate1d, random

Examples

Run this code
variable=c("revenue","costs")
distribution=c("norm","norm")
 lower=c(10000,  5000)
 upper=c(100000, 50000)
 estimateObject<-as.estimate(variable, distribution, lower, upper)
 x<-random(rho=estimateObject, n=10000)
 apply(X=x, MARGIN=2, FUN=quantile, probs=c(0.05, 0.95))
 cor(x)
 colnames(x)
 summary(x)
 hist(x[,"revenue"])
 hist(x[,"costs"])
 
 # Create an estimate with median and method information:
 estimateObject<-estimate(         c("posnorm", "lnorm"),
                                   c(        4,       4),
                                   c(       50,      10),
                          variable=c("revenue", "costs"),
                          median = c(   "mean",      NA),
                          method = c(    "fit",      ""))
 # Sample random values for this estimate:
 x<-random(rho=estimateObject, n=10000)
 # Check the results 
 apply(X=x, MARGIN=2, FUN=quantile, probs=c(0.05, 0.95))
 summary(x)
 hist(x[,"revenue"], breaks=100)
 hist(x[,"costs"], breaks=100)
 

Run the code above in your browser using DataLab