View source: R/distributional_uncertainty.R
drnorm | R Documentation |
Distributional random number generation (equivalent to rnorm)
drnorm(d_seed, mean = 0, sd = 1)
d_seed |
A distributional seed as returned by distributional_seed() |
mean |
vector of means of the unperturbed Gaussian distribution |
sd |
vector of standard deviations of the unperturbed Gaussian distribution |
d_seed <- distributional_seed(1000,10) qqnorm(drnorm(d_seed)) # Compare to standard normal qqnorm(rnorm(1000)) # Test whether it works for multi-dimensional data generation n <- 1000 delta <- 1.3 draw_perturbed_data <- function(n,delta){ #Set distributional seed d_seed <- distributional_seed(n,delta) #Draw from perturbed model x <- drnorm(d_seed) y <- drnorm(d_seed) c(mean(x),mean(x^2),mean(x^3),mean(y),mean(y^2),mean(x*y)) } mat <- sapply(rep(n,10000),draw_perturbed_data,delta=delta) vec <- apply(mat,1,var) # target delta^2 delta^2 # achieved delta^2 on simulated data n*vec[1]/var(rnorm(10000)) n*vec[2]/var(rnorm(10000)^2) n*vec[3]/var(rnorm(10000)^3) n*vec[4]/var(rnorm(10000)) n*vec[5]/var(rnorm(10000)^2) n*vec[6]/var(rnorm(10000)*rnorm(10000))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.