rbnorm | R Documentation |
rbnorm()
is a function to randomly generate values from a bounded normal
(really: a scaled beta) distribution with specified mean, standard deviation, and upper/lower bounds.
I use this function to randomly generate data that we treat as interval for sake of getting
means and standard deviations, but have discernible bounds (and even skew) to teach students
about things like random sampling and central limit theorem.
rbnorm(n, mean, sd, lowerbound, upperbound, round = FALSE, seed)
n |
the number of observations to simulate |
mean |
a mean to approximate |
sd |
a standard deviation to approximate |
lowerbound |
a lower bound for the data to be generated |
upperbound |
an upper bound for the data to be generated |
round |
whether to round the values to whole integers. Defaults to FALSE |
seed |
set an optional seed |
I call it "bounded normal" when it's really a beta distribution. I'm aware of this. I took much of this code from somewhere. I forget where.
The function returns a vector of simulated data approximating the user-specified conditions.
library(tibble)
tibble(x = rbnorm(10000, 57, 14, 0, 100))
tibble(x = rbnorm(10000, 57, 14, 0, 100, round = TRUE))
tibble(x = rbnorm(10000, 57, 14, 0, 100, seed = 8675309))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.