Created
March 21, 2018 16:33
-
-
Save arcaravaggi/bafe1982851078f9bc5b9f64d4568585 to your computer and use it in GitHub Desktop.
Function for the truncation of normal distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function for truncation of normal distribution | |
# n = number of iterations (default = 1000) | |
# m = mean | |
# s = SD/SE/CI | |
# l = lower bounds (default = -100) | |
# u = upper bounds (default = 100) | |
# r = round to x integers (default = 5) | |
tnorm <- function(n = 1000, m, s, l = -100, u = 100, r = 5) { | |
tdist <- round(rnorm(n, m, s), r) | |
tdist[tdist < l] <- l | |
tdist[tdist > u] <- u | |
tdist | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment