Skip to content

Commit

Permalink
Set the random number generator type for test data
Browse files Browse the repository at this point in the history
This appears to generate the same random numbers across different
versions of R. See stack overflow post:
https://stackoverflow.com/questions/47199415/is-set-seed-consistent-over-different-versions-of-r-and-ubuntu
  • Loading branch information
amstilp committed May 14, 2024
1 parent bbde089 commit 37cb2d5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test_data/test_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ file_names <- c(
"cancer_prostate",
"family_history")

# Compatibility for using set.seed between different versions of R:
# https://stackoverflow.com/questions/47199415/is-set-seed-consistent-over-different-versions-of-r-and-ubuntu
RNGkind(
kind = "Mersenne-Twister",
normal.kind = "Inversion",
sample.kind = "Rounding"
)

# truncated normal distribution
rtnorm <- function(n, mean, sd, a = -Inf, b = Inf){
qnorm(runif(n, pnorm(a, mean, sd), pnorm(b, mean, sd)), mean, sd)
Expand Down

0 comments on commit 37cb2d5

Please sign in to comment.