I am very new to R and programming for biostatistical research. I am attempting to use the Sel_DataGen() function in the {GenEpiSim} package. In order to run the main function in the package, I need to create "a file containing seeds for each replicate in the working directory. This file is provided by the user and named ‘seed_data.txt.’"
I created the file "seed_data.txt" within my working directory, but have not figured out how to "put seeds" in it. Running the function as is results in this response:
Error in read.table("seed_data.txt", header = F) :
no lines available in input
I realize that this means that the file is empty. How can I set seeds within this folder? Additionally, does this mean that I’ll have to create a new seed file each time I run the function?
Thank you, any help is much appreciated!
>Solution :
If you are trying to use GenEpiSim::Sel_DataGen() then the example ‘seed_data.txt’ in the package contains 5 digit numbers with the following characteristics:
example_seeds <- readLines("https://raw.githubusercontent.com/SmaragdaT/GenEpi/master/GenEpiSim/seed_data.txt")
summary(as.numeric(example_seeds))
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 10019 12586 15316 15140 17929 19966
hist(as.numeric(example_seeds))

Created on 2024-01-05 with reprex v2.0.2
This appears to be a rather uniform distribution ranging from 10,000 to 20,000.
Therefore, the following should generate your required file:
nReps <- 10 # set to whatever your nReps truly are
r_seeds <- runif(nReps, 10000, 20000)
i_seeds <- round(r_seeds)
writeLines(as.character(i_seeds), "seed_data.txt")
Note that replicating the distributional characteristics of the example seeds is not necessary as any nReps number of integers would suffice.
If you wish to have reproducible results, you would only create this file once.