Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I create a file containing seeds for each replicate in order to run the main function in my package?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading