R/return_random_participants.R
return_random_participants.Rd
There are situations (e.g. randomized monitoring) in which you may want to return a list of random participants from a secuTrial export.
return_random_participants(
x,
centres = "all",
percent = 0.1,
date = "1900-01-01",
seed = 1
)
a secuTrialdata
object
A character vector of centres for which participants should be returned. If left unspecified it will return participants for every study centre.
A number greater than 0 and smaller than 1 specifying the approximate percentage of participants to be returned per centre.
If only participants after a specific date should be considered this can be entered here. Format should be "YYYY-MM-DD" (e.g. "2011-03-26" for March 26th 2011). This date is checked against mnpvisstartdate in the casenodes table.
Allows to configure a seed for id sampling. Every centre will use a small variation of this seed.
list of two elements. First, a data.frame that contains the
random participants from each specified centre. This is performed based on a specified seed to retain
reproducibilty. Second, the configuration of the randomization (i.e. result of RNGkind()
).
If the percentage does not yield an integer for a centre the number is tranformed into an integer
under application of the ceiling()
function (i.e. it is rounded up).
# export location
expot_loc <- system.file("extdata", "sT_exports", "lnames",
"s_export_CSV-xls_CTU05_long_ref_miss_en_utf8.zip",
package = "secuTrialR")
# read export
sT_export <- read_secuTrial(expot_loc)
#> Read export successfully.
#> The following export options deviate from the suggested specifications:
#> Data from hidden fields is part of the export.
#> Short names was not selected.
# return random participants
return_random_participants(sT_export, percent = 0.25, seed = 1337, date = "2019-03-18",
centres = c("Inselspital Bern (RPACK)", "Charité Berlin (RPACK)"))
#> $participants
#> mnpaid centre mnpvisstartdate
#> 2 RPACK-INS-012 Inselspital Bern (RPACK) 2019-04-12
#> 4 RPACK-INS-014 Inselspital Bern (RPACK) 2019-04-14
#> 5 RPACK-CBE-005 Charité Berlin (RPACK) 2019-04-05
#> 3 RPACK-CBE-003 Charité Berlin (RPACK) 2019-04-03
#>
#> $rng_config
#> [1] "Mersenne-Twister" "Inversion" "Rejection"
#>