-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#' Dummy Trial Data with Permute-Block Randomization | ||
#' | ||
#' This dataset contains the dummy trial data with permute block randomization. | ||
#' | ||
#' @format A data frame with 400 rows and 3 columns: | ||
#' \describe{ | ||
#' \item{id}{The ID of the patients.} | ||
#' \item{treatment}{The treatment assignment.} | ||
#' \item{s1}{The first stratification variable.} | ||
#' \item{s2}{The second stratification variable.} | ||
#' \item{covar}{The covariate.} | ||
#' \item{y}{The continuous response.} | ||
#' \item{y_b}{The binary response.} | ||
#' } | ||
#' | ||
#' @source The data is generated by the create_dummy.R script. | ||
#' | ||
#' @keywords dataset | ||
"dummy_data" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Create permute-block randomization dummy data | ||
|
||
library(dplyr) | ||
#' Set seed to ensure reproducibility | ||
set.seed(20240408) | ||
|
||
n <- 400 | ||
block <- c(0L, 0L, 1L, 1L) | ||
|
||
dummy_data <- tibble( | ||
s1 = sample(c("a", "b"), replace = TRUE, size = n), | ||
s2 = sample(c("c", "d"), replace = TRUE, size = n), | ||
covar = rnorm(n), | ||
id = seq_len(n) | ||
) %>% | ||
group_by(s1, s2) %>% | ||
mutate(treatment = unlist(replicate(ceiling(n() / length(block)), sample(block)))[seq_len(n())]) %>% | ||
ungroup() %>% | ||
mutate( | ||
y = covar * 0.2 + 0.4 * (s1 == "a") - 0.1 * (s2 == "c") + 0.6 * treatment + rnorm(n), | ||
y_b = ifelse(y > 0.6, 1L, 0L) | ||
) %>% | ||
mutate( | ||
s1 = factor(s1), | ||
s2 = factor(s2) | ||
) %>% | ||
select(id, treatment, s1, s2, covar, y, y_b) | ||
|
||
usethis::use_data(dummy_data) |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.