Skip to content

Commit

Permalink
11 dummy data (#15)
Browse files Browse the repository at this point in the history
* add dummy data

* rename dummy data
  • Loading branch information
clarkliming authored May 7, 2024
1 parent 498ee82 commit 237c9e1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
19 changes: 19 additions & 0 deletions R/data.R
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"
29 changes: 29 additions & 0 deletions data-raw/create_dummy.R
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 added data/dummy_data.rda
Binary file not shown.
28 changes: 28 additions & 0 deletions man/dummy_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 237c9e1

Please sign in to comment.