# Copyright (c) 2022 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. All rights reserved.
#
# This file is part of the simtrial program.
#
# simtrial is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#' @importFrom dplyr filter mutate select %>%
NULL
#' Cut a Dataset for Analysis at a Specified Date
#'
#' @param x a time-to-event dataset, e.g., generated by \code{simPWSurv}
#' @param cut_date date relative to start of randomization (\code{cte} from input dataset)
#' at which dataset is to be cut off for analysis
#'
#' @return A dataset ready for survival analysis
#'
#' @examples
#' # Use default enrollment and event rates and
#' # cut at calendar time 5 after start of randomization
#' library(dplyr)
#' sim_pw_surv(n = 20) %>% cut_data_by_date(5)
#'
#' @export
#'
cut_data_by_date <- function(x, cut_date){
ans <- x %>%
filter(enroll_time <= cut_date) %>%
mutate(tte = pmin(cte, cut_date) - enroll_time,
event = fail * (cte <= cut_date)) %>%
select(tte, event, Stratum, Treatment)
return(ans)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.