|
15 | 15 | # You should have received a copy of the GNU General Public License |
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
|
18 | | -#' @import tibble |
19 | | -#' @import dplyr |
| 18 | +#' @importFrom dplyr ungroup select mutate filter arrange last |
20 | 19 | NULL |
21 | 20 | #' Get Date at Which an Event Count is Reached |
22 | 21 | #' |
|
25 | 24 | #' |
26 | 25 | #' @examples |
27 | 26 | #' library(dplyr) |
| 27 | +#' library(tibble) |
| 28 | +#' |
28 | 29 | #' # Use default enrollment and calendar cut date for 50 events in Positive stratum |
29 | | -#' x <- simPWSurv(n=200, |
30 | | -#' strata = tibble::tibble(Stratum=c("Positive","Negative"), p = c(.5, .5)), |
31 | | -#' failRates = tibble::tibble(Stratum = rep(c("Positive","Negative"),2), |
32 | | -#' period = rep(1, 4), |
33 | | -#' Treatment = c(rep("Control", 2), |
34 | | -#' rep("Experimental", 2)), |
35 | | -#' duration = rep(1, 4), |
36 | | -#' rate = log(2) / c(6, 9, 9, 12) |
37 | | -#' ), |
38 | | -#' dropoutRates = tibble::tibble(Stratum = rep(c("Positive","Negative"),2), |
39 | | -#' period = rep(1, 4), |
40 | | -#' Treatment = c(rep("Control", 2), |
41 | | -#' rep("Experimental", 2)), |
42 | | -#' duration = rep(1, 4), |
43 | | -#' rate = rep(.001, 4) |
44 | | -#' ) |
45 | | -#' ) |
46 | | -#' d <- getCutDateForCount(filter(x,Stratum=="Positive"),count=50) |
47 | | -#' y <- cutData(x,cutDate=d) |
48 | | -#' table(y$Stratum,y$event) |
| 30 | +#' x <- simPWSurv( |
| 31 | +#' n = 200, |
| 32 | +#' strata = tibble(Stratum = c("Positive", "Negative"), |
| 33 | +#' p = c(.5, .5)), |
| 34 | +#' failRates = tibble(Stratum = rep(c("Positive","Negative"), 2), |
| 35 | +#' period = rep(1, 4), |
| 36 | +#' Treatment = c(rep("Control", 2), rep("Experimental", 2)), |
| 37 | +#' duration = rep(1, 4), |
| 38 | +#' rate = log(2) / c(6, 9, 9, 12)), |
| 39 | +#' dropoutRates = tibble(Stratum = rep(c("Positive", "Negative"),2), |
| 40 | +#' period = rep(1, 4), |
| 41 | +#' Treatment = c(rep("Control", 2), rep("Experimental", 2)), |
| 42 | +#' duration = rep(1, 4), |
| 43 | +#' rate = rep(.001, 4))) |
| 44 | +#' |
| 45 | +#' d <- getCutDateForCount(x %>% filter(Stratum == "Positive"), count = 50) |
| 46 | +#' |
| 47 | +#' y <- cutData(x, cutDate = d) |
| 48 | +#' table(y$Stratum, y$event) |
49 | 49 | #' |
50 | 50 | #' @return The a numeric value with the \code{cte} from the input dataset at which the targeted event count |
51 | 51 | #' is reached, or if the final event count is never reached, the final \code{cte} at which an event occurs. |
52 | 52 | #' |
53 | 53 | #' @export |
54 | 54 |
|
55 | | -getCutDateForCount <- function(x,count){ |
56 | | - y <- ungroup(x) %>% select(cte,fail) %>% filter(fail==1) %>% select(cte) %>% arrange(cte) %>% |
57 | | - mutate(eventCount=row_number()) %>% |
58 | | - subset(eventCount<=count) |
| 55 | +getCutDateForCount <- function(x, count){ |
| 56 | + y <- x %>% |
| 57 | + ungroup() %>% |
| 58 | + select(cte, fail) %>% |
| 59 | + filter(fail == 1) %>% |
| 60 | + select(cte) %>% |
| 61 | + arrange(cte) %>% |
| 62 | + mutate(eventCount = row_number()) %>% |
| 63 | + subset(eventCount <= count) |
| 64 | + |
59 | 65 | return(last(y$cte)) |
60 | 66 | } |
0 commit comments