R Under development (unstable) (2025-02-03 r87683 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(Umpire) > # set seed to ensure reproducibility > set.seed(63582) > > sm <- SurvivalModel(baseHazard = 1/5, # default 1/5 inverse years + accrual = 5, # default 5 years + followUp = 1, # default 1 years + units = 12, unitName = "months") > > sdata <- rand(sm, 100) > class(sdata) == "data.frame" [1] TRUE > all( dim(sdata) == c(100, 2) ) [1] TRUE > summary(sdata) # median raw survival == 29 months, 44 events out of 100 patients LFU Event Min. : 0.00 Mode :logical 1st Qu.:16.75 FALSE:56 Median :29.00 TRUE :44 Mean :31.39 3rd Qu.:44.25 Max. :71.00 > if(require(survival)) { + model <- survfit(Surv(LFU, Event) ~ 1, sdata) + print(model) + plot(model) + } Loading required package: survival Call: survfit(formula = Surv(LFU, Event) ~ 1, data = sdata) n events median 0.95LCL 0.95UCL [1,] 100 44 45 41 NA > > sm <- SurvivalModel(1/2, 5, 2, 12, "months") > sdata <- rand(sm, 100) > class(sdata) == "data.frame" [1] TRUE > all( dim(sdata) == c(100, 2) ) [1] TRUE > summary(sdata) # median raw survival == 29 months, 44 events out of 100 patients LFU Event Min. : 0.00 Mode :logical 1st Qu.: 8.00 FALSE:11 Median :17.00 TRUE :89 Mean :18.73 3rd Qu.:24.50 Max. :63.00 > if(require(survival)) { + model <- survfit(Surv(LFU, Event) ~ 1, sdata) + print(model) + plot(model) + } Call: survfit(formula = Surv(LFU, Event) ~ 1, data = sdata) n events median 0.95LCL 0.95UCL [1,] 100 89 17 15 20 > > ## Now test how SurvivalModel works in the CancerModel > ## return to defaults > sm <- SurvivalModel(baseHazard = 1/5, # default 1/5 inverse years + accrual = 5, # default 5 years + followUp = 1, # default 1 years + units = 12, unitName = "months") > R <- rand(sm, 200) > summary(R) LFU Event Min. : 1.00 Mode :logical 1st Qu.:15.00 FALSE:106 Median :28.00 TRUE :94 Mean :30.43 3rd Qu.:45.00 Max. :71.00 > > cm <- CancerModel("survtester", nPossible=20, nPattern=2, + SURV = function(n) rnorm(n, 0, 0.3), + survivalModel = sm) > S <- rand(cm, 200) > summary(S) CancerSubType Outcome LFU Event Min. :1.00 Bad :103 Min. : 0.00 Mode :logical 1st Qu.:1.00 Good: 97 1st Qu.: 5.00 FALSE:37 Median :2.00 Median :12.00 TRUE :163 Mean :1.53 Mean :15.94 3rd Qu.:2.00 3rd Qu.:23.25 Max. :2.00 Max. :65.00 > attach(S) > table(CancerSubType, Outcome) Outcome CancerSubType Bad Good 1 48 46 2 55 51 > detach() > if(require(survival)) { + model <- survfit(Surv(LFU, Event) ~ CancerSubType, S) + print(model) + plot(model, col=2:3) + } Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S) n events median 0.95LCL 0.95UCL CancerSubType=1 94 71 18 9 28 CancerSubType=2 106 92 11 8 14 > > ## Now test how SurvivalModel works in the ClinicalEngine > > ce <- ClinicalEngine(20, 4, TRUE, survivalModel = sm) > summary(ce) A 'CancerEngine' using the cancer model: -------------- Clinical Simulation Model (Raw), a CancerModel object constructed via: CancerModel(name = "Clinical Simulation Model (Raw)", nPossible = NP, nPattern = nClusters, HIT = hitfn, SURV = SURV, OUT = OUT, survivalModel = survivalModel, prevalence = Prevalence(isWeighted, nClusters)) Pattern prevalences: [1] 0.2585102 0.2920282 0.1668301 0.2826315 Survival effects: Min. 1st Qu. Median Mean 3rd Qu. Max. -0.85050 -0.18776 -0.07136 -0.01801 0.25903 0.65327 Outcome effects: Min. 1st Qu. Median Mean 3rd Qu. Max. -0.40705 -0.26531 -0.09070 -0.09424 0.07027 0.22813 -------------- Base expression given by: An Engine with 10 components. Altered expression given by: An Engine with 10 components. > X <- rand(ce, 200) > summary(X$clinical) CancerSubType Outcome LFU Event Min. :1.000 Bad : 80 Min. : 0.00 Mode :logical 1st Qu.:1.000 Good:120 1st Qu.:15.00 FALSE:115 Median :2.000 Median :28.00 TRUE :85 Mean :2.415 Mean :29.93 3rd Qu.:3.000 3rd Qu.:41.00 Max. :4.000 Max. :71.00 > > proc.time() user system elapsed 1.39 0.29 1.62