Skip to content

Commit 4ac8c48

Browse files
kkholstbenesom
andauthored
fix(outcome_phreg): time,status variables must be in the data.frame a… (#25)
* fix(outcome_phreg): time,status variables must be in the data.frame and not only in env. * fix linter --------- Co-authored-by: Benedikt Sommer <benediktsommer92@gmail.com>
1 parent 54715ec commit 4ac8c48

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

R/Trial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ trial_simulate <- function(self, n, .niter, ...) {
819819
}
820820
xt <- lapply(xt, data.table)
821821
if (count == 0) nsim <- n * length(xt)
822-
for (i in seq_len(length(xt))) {
822+
for (i in seq_along(xt)) {
823823
## Append subject id and period variable
824824
xt[[i]][, `:=`(id = ids, num = i - 1)]
825825
}

R/outcome_models.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,15 @@ outcome_phreg <- function(data,
367367
timemod <- proc_phreg(model)
368368
model <- timemod$model
369369
if (is.null(cens.model)) {
370-
if (is.null(model)) stop(
370+
if (is.null(model)) {
371+
stop(
371372
"Need 'phreg' object (argument 'model') or specify parametric model"
372-
)
373-
fcens <- with(model, Surv(time, !status) ~ 1)
374-
cens.model <- mets::phreg(fcens, data = model.frame(model))
375-
cens.lp <- ~fcens
373+
)
374+
}
375+
fcens <- Surv(time, !status) ~ 1
376+
newd <- with(model, data.frame(time, status))
377+
cens.model <- mets::phreg(fcens, data = newd)
378+
cens.lp <- fcens
376379
}
377380
censmod <- proc_phreg(cens.model)
378381
cens.model <- censmod$model

0 commit comments

Comments
 (0)