Skip to content

Commit

Permalink
Handle new naming scheme used by survfit()
Browse files Browse the repository at this point in the history
  • Loading branch information
chjackson committed Apr 17, 2024
1 parent 6232e16 commit 28d5fbf
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions R/summary.flexsurvmix.R
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,17 @@ ajfit_flexsurvmix <- function(x, maxt=NULL, startname="Start", B=NULL){
class(newdata[[i]]) <- class(dat[[i]]) # preserve e.g. ordered factor status
} else newdata <- NULL
statenames <- c(startname,x$evnames)

ajlong <- ajfit(x) %>%
tidyr::pivot_longer(cols = c(tidyselect::num_range("pstate.",1:nstates),
tidyselect::num_range("lower.",1:nstates),
tidyselect::num_range("upper.",1:nstates)),
names_to=c("summary","state"),
names_sep="\\.", values_to="prob") %>%
tidyr::pivot_wider(names_from="summary", values_from="prob")
dplyr::rename("pstate._s0_"="pstate..s0.", ## rename name chosen by survfit()
"lower._s0_"="lower..s0.", ## since double dot confuses names_sep
"upper._s0_"="upper..s0.") %>%
tidyr::pivot_longer(cols = c(tidyselect::starts_with("pstate."),
tidyselect::starts_with("lower."),
tidyselect::starts_with("upper.")),
names_to=c("summary","state"),
names_sep="\\.", values_to="prob") %>%
tidyr::pivot_wider(names_from="summary", values_from="prob")
ajlong$state <- as.character(factor(ajlong$state, labels=statenames))
names(ajlong)[names(ajlong)=="pstate"] <- "val"
ajlong$model <- "Aalen-Johansen"
Expand Down

0 comments on commit 28d5fbf

Please sign in to comment.