We set the data in different formats. We stratified the data depending on paientโ€™s baseline treatment completion status.


#https://stackoverflow.com/questions/21964078/how-to-eliminate-na-nan-inf-in-foreign-function-call-arg-7-running-predict-w
#https://www.statology.org/error-in-do_onenmeth-na-nan-inf-in-foreign-function-call/

dt_ms_d_match_surv<-dplyr::mutate(ms_d_match_surv,id=as.numeric(id)) %>% 
  data.table()
#see example
#DT::datatable(subset(dt_ms_d_match_surv2, id %in% c(52,32,20521,21869), c("id","time", "trans","tipo_de_plan_res_1","TD_1", "TD_2", "TD_3","DWCA_1", "DWCA_2", "DWCA_3")))

dt_ms_d_match_surv_oct_2022_a<-dplyr::mutate(ms_d_match_surv_oct_2022,id=as.numeric(id))%>% 
  dplyr::mutate(cond= dplyr::case_when(trans==1 & status==1~"1", trans==2 & status==1~"2", T~ NA_character_)) %>% 
  dplyr::group_by(id) %>% 
  dplyr::mutate(cond=suppressWarnings(max(as.character(cond),na.rm=T)))%>% 
  dplyr::ungroup()%>% 
  dplyr::filter(cond=="1",!trans %in% c(1,2))%>% 
  dplyr::mutate(trans_cor= dplyr::case_when(trans==7~ 3, trans==5~ 2, T~ 1))%>% 
  data.table() 

if(no_mostrar==1){
rio::export(dt_ms_d_match_surv_oct_2022_a, "oct_2022_a.dta")
}
dt_ms_d_match_surv_oct_2022_b<-dplyr::mutate(ms_d_match_surv_oct_2022,id=as.numeric(id))%>% 
  dplyr::mutate(cond= dplyr::case_when(trans==1 & status==1~"1", trans==2 & status==1~"2", T~ NA_character_)) %>% 
  dplyr::group_by(id) %>% 
  dplyr::mutate(cond=suppressWarnings(max(as.character(cond),na.rm=T)))%>% 
  dplyr::ungroup()%>% 
  dplyr::filter(cond=="2",!trans %in% c(1,2))%>% 
  dplyr::mutate(trans_cor= dplyr::case_when(trans==8~ 3, trans==6~ 2, T~ 1))%>% 
  data.table() 
if(no_mostrar==1){
rio::export(dt_ms_d_match_surv_oct_2022_b, "oct_2022_b.dta")
}

Time for this code chunk to run: 0 minutes

if(no_mostrar==1){
rio::export(dt_ms_d_match_surv2,
paste0(sub("/SUD_CL","",getwd()),"/_mult_state_ags/five_st_msprep_apr22_long.dta"))
CONS_C1_df_dup_SEP_2020_match_miss_after_imp_conservados %>% rio::export(paste0(sub("/SUD_CL","",getwd()),"/_mult_state_ags/five_st_msprep_apr22_long_tot.dta"))
invisible("Para g-estimation")
CONS_C1_df_dup_SEP_2020_match_miss_after_imp_conservados %>% rio::export(paste0(sub("/SUD_CL","",getwd()),"/_mult_state_ags/five_st_msprep_apr22_long_tot.dta"))
}

coxphw_pwp_int<-
  coxphw(Surv(Tstart, Tstop,status) ~ tipo_de_plan_res_1*strata(trans)+  
           cluster(id), data = dt_ms_d_match_surv,template="AHR",  robust=T)

Time for this code chunk to run: 0.1 minutes

dt_ms_d_match_surv_oct_2022_a$arr_trans<- dlookr::get_transform(dt_ms_d_match_surv_oct_2022_a$arrival, "Yeo-Johnson")
dt_ms_d_match_surv_oct_2022_b$arr_trans<- dlookr::get_transform(dt_ms_d_match_surv_oct_2022_b$arrival, "Yeo-Johnson")

Time for this code chunk to run: 0.1 minutes


Sequential glimpse

5 states

library(easyalluvial)
library(parcats)
p_alluvial<-
  d_match_surv_msprep[,c(1,3:6)] %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(ifelse(is.na(.),2,.))) %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(factor(.,labels=c("ambulatory","residential","censored"),levels=c(0,1,2)))) %>% #$fct_rev(
      alluvial_wide(
                   id = "id", 
                  bin=2,
                   bin_labels = c("ambulatory", "residential"),
                  order_levels= c("ambulatory", "residential","censored"),
                   fill_by = 'first_variable',
                    NA_label = "censored",
                   col_vector_flow=c("red","grey60"),#"#cF291D",
                    #palette_qualitative() %>% palette_filter(greys = F), #,#,"#ffe6d5","#bf6f6f","#eec1ad","#d29985","#cF291D","#b50717","#a43232","","gray",
                  col_vector_value=c("#bf6f6f","#eec1ad","#d29985") ,
                  auto_rotate_xlabs = T,
                  stratum_label_size = 3,
                   colorful_fill_variable_stratum = F)+
  theme_void()
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
p_alluvial
Figure 3. Sankey Plot of Transitions by Treatment Setting

Figure 3. Sankey Plot of Transitions by Treatment Setting

# parcats::parcats(p_alluvial, marginal_histograms = F, data=  d_match_surv_msprep[,c(1,3:6)] %>% 
#   mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(ifelse(is.na(.),2,.))) %>% 
#   mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(factor(.,labels=c("ambulatory","residential","censored"),levels=c(0,1,2)))), 
#                  labelfont = list(size = 12, color = "black"),
#                width = 840, height = 672)#, height=1600,width=1600) 672  480

Time for this code chunk to run: 0 minutes


alluvial_long(data.frame(dt_ms_d_match_surv %>% dplyr::mutate(tipo_de_plan_res=factor(tipo_de_plan_res, labels=c("ambulatory", "residential")))), 
              key=from,
              id= id, 
              value= tipo_de_plan_res, 
              fill_by="first_variable",
              NA_label = "censored", 
              complete=F,
              bin=2, 
              stratum_label_size=2,
              stratum_width=1/4,
              bin_labels = c("ambulatory", "residential"),
              col_vector_flow=c("red","yellow"),
              col_vector_value=c("#bf6f6f","#eec1ad","gray60") )+
  theme_void()
Figure 4. Sankey Plot of Transitions by Treatment Setting

Figure 4. Sankey Plot of Transitions by Treatment Setting

Time for this code chunk to run: 0.1 minutes

library(ggrepel)
library(ggalluvial)

plot_flow_alluvial<-
ggplot(data.frame(dt_ms_d_match_surv %>% dplyr::mutate(tipo_de_plan_res=factor(tipo_de_plan_res, labels=c("ambulatory", "residential"))) ), #requiere long %>% dplyr::filter(trans==1)
       aes(x = from, stratum = tipo_de_plan_res, alluvium = id,
            fill = tipo_de_plan_res)) +
  ggalluvial::geom_lode() + 
  geom_flow(curve_type = "cubic") +
  geom_stratum(alpha = 0) +
  theme_void()+
  scale_fill_manual(name="Treatment\nSetting", values=c('lightblue','gray70'))

set.seed(42)
plot_flow_alluvial2<-
  plot_flow_alluvial+
  geom_text_repel(stat = "flow",
            aes(label = scales::percent(after_stat(prop),accuracy = 1)),#hjust = (after_stat(flow) == "to"),
            size = 3,
            box.padding = unit(0.75, "lines"),
            show.legend=F,
            arrow = arrow(length = unit(0.005, "npc")))
plot_flow_alluvial2

ggsave(paste0(path,"/_mult_state_ags/Fig_plan_alt.jpg"), 
       plot_flow_alluvial2, width = 9, height = 11, dpi = 600, units= "in")

#C:\Users\CISS Fondecyt\Mi unidad\Alvacast\Matching\graphs

Time for this code chunk to run: 0 minutes

tab_1st_tr<-
 d_match_surv_msprep[,c(1,3:6)] %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(ifelse(is.na(.),2,.))) %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(factor(.,labels=c("ambulatory","residential","censored"),levels=c(0,1,2)))) %>% 
    #dplyr::filter(tipo_de_plan_res_3!="censored") %>% 
    dplyr::count(tipo_de_plan_res_1,tipo_de_plan_res_2) %>% 
    dplyr::filter(case_when(.[[1]] =="censored" & .[[2]] =="censored" ~ n< 0, #When y == "", x > 3
                   T ~ n>0)) %>% 
    #dplyr::filter(.[1]!="censored" & .[2]!="censored") %>% 
    dplyr::group_by(.[1]) %>% 
    dplyr::mutate(prop=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::mutate(show=paste0(format(n, big.mark=","), " (",prop,")"))

tab_2nd_tr<-
 d_match_surv_msprep[,c(1,3:6)] %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(ifelse(is.na(.),2,.))) %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(factor(.,labels=c("ambulatory","residential","censored"),levels=c(0,1,2)))) %>% 
    #dplyr::filter(tipo_de_plan_res_3!="censored") %>% 
    dplyr::count(tipo_de_plan_res_2,tipo_de_plan_res_3) %>% 
    dplyr::filter(case_when(.[[1]] =="censored" & .[[2]] =="censored" ~ n< 0, #When y == "", x > 3
                   T ~ n>0)) %>% 
    dplyr::group_by(.[1]) %>% 
    dplyr::mutate(prop=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::mutate(show=paste0(format(n, big.mark=","), " (",prop,")")) 

tab_3rd_tr<-
  d_match_surv_msprep[,c(1,3:6)] %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(ifelse(is.na(.),2,.))) %>% 
    mutate_at(vars(starts_with("tipo_de_plan_res_")), funs(factor(.,labels=c("ambulatory","residential","censored"),levels=c(0,1,2)))) %>% 
    dplyr::count(tipo_de_plan_res_3,tipo_de_plan_res_4) %>% 
    dplyr::filter(case_when(.[[1]] =="censored" & .[[2]] =="censored" ~ n< 0, #When y == "", x > 3
                   T ~ n>0)) %>% 
    #dplyr::filter(.[1]!="censored"&.[2]!="censored") %>% 
    dplyr::group_by(.[1]) %>% 
    dplyr::mutate(prop=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup()  %>% 
    dplyr::mutate(show=paste0(format(n, big.mark=","), " (",prop,")"))

combinacion_concatenacion_eventos<-
d_match_surv_msprep[,c(1,3:6)] %>% 
  tidyr::unite("4_ev", tipo_de_plan_res_1:tipo_de_plan_res_4, remove = FALSE) %>% 
  dplyr::group_by(`4_ev`) %>% 
  dplyr::summarise(n=n())


cat("Third row of the graphics")
## Third row of the graphics
comb_conc_ev2<-
combinacion_concatenacion_eventos %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>% 
    dplyr::group_by(`2_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`2_ev`,into=c("first","second"), sep="_") %>% 
    dplyr::group_by(`first`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(second!="NA")

cat("Fourth row of the graphics")
## Fourth row of the graphics
comb_conc_ev3<-
combinacion_concatenacion_eventos %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>% 
    dplyr::group_by(`3_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`3_ev`,into=c("first","second","third"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>%
    dplyr::group_by(`2_ev`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(third!="NA")

cat("Last row of the graphics")
## Last row of the graphics
comb_conc_ev4<-
combinacion_concatenacion_eventos %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>% 
    dplyr::group_by(`3_ev`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(fourth!="NA")



cbind.fill <- function(...) {
    transpoted <- lapply(list(...),t)
    transpoted_dataframe <- lapply(transpoted, as.data.table, keep.rownames=T)
    return (data.frame(t(plyr::rbind.fill(transpoted_dataframe))))                                               
} 

options(knitr.kable.NA = '')
cbind.fill(comb_conc_ev2,comb_conc_ev3,comb_conc_ev4) %>% 
  slice(-1) %>% 
  #dplyr::select(-1) %>% 
      knitr::kable(.,format = "html", format.args = list(decimal.mark = ".", big.mark = ","),
       caption = paste0("Table. Setting of readmissions and percentages by the previous one"),
       col.names = c("First\nevent","Second\nevent", "n", "%", "Concatenated\nevents", "First\nevent", "Second\nevent", "Third\nevent", "n", "%", "Concatenated\nevents","First\nevent", "Second\nevent","Third\nevent", "Fourth\nevent","n","%"),
               align =c('l',rep('c', 101)), escape=T) %>%
  kableExtra::kable_classic(bootstrap_options = c("striped", "hover"),font_size = 12) %>%
  kableExtra::add_header_above(c("Second"=5, "Third"=6, "Fouth"=7)) %>% 
  kableExtra::add_footnote("Note. 0/1 denotes Ambulatory and Residential Treatment, respectively; % denotes the percentage of the previous event", notation="none") %>% 
  kableExtra::scroll_box(width = "100%", height = "375px")
Table. Setting of readmissions and percentages by the previous one
Second
Third
Fouth
First event Second event n % Concatenated events First event Second event Third event n % Concatenated events First event Second event Third event Fourth event n %
V1 0 0 1870 17% 0_0 0 0 0 384 21% 0_0_0 0 0 0 0 74 19%
V2 0 1 759 7% 0_0 0 0 1 123 7% 0_0_0 0 0 0 1 27 7%
V3 1 0 2067 18% 0_1 0 1 0 154 20% 0_0_1 0 0 1 0 31 25%
V4 1 1 1674 15% 0_1 0 1 1 124 16% 0_0_1 0 0 1 1 13 11%
V5 1_0 1 0 0 355 17% 0_1_0 0 1 0 0 26 17%
V6 1_0 1 0 1 217 10% 0_1_0 0 1 0 1 14 9%
V7 1_1 1 1 0 305 18% 0_1_1 0 1 1 0 27 22%
V8 1_1 1 1 1 329 20% 0_1_1 0 1 1 1 26 21%
V9 1_0_0 1 0 0 0 74 21%
V10 1_0_0 1 0 0 1 28 8%
V11 1_0_1 1 0 1 0 42 19%
V12 1_0_1 1 0 1 1 35 16%
V13 1_1_0 1 1 0 0 50 16%
V14 1_1_0 1 1 0 1 41 13%
V15 1_1_1 1 1 1 0 47 14%
V16 1_1_1 1 1 1 1 80 24%
Note. 0/1 denotes Ambulatory and Residential Treatment, respectively; % denotes the percentage of the previous event

Time for this code chunk to run: 0 minutes

combinacion_concatenacion_eventos2<-
d_match_surv_msprep[,c(1,3,19:21)] %>% 
  tidyr::unite("4_ev", tipo_de_plan_res_1:TD_3, remove = FALSE) %>% 
  dplyr::group_by(`4_ev`) %>% 
  dplyr::summarise(n=n())

cat("Third row of the graphics")
## Third row of the graphics
comb2_conc_ev2<-
combinacion_concatenacion_eventos2 %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>% 
    dplyr::group_by(`2_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`2_ev`,into=c("first","second"), sep="_") %>% 
    dplyr::group_by(`first`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n))) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(second!="NA")

cat("Fourth row of the graphics")
## Fourth row of the graphics
comb2_conc_ev3<-
combinacion_concatenacion_eventos2 %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>% 
    dplyr::group_by(`3_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`3_ev`,into=c("first","second","third"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>%
    #dplyr::group_by(`2_ev`) %>% 
    dplyr::group_by(first) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n))) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(third!="NA")

cat("Last row of the graphics")
## Last row of the graphics
comb2_conc_ev4<-
combinacion_concatenacion_eventos2 %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third", "fourth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>% 
    dplyr::group_by(first) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n))) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(fourth!="NA")


options(knitr.kable.NA = '')
cbind.fill(comb2_conc_ev2,comb2_conc_ev3,comb2_conc_ev4) %>% 
  slice(-1) %>% 
  #dplyr::select(-1) %>% 
      knitr::kable(.,format = "html", format.args = list(decimal.mark = ".", big.mark = ","),
       caption = paste0("Table. Treatment completion status counts and percentages by the previous one"),
       col.names = c("Base Tr.\nSetting","Second\nevent", "n", "%", "Concatenated\nevents", "Base Tr.\nSetting", "Second\nevent", "Third\nevent", "n", "%", "Concatenated\nevents","Base Tr.\nSetting", "Second\nevent","Third\nevent", "Fourth\nevent","n","%"),
               align =c('l',rep('c', 101)), escape=T) %>%
  kableExtra::kable_classic(bootstrap_options = c("striped", "hover"),font_size = 12) %>%
  kableExtra::add_header_above(c("Second (First tr. completion status)"=5, "Third (2nd tr. completion status)"=6, "Fouth (3rd tr. completion status)"=7)) %>% 
  kableExtra::add_footnote("Note. 0/1 denotes Not-completion and Treatment Completion, respectively; % denotes the percentage of the total", notation="none") %>% 
  kableExtra::scroll_box(width = "100%", height = "375px")
Table. Treatment completion status counts and percentages by the previous one
Second (First tr. completion status)
Third (2nd tr. completion status)
Fouth (3rd tr. completion status)
Base Tr. Setting Second event n % Concatenated events Base Tr. Setting Second event Third event n % Concatenated events Base Tr. Setting Second event Third event Fourth event n %
V1 0 0 9188 82% 0_0 0 0 0 1808 16.1% 0_0_0 0 0 0 0 461 4.107%
V2 0 1 2038 18% 0_0 0 0 1 408 3.6% 0_0_0 0 0 0 1 93 0.828%
V3 1 0 7908 70% 0_1 0 1 0 290 2.6% 0_0_1 0 0 1 0 93 0.828%
V4 1 1 3318 30% 0_1 0 1 1 123 1.1% 0_0_1 0 0 1 1 34 0.303%
V5 1_0 1 0 0 2113 18.82% 0_1_0 0 1 0 0 69 0.615%
V6 1_0 1 0 1 523 4.66% 0_1_0 0 1 0 1 11 0.098%
V7 1_1 1 1 0 748 6.66% 0_1_1 0 1 1 0 15 0.134%
V8 1_1 1 1 1 357 3.18% 0_1_1 0 1 1 1 9 0.080%
V9 1_0_0 1 0 0 0 598 5.327%
V10 1_0_0 1 0 0 1 101 0.900%
V11 1_0_1 1 0 1 0 113 1.007%
V12 1_0_1 1 0 1 1 51 0.454%
V13 1_1_0 1 1 0 0 179 1.595%
V14 1_1_0 1 1 0 1 54 0.481%
V15 1_1_1 1 1 1 0 68 0.606%
V16 1_1_1 1 1 1 1 42 0.374%
Note. 0/1 denotes Not-completion and Treatment Completion, respectively; % denotes the percentage of the total

Time for this code chunk to run: 0 minutes

library(data.tree)

tree_str<-
    plyr::rbind.fill(cbind(step=1,comb_conc_ev2),cbind(step=2,comb_conc_ev3),cbind(step=3,comb_conc_ev4)) %>% dplyr::select(step, first, second, third, fourth, `3_ev`, n, perc) %>% arrange(step,desc(first), second, third, fourth) %>% dplyr::mutate(label=paste0(formatC(n,big.mark=",")," (", perc,")")) %>% 
  dplyr::mutate(`3_ev`=dplyr::case_when(step==1~paste0(first,"_",second),step==2~paste0(first,"_",second,"_",third),T~paste0(`3_ev`,"_",fourth)))


#scales::percent(358/2078,accuracy = 1)รค
 traveller <- Node$new("Admission")
route1 <- traveller$AddChild(paste0("1st  tr., Residential: ",format(dim(d_match_surv_msprep)[1]/2,big.mark=","),"(50%)"))
route0 <- traveller$AddChild(paste0("1st  tr., Ambulatory: ",format(dim(d_match_surv_msprep)[1]/2,big.mark=","),"(50%)"))

#step 1
route10 <-route1$AddChild(paste0("2nd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_0",select="label")))
route11 <-route1$AddChild(paste0("2nd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_1",select="label")))
route00 <- route0$AddChild(paste0("2nd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_0",select="label")))
route01 <- route0$AddChild(paste0("2nd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_1",select="label")))

#step 2
route100<-route10$AddChild(paste0("3rd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_0_0",select="label")))
route101<-route10$AddChild(paste0("3rd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_0_1",select="label")))
route110<-route11$AddChild(paste0("3rd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_1_0",select="label")))
route111<-route11$AddChild(paste0("3rd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_1_1",select="label")))
route000<-route00$AddChild(paste0("3rd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_0_0",select="label")))
route001<-route00$AddChild(paste0("3rd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_0_1",select="label")))
route010<-route01$AddChild(paste0("3rd  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_1_0",select="label")))
route011<-route01$AddChild(paste0("3rd  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_1_1",select="label")))

#step 3
route100$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_0_0_0",select="label")))
route100$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_0_0_1",select="label")))
route101$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_0_1_0",select="label")))
route101$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_0_1_1",select="label")))
route110$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_1_0_0",select="label")))
route110$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_1_0_1",select="label")))
route111$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="1_1_1_0",select="label")))
route111$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="1_1_1_1",select="label")))

route000$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_0_0_0",select="label")))
route000$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_0_0_1",select="label")))
route001$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_0_1_0",select="label")))
route001$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_0_1_1",select="label")))
route010$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_1_0_0",select="label")))
route010$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_1_0_1",select="label")))
route011$AddChild(paste0("4th  tr., Ambulatory: ",subset(tree_str,subset=`3_ev`=="0_1_1_0",select="label")))
route011$AddChild(paste0("4th  tr., Residential: ",subset(tree_str,subset=`3_ev`=="0_1_1_1",select="label")))

SetGraphStyle(traveller, rankdir = "LR")
plot(traveller)

Figure 6. Tree diagram of counts and total proportions of Type of Plan from the first to the fourth treatment

library(rsvg)
library(DiagrammeRsvg)
plot(traveller) %>%
    export_svg %>% charToRaw %>% rsvg_pdf(paste0(path,"/_mult_state_ags/_flowchart_transition_22.pdf"))
plot(traveller) %>%
    export_svg %>% charToRaw %>% rsvg_png(paste0(path,"/_mult_state_ags/_flowchart_transition_22.png"))

Time for this code chunk to run: 0 minutes

9 states

Incidence rates:

#https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/%22event%22+%22jos%C3%A9%22/FMfcgzGkXwLJKPwsCJJNSWTlgGlPQqKk
#info with jose

comp_status_readmission_setting_oct2022_1 <-
  irrs(x="tipo_de_plan_res_1", 
                              y="TD_status",# 2021-04-06, 
                              z="TD_time", 
                              db="d_match_surv_msprep_oct_2022")

bind_rows(
biostat3::survRate(Surv(TD_time, TD_status) ~ tipo_de_plan_res_1, data=d_match_surv_msprep_oct_2022),
cbind(1,data.table(biostat3::survRate(Surv(TD_time, TD_status) ~ 1, data=d_match_surv_msprep_oct_2022), keep.rownames = T))
)%>% 
  dplyr::select(-V1, -rn) %>% 
  dplyr::mutate_at(4:6,~.*1e4) %>% 
  dplyr::mutate(tipo_de_plan_res_1= dplyr::case_when(tipo_de_plan_res_1==0~ "Ambulatory",tipo_de_plan_res_1==1~ "Residential", T~ "Total")) %>% 
  knitr::kable( col.names= c("Setting", "tstop", "event", "rate (per 10,000)", "lower", "upper"))%>%
  kableExtra::kable_classic()
Setting tstop event rate (per 10,000) lower upper
Ambulatory 17702840 2038 1.151228 1.101784 1.202319
Residential 16713796 3318 1.985186 1.918207 2.053908
Total 34416636 5356 1.556224 1.514823 1.598470

Time for this code chunk to run: 0.1 minutes

#https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/%22event%22+%22jos%C3%A9%22/FMfcgzGkXwLJKPwsCJJNSWTlgGlPQqKk
#info with jose

comp_status_readmission_setting_oct2022_2 <-
  irrs(x="tipo_de_plan_res_1", 
                              y="DWCA_status",# 2021-04-06, 
                              z="DWCA_time", 
                              db="d_match_surv_msprep_oct_2022")

bind_rows(
biostat3::survRate(Surv(DWCA_time, DWCA_status) ~ tipo_de_plan_res_1, data=d_match_surv_msprep_oct_2022),
cbind(1,data.table(biostat3::survRate(Surv(DWCA_time, DWCA_status) ~ 1, data=d_match_surv_msprep_oct_2022), keep.rownames = T))
)%>% 
  dplyr::select(-V1, -rn) %>% 
  dplyr::mutate_at(4:6,~.*1e4) %>% 
  dplyr::mutate(tipo_de_plan_res_1= dplyr::case_when(tipo_de_plan_res_1==0~ "Ambulatory",tipo_de_plan_res_1==1~ "Residential", T~ "Total")) %>% 
  knitr::kable( col.names= c("Setting", "tstop", "event", "rate (per 10,000)", "lower", "upper"))%>%
  kableExtra::kable_classic()
Setting tstop event rate (per 10,000) lower upper
Ambulatory 7870859 7203 9.151479 8.941344 9.365305
Residential 11297554 5864 5.190504 5.058495 5.325087
Total 19168413 13067 6.816944 6.700556 6.934846

Time for this code chunk to run: 0.1 minutes

#https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/%22event%22+%22jos%C3%A9%22/FMfcgzGkXwLJKPwsCJJNSWTlgGlPQqKk
#info with jose

comp_status_readmission_setting_oct2022_3 <-
  irrs(x="tipo_de_plan_res_1", 
                              y="Readmission_status",# 2021-04-06, 
                              z="Readmission_time", 
                              db="d_match_surv_msprep_oct_2022")

bind_rows(
biostat3::survRate(Surv(Readmission_time, Readmission_status) ~ tipo_de_plan_res_1, data=d_match_surv_msprep_oct_2022),
cbind(1,data.table(biostat3::survRate(Surv(Readmission_time, Readmission_status) ~ 1, data=d_match_surv_msprep_oct_2022), keep.rownames = T))
)%>% 
  dplyr::select(-V1, -rn) %>% 
  dplyr::mutate_at(4:6,~.*1e4) %>% 
  dplyr::mutate(tipo_de_plan_res_1= dplyr::case_when(tipo_de_plan_res_1==0~ "Ambulatory",tipo_de_plan_res_1==1~ "Residential", T~ "Total")) %>% 
  knitr::kable( col.names= c("Setting", "tstop", "event", "rate (per 10,000)", "lower", "upper"))%>%
  kableExtra::kable_classic()
Setting tstop event rate (per 10,000) lower upper
Ambulatory 20402990 413 0.2024213 0.1833674 0.2229173
Residential 21324649 1105 0.5181797 0.4880737 0.5496567
Total 41727639 1518 0.3637877 0.3457153 0.3825596

Time for this code chunk to run: 0.1 minutes


library(ggrepel)
library(ggalluvial)
## Warning: package 'ggalluvial' was built under R version 4.0.5
combinacion_concatenacion_eventos_oct_2022<-
d_match_surv_msprep_oct_2022[,c("tipo_de_plan_res_1", "TD_status", "DWCA_status", "Readmission_status", "Readmissionb_status", "Readmission2_status", "Readmission2b_status", "Readmission3_status", "Readmission3b_status")] %>% 
  dplyr::mutate(TD_status= dplyr::case_when(DWCA_status==1~2, TD_status==0 & DWCA_status==0~ NA_real_, T~ TD_status)) %>% 
  dplyr::mutate(Readmission_status= dplyr::case_when(Readmissionb_status==1 & Readmission_status==0~ 1, Readmissionb_status==0 & Readmission_status==0~ NA_real_, T~ Readmission_status)) %>% 
  dplyr::mutate(Readmission2_status= dplyr::case_when(Readmission2b_status==1 & Readmission2_status==0~ 1, Readmission2b_status==0 & Readmission2_status==0~ NA_real_, T~ Readmission2_status)) %>% 
  dplyr::mutate(Readmission3_status= dplyr::case_when(Readmission3b_status==1 & Readmission3_status==0~ 1, Readmission3b_status==0 & Readmission3_status==0~ NA_real_, T~ Readmission3_status)) %>% 
  dplyr::select(-DWCA_status, -Readmissionb_status, -Readmission2b_status, - Readmission3b_status)%>% 
  tidyr::unite("5_ev", tipo_de_plan_res_1:Readmission3_status , remove = FALSE) %>% 
  dplyr::group_by(`5_ev`) %>% 
  dplyr::summarise(n=n())


set.seed(42)
plot_alluvial_9s<-
combinacion_concatenacion_eventos_oct_2022 %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third", "fourth", "fifth"), sep="_") %>% 
  #is_alluvia_form(as.data.frame(.), axes = 1:5, silent = TRUE) %>% 
  dplyr::mutate(first=dplyr::case_when(first==0~ "Ambulatory", first==1~ "Residential", T~"Censored"), second=dplyr::case_when(second==2~ "Complete\ntr.", second==1~ "Non-Complete\ntr.", T~"Cens.")) %>% 
    dplyr::mutate(third= dplyr::case_when(third==1~"Readmission",T~"Cens.")) %>%
  dplyr::mutate(fourth= dplyr::case_when(fourth==1~"2nd\nReadm",T~"Cens."))%>%
  dplyr::mutate(fifth= dplyr::case_when(fifth==1~ "3rd Readm",T~"Cens.")) %>%
  ggplot(aes(y= n, axis1= first, axis2= second, axis3= third, axis4= fourth, axis5= fifth))+
    scale_x_discrete(limits = c("first","second", "third", "fourth", "fifth"), expand = c(.2, .05)) +
  xlab("State") +
  geom_alluvium(aes(fill = first)) +
  geom_stratum(alpha=.65, size=0, width = .7)+
  geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
  theme_void()+
 theme(#legend.position="right",
   legend.position=c(1.03,.5),
       legend.justification="right", 
       legend.box.spacing = unit(0, "pt"),# The spacing between the plotting area and the legend box (unit)
        legend.margin = margin(0, 0, 0, 0, "cm"),
        #legend.margin = margin(0.2, 0.2, 0.2, 0.2, "cm"),
        legend.box.margin=margin(0,0,0,0)) +
   scale_fill_manual(name="Treatment\nSetting", values=c('lightblue','gray70'))+
  theme(plot.margin = margin(0,1.0,0,-1.1, "cm"))
  # geom_text_repel(stat = "flow",
  #           aes(label = scales::percent(after_stat(prop),accuracy = 1)),#hjust = 
  #           size = 4,
  #           box.padding = unit(0.75, "lines"),
  #           show.legend=F,
  #           arrow = arrow(length = unit(0.005, "npc")))
plot_alluvial_9s
## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.
## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.

## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.
Figure 5. Sankey Plot of Transitions by Treatment Setting (9 states)

Figure 5. Sankey Plot of Transitions by Treatment Setting (9 states)

ggsave(paste0(path,"/_mult_state_ags/Fig_plan_alt_9s.jpg"), 
       plot_alluvial_9s, width = 9, height = 11, dpi = 600, units= "in")
## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.

## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.

## Warning in to_lodes_form(data = data, axes = axis_ind, discern =
## params$discern): Some strata appear at multiple axes.
#C:\Users\CISS Fondecyt\Mi unidad\Alvacast\Matching\graphs

Time for this code chunk to run: 0.5 minutes

library(data.tree)

cat("Fifth row of the graphics")
## Fifth row of the graphics
comb_conc_ev2_oct_2022<-
combinacion_concatenacion_eventos_oct_2022 %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third", "fourth", "fifth"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>% 
    dplyr::group_by(`2_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`2_ev`,into=c("first","second"), sep="_") %>% 
    dplyr::group_by(`first`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(second!="NA")

cat("Fourth row of the graphics")
## Fourth row of the graphics
comb_conc_ev3_oct_2022<-
combinacion_concatenacion_eventos_oct_2022 %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third", "fourth", "fifth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>% 
    dplyr::group_by(`3_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`3_ev`,into=c("first","second","third"), sep="_") %>% 
    tidyr::unite("2_ev", first:second, remove = FALSE) %>%
    dplyr::group_by(`2_ev`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(third!="NA")%>% 
      dplyr::group_by(first) %>% 
    dplyr::mutate(letters= row_number()) %>% 
    dplyr::ungroup() %>% 
  dplyr::arrange(letters, second, third)
#0-2/1-2 =4046 era menos que 4051 (1st readmission)
#0-1/1-1= 1518 es mayor a 1517

cat("Fifth row of the graphics")
## Fifth row of the graphics
comb_conc_ev4_oct_2022<-
combinacion_concatenacion_eventos_oct_2022 %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third", "fourth", "fifth"), sep="_") %>% 
    tidyr::unite("4_ev", first:fourth, remove = FALSE) %>% 
    dplyr::group_by(`4_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`4_ev`,into=c("first","second","third","fourth"), sep="_") %>% 
    tidyr::unite("3_ev", first:third, remove = FALSE) %>%
    dplyr::group_by(`3_ev`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(fourth!="NA")%>% 
      dplyr::group_by(first) %>% 
    dplyr::mutate(letters= row_number()) %>% 
    dplyr::ungroup() %>% 
  dplyr::arrange(letters, second, third, fourth)
#0-2 1305 Readmission2 TNC

# cbind.data.frame(comb_conc_ev4_oct_2022, letters=rep(1:4,2)) %>% 
#     dplyr::arrange(letters, second, third, fourth)
# *-2-1-1 31+96+73+247 = 447 TC to 2nd readm
# *-1-1-1 180+267+393+465 = 1305 TNC to 2nd readm

cat("Last row of the graphics")
## Last row of the graphics
comb_conc_ev5_oct_2022<-
combinacion_concatenacion_eventos_oct_2022 %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third", "fourth", "fifth"), sep="_") %>% 
    tidyr::unite("5_ev", first:fifth, remove = FALSE) %>% 
    dplyr::group_by(`5_ev`) %>%
    dplyr::summarise(n=sum(n)) %>% 
    tidyr::separate(`5_ev`,into=c("first","second","third","fourth", "fifth"), sep="_") %>% 
    tidyr::unite("4_ev", first:fourth, remove = FALSE) %>%
    dplyr::group_by(`4_ev`) %>% 
    dplyr::mutate(perc=scales::percent(n/sum(n), accuracy=1)) %>% 
    dplyr::ungroup() %>% 
    dplyr::filter(fifth!="NA")%>% 
      dplyr::group_by(first) %>% 
    dplyr::mutate(letters= row_number()) %>% 
    dplyr::ungroup() %>% 
  dplyr::arrange(letters, second, third, fourth, fifth)


tree_str_oct_2022<-
    plyr::rbind.fill(cbind(step=1,comb_conc_ev2_oct_2022),cbind(step=2,comb_conc_ev3_oct_2022),cbind(step=3,comb_conc_ev4_oct_2022),cbind(step=4,comb_conc_ev5_oct_2022))

tree_str_oct_2022<-
tree_str_oct_2022%>% dplyr::select(step, first, second, third, fourth, fifth, `4_ev`, n, perc) %>% arrange(step,desc(first), second, third, fourth, fifth) 


tree_str_oct_2022<-
tree_str_oct_2022%>% dplyr::mutate(label=paste0(formatC(n,big.mark=",")," (", perc,")"))%>% dplyr::mutate(`4_ev`=dplyr::case_when(step==1~ paste0(first,"_",second), step==2~paste0(first,"_",second,"_",third), step==3~paste0(first,"_",second,"_",third,"_",fourth), T~paste0(`4_ev`,"_",fourth)))
 
invisible(" I could make that the tree resemble to the stata graphic")

#scales::percent(358/2078,accuracy = 1)รค
 traveller_oct_2022 <- Node$new("Admission")
route_oct_2022_1 <- traveller_oct_2022$AddChild(paste0("1st treatment\nResidential:\n ",format(dim(d_match_surv_msprep_oct_2022)[1]/2,big.mark=","),"(50%)"))
route_oct_2022_0 <- traveller_oct_2022$AddChild(paste0("1st treatment\nAmbulatory:\n ",format(dim(d_match_surv_msprep_oct_2022)[1]/2,big.mark=","),"(50%)"))

#plot(traveller_oct_2022)
#rm(list=ls(pattern="^route_oct_2022_"))

#step 1
route_oct_2022_11 <-route_oct_2022_1$AddChild(paste0("1st  treatment\nCompletion:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_1",select="label")))
route_oct_2022_12 <-route_oct_2022_1$AddChild(paste0("1st  treatment\nNon-Completion:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_2",select="label")))
route_oct_2022_01 <-route_oct_2022_0$AddChild(paste0("1st  treatment\nCompletion:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_1",select="label")))
route_oct_2022_02 <-route_oct_2022_0$AddChild(paste0("1st  treatment\nNon-Completion:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_2",select="label")))

#step 2
route_oct_2022_111<-route_oct_2022_11$AddChild(paste0("1st Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_1_1",select="label")))
route_oct_2022_121<-route_oct_2022_12$AddChild(paste0("1st Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_2_1",select="label")))
route_oct_2022_011<-route_oct_2022_01$AddChild(paste0("1st Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_1_1",select="label")))
route_oct_2022_021<-route_oct_2022_02$AddChild(paste0("1st Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_2_1",select="label")))

#step 3
route_oct_2022_1111<-route_oct_2022_111$AddChild(paste0("2nd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_1_1_1",select="label")))
route_oct_2022_1211<-route_oct_2022_121$AddChild(paste0("2nd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_2_1_1",select="label")))
route_oct_2022_0111<-route_oct_2022_011$AddChild(paste0("2nd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_1_1_1",select="label")))
route_oct_2022_0211<-route_oct_2022_021$AddChild(paste0("2nd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_2_1_1",select="label")))

#step 3
route_oct_2022_11111<-route_oct_2022_1111$AddChild(paste0("3rd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_1_1_1_1",select="label")))
route_oct_2022_12111<-route_oct_2022_1211$AddChild(paste0("3rd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="1_2_1_1_1",select="label")))
route_oct_2022_01111<-route_oct_2022_0111$AddChild(paste0("3rd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_1_1_1_1",select="label")))
route_oct_2022_02111<-route_oct_2022_0211$AddChild(paste0("3rd Readmission:\n ",subset(tree_str_oct_2022,subset=`4_ev`=="0_2_1_1_1",select="label")))


invisible("Im not sure if these are readmissions, i think theyt are, but why there are more than one casefor the 3rd step")


SetGraphStyle(traveller_oct_2022, rankdir = "LR")
plot(traveller_oct_2022)

Figure 6. Tree diagram of counts and total proportions of Type of Plan from the first to the fourth treatment

library(rsvg)
library(DiagrammeRsvg)
plot(traveller_oct_2022) %>%
    export_svg %>% charToRaw %>% rsvg_pdf(paste0(path,"/_mult_state_ags/_flowchart_transition_22oct.pdf"))
plot(traveller_oct_2022) %>%
    export_svg %>% charToRaw %>% rsvg_png(paste0(path,"/_mult_state_ags/_flowchart_transition_22oct.png"))

Time for this code chunk to run: 0 minutes


Session Info

Sys.getenv("R_LIBS_USER")
## [1] "C:/Users/CISS Fondecyt/OneDrive/Documentos/R/win-library/4.0"
if (grepl("CISS Fondecyt",rstudioapi::getSourceEditorContext()$path)==T){
    save.image("C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/mult_state_5_apr22.RData")
  } else if (grepl("andre",rstudioapi::getSourceEditorContext()$path)==T){
    save.image("C:/Users/andre/Desktop/SUD_CL/mult_state_5_apr22.RData")
  } else if (grepl("E:",rstudioapi::getSourceEditorContext()$path)==T){
    save.image("E:/Mi unidad/Alvacast/SISTRAT 2019 (github)/mult_state_5_apr22.RData")
  } else if (grepl("G:",rstudioapi::getSourceEditorContext()$path)==T){
    save.image("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/mult_state_5_apr22.RData")
  } else {
    save.image("~/mult_state_5_apr22.RData")
    path.expand("~/mult_state_5_apr22.RData")
  }

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19042)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Spanish_Chile.1252  LC_CTYPE=Spanish_Chile.1252   
## [3] LC_MONETARY=Spanish_Chile.1252 LC_NUMERIC=C                  
## [5] LC_TIME=Spanish_Chile.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] ggalluvial_0.12.3       ggrepel_0.8.2           data.tree_1.0.0        
##  [4] coxphw_4.0.2            EValue_4.1.3            DiagrammeRsvg_0.1      
##  [7] DiagrammeR_1.0.6.1.9000 rsvg_2.1.2              htmltools_0.5.1.1      
## [10] timereg_2.0.0           easyalluvial_0.3.0      parcats_0.0.2          
## [13] cluster_2.1.2           igraph_1.2.6            reshape2_1.4.4         
## [16] gridExtra_2.3           foreign_0.8-81          survMisc_0.5.5         
## [19] ggfortify_0.4.12        survminer_0.4.9         ggpubr_0.4.0           
## [22] epiR_2.0.33             forcats_0.5.1           dplyr_1.0.7            
## [25] purrr_0.3.4             readr_2.0.1             tidyr_1.1.3            
## [28] tibble_3.0.3            tidyverse_1.3.1         sf_1.0-2               
## [31] ggiraph_0.7.10          RColorBrewer_1.1-2      data.table_1.14.2      
## [34] devtools_2.4.2          usethis_2.0.1           sqldf_0.4-11           
## [37] RSQLite_2.2.8           gsubfn_0.7              proto_1.0.0            
## [40] broom_0.7.9             rbokeh_0.5.2            janitor_2.1.0          
## [43] plotly_4.9.4.1          kableExtra_1.3.4        Hmisc_4.5-0            
## [46] Formula_1.2-4           survival_3.1-12         lattice_0.20-41        
## [49] ggplot2_3.3.5           stringr_1.4.0           stringi_1.4.6          
## [52] knitr_1.33             
## 
## loaded via a namespace (and not attached):
##   [1] estimability_1.3       muhaz_1.2.6.4          coda_0.19-4           
##   [4] bit64_4.0.5            multcomp_1.4-17        rpart_4.1-15          
##   [7] generics_0.1.3         callr_3.7.0            cowplot_1.1.1         
##  [10] TH.data_1.0-10         proxy_0.4-26           chron_2.3-56          
##  [13] bit_4.0.4              tzdb_0.1.2             httpuv_1.6.2          
##  [16] webshot_0.5.2          xml2_1.3.2             lubridate_1.7.10      
##  [19] assertthat_0.2.1       gower_0.2.2            xfun_0.25             
##  [22] hms_1.1.0              jquerylib_0.1.4        promises_1.2.0.1      
##  [25] evaluate_0.14          fansi_0.4.1            dbplyr_2.1.1          
##  [28] readxl_1.3.1           quantmod_0.4.18        km.ci_0.5-2           
##  [31] DBI_1.1.1              htmlwidgets_1.5.3.9000 ellipsis_0.3.2        
##  [34] backports_1.1.7        V8_3.4.2               ggcorrplot_0.1.3      
##  [37] libcoin_1.0-8          vctrs_0.3.8            TTR_0.24.2            
##  [40] remotes_2.4.0          abind_1.4-5            cachem_1.0.6          
##  [43] withr_2.5.0            pryr_0.1.5             progressr_0.8.0       
##  [46] checkmate_2.0.0        emmeans_1.6.3          xts_0.12.1            
##  [49] prettyunits_1.1.1      rateratio.test_1.0-2   svglite_2.0.0         
##  [52] pacman_0.5.1           lazyeval_0.2.2         urca_1.3-0            
##  [55] crayon_1.4.1           crul_1.1.0             labeling_0.4.2        
##  [58] recipes_0.1.16         pkgconfig_2.0.3        units_0.7-2           
##  [61] nlme_3.1-148           pkgload_1.2.1          nnet_7.3-16           
##  [64] rlang_0.4.11           lifecycle_1.0.1        sandwich_3.0-1        
##  [67] httpcode_0.3.0         sysfonts_0.8.5         extrafontdb_1.0       
##  [70] mathjaxr_1.4-0         modelr_0.1.8           cellranger_1.1.0      
##  [73] tcltk_4.0.2            rprojroot_2.0.2        lmtest_0.9-38         
##  [76] partykit_1.2-15        showtextdb_3.0         Matrix_1.2-18         
##  [79] KMsurv_0.1-5           carData_3.0-4          boot_1.3-28           
##  [82] zoo_1.8-9              reprex_2.0.1           base64enc_0.1-3       
##  [85] ggridges_0.5.3         processx_3.5.2         png_0.1-7             
##  [88] viridisLite_0.4.1      mstate_0.3.1           KernSmooth_2.23-17    
##  [91] visNetwork_2.0.9       pander_0.6.3           blob_1.2.2            
##  [94] classInt_0.4-3         jpeg_0.1-9             rstatix_0.7.0         
##  [97] pagedown_0.16          ggsignif_0.6.3         scales_1.1.1          
## [100] memoise_2.0.0          magrittr_2.0.1         plyr_1.8.6            
## [103] hexbin_1.28.2          compiler_4.0.2         dlookr_0.6.0          
## [106] snakecase_0.11.0       cli_3.0.1              ps_1.6.0              
## [109] htmlTable_2.2.1        MASS_7.3-51.6          tidyselect_1.1.1      
## [112] biostat3_0.1.5         highr_0.9              tseries_0.10-48       
## [115] yaml_2.2.1             latticeExtra_0.6-29    grid_4.0.2            
## [118] sass_0.4.0             tools_4.0.2            parallel_4.0.2        
## [121] rio_0.5.27             rstudioapi_0.13        uuid_0.1-4            
## [124] inum_1.0-4             showtext_0.9-4         gistr_0.9.0           
## [127] prodlim_2019.11.13     farver_2.1.1           digest_0.6.25         
## [130] shiny_1.6.0            lava_1.6.9             quadprog_1.5-8        
## [133] Rcpp_1.0.7             car_3.0-11             metafor_3.0-2         
## [136] later_1.3.0            gdtools_0.2.3          httr_1.4.2            
## [139] MetaUtility_2.1.2      colorspace_1.4-1       rvest_1.0.1           
## [142] fs_1.5.0               splines_4.0.2          statmod_1.4.37        
## [145] sessioninfo_1.1.1      systemfonts_1.0.2      xtable_1.8-4          
## [148] jsonlite_1.7.2         timeDate_3043.102      testthat_3.0.4        
## [151] ipred_0.9-11           R6_2.5.1               mime_0.11             
## [154] pillar_1.7.0           reactable_0.3.0        glue_1.4.1            
## [157] fastmap_1.1.0          deSolve_1.28           flexsurv_2.2          
## [160] class_7.3-19           codetools_0.2-16       maps_3.3.0            
## [163] pkgbuild_1.2.0         mvtnorm_1.1-2          utf8_1.1.4            
## [166] bslib_0.2.5.1          numDeriv_2016.8-1.1    hrbrthemes_0.8.0      
## [169] curl_4.3               BiasedUrn_1.07         forecast_8.15         
## [172] Rttf2pt1_1.3.9         zip_2.2.0              openxlsx_4.2.4        
## [175] rmarkdown_2.11         desc_1.3.0             munsell_0.5.0         
## [178] e1071_1.7-8            fracdiff_1.5-1         haven_2.4.3           
## [181] gtable_0.3.1           extrafont_0.17
sesion_info <- devtools::session_info()
dplyr::select(
  tibble::as_tibble(sesion_info$packages),
  c(package, loadedversion, source)
) %>% 
  DT::datatable(filter = 'top', colnames = c('Row number' =1,'Variable' = 2, 'Percentage'= 3),
              caption = htmltools::tags$caption(
        style = 'caption-side: top; text-align: left;',
        '', htmltools::em('Packages')),
      options=list(
initComplete = htmlwidgets::JS(
      "function(settings, json) {",
      "$(this.api().tables().body()).css({'font-size': '80%'});",
      "}")))

Time for this code chunk to run: 0 minutes