diff --git a/vignettes/jstable_competing_risk_analysis.Rmd b/vignettes/jstable_competing_risk_analysis.Rmd index 353cb49..9d4d785 100644 --- a/vignettes/jstable_competing_risk_analysis.Rmd +++ b/vignettes/jstable_competing_risk_analysis.Rmd @@ -29,20 +29,21 @@ library(dplyr) - When using the TableSubgroupMultiCox function, preprocessing the data with the finegray function from the survival package is required. The finegray function generates a new dataset containing fgstart, fgstop, fgstatus, and fgwt. The TableSubgroupMultiCox function then displays results based on the corresponding formula and weights. ```{r} data <- mgus2 -data$etime <- with(data, ifelse(pstat==0, futime, ptime)) -data$event <- with(data, ifelse(pstat==0, 2*death, 1)) -data$event <- factor(data$event, 0:2, labels=c("censor", "pcm", "death")) -data$age65<- with(data, ifelse(age >65, 1, 0)) -data$age65<- factor(data$age65) -pdata <- survival::finegray(survival::Surv(etime, event) ~ ., data=data) -TableSubgroupMultiCox(formula = Surv(fgstart, fgstop, fgstatus) ~ sex, data = pdata, var_cov = 'age', weights = 'fgwt', var_subgroups = c('age65')) +data$etime <- with(data, ifelse(pstat == 0, futime, ptime)) +data$event <- with(data, ifelse(pstat == 0, 2 * death, 1)) +data$event <- factor(data$event, 0:2, labels = c("censor", "pcm", "death")) +data$age65 <- with(data, ifelse(age > 65, 1, 0)) +data$age65 <- factor(data$age65) +pdata <- survival::finegray(survival::Surv(etime, event) ~ ., data = data) +TableSubgroupMultiCox(formula = Surv(fgstart, fgstop, fgstatus) ~ sex, data = pdata, var_cov = "age", weights = "fgwt", var_subgroups = c("age65")) ``` ## cox2.display - As written above, preprocessing the data with finegray function is also required. By using corresponding formula and weights, cox2.display function will display table results. ```{r} -fgfit <- coxph(Surv(fgstart, fgstop, fgstatus) ~ age+sex, - weight= fgwt, data=pdata, model = T) +fgfit <- coxph(Surv(fgstart, fgstop, fgstatus) ~ age + sex, + weight = fgwt, data = pdata, model = T +) cox2.display(fgfit) ``` diff --git a/vignettes/jstable_options.Rmd b/vignettes/jstable_options.Rmd index 7aa69d5..86f394e 100644 --- a/vignettes/jstable_options.Rmd +++ b/vignettes/jstable_options.Rmd @@ -28,27 +28,27 @@ library(dplyr) ## TableSubgroupMultiCox ```{r} - lung %>% - mutate( - status = as.integer(status == 1), - sex = factor(sex), - kk = factor(as.integer(pat.karno >= 70)), - kk1 = factor(as.integer(pat.karno >= 60)), - ph.ecog = factor(ph.ecog) - ) -> lung - lung.label <- mk.lev(lung) - lung.label <- lung.label %>% - mutate( - val_label = case_when( - variable == "sex" & level == "1" ~ "Male", - variable == "sex" & level == "2" ~ "Female", - variable == "kk" & level == "0" ~ "No", - variable == "kk" & level == "1" ~ "Yes", - variable == "kk1" & level == "0" ~ "No", - variable == "kk1" & level == "1" ~ "Yes", - TRUE ~ val_label - ) +lung %>% + mutate( + status = as.integer(status == 1), + sex = factor(sex), + kk = factor(as.integer(pat.karno >= 70)), + kk1 = factor(as.integer(pat.karno >= 60)), + ph.ecog = factor(ph.ecog) + ) -> lung +lung.label <- mk.lev(lung) +lung.label <- lung.label %>% + mutate( + val_label = case_when( + variable == "sex" & level == "1" ~ "Male", + variable == "sex" & level == "2" ~ "Female", + variable == "kk" & level == "0" ~ "No", + variable == "kk" & level == "1" ~ "Yes", + variable == "kk1" & level == "0" ~ "No", + variable == "kk1" & level == "1" ~ "Yes", + TRUE ~ val_label ) + ) ``` ## Counting the Number of Independent Variables for Comparison @@ -60,13 +60,13 @@ TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), ## Calculate crude incidence rate of event - The default value for the event option is set to FALSE. By setting event to TRUE, the table will display the crude incidence rate of events. This rate is calculated using the number of events as the numerator and the count of the independent variable as the denominator.(Different from Kaplan-Meier Estimates) ```{r} -TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100, line = TRUE, cluster = "inst", strata = "inst", weights = "age", event = TRUE, count_by = "sex", labeldata = lung.label) +TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100, line = TRUE, cluster = "inst", strata = "inst", weights = "age", event = TRUE, count_by = "sex", labeldata = lung.label) ``` ## Using both count_by and event option is also available - By using both count_by and event option, the table will display crude incidence rate and the counts for each level of the independant variable. ```{r} -TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100, line = TRUE, cluster = "inst", strata = "inst", weights = "age", event = TRUE, count_by = NULL, labeldata = lung.label) +TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100, line = TRUE, cluster = "inst", strata = "inst", weights = "age", event = TRUE, count_by = NULL, labeldata = lung.label) ``` # Introducing pairwise option @@ -77,37 +77,37 @@ CreateTableOneJS(vars = names(lung), strata = "ph.ecog", data = lung, showAllLev ``` - By setting pairwise.showtest option to TRUE, the table will display test used to calculate p-values for pairwise comparisons of stratified groups. Default test for categorical variables are chi-sq test and continuous variables are t-test. ```{r} -CreateTableOneJS(vars = names(lung), strata = "ph.ecog", data = lung, showAllLevels = F, labeldata = lung.label, Labels = T, pairwise = T, pairwise.showtest = T) +CreateTableOneJS(vars = names(lung), strata = "ph.ecog", data = lung, showAllLevels = F, labeldata = lung.label, Labels = T, pairwise = T, pairwise.showtest = T) ``` ## Introducing pairwise option in svyCreateTableOneJS - The default value for the pairwise option is FALSE. By setting pairwise to TRUE, the table will display p-values for pairwise comparisons of stratified groups. ```{r} -library(survey) +library(survey) data(nhanes) - nhanes$SDMVPSU <- as.factor(nhanes$SDMVPSU) - nhanes$race <- as.factor(nhanes$race) - nhanes$RIAGENDR <- as.factor(nhanes$RIAGENDR) - a.label <- mk.lev(nhanes) - a.label <- a.label %>% - dplyr::mutate(val_label = case_when( - variable == "race" & level == "1" ~ "White", - variable == "race" & level == "2" ~ "Black", - variable == "race" & level == "3" ~ "Hispanic", - variable == "race" & level == "4" ~ "Asian", - TRUE ~ val_label - )) - nhanesSvy <- svydesign(ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~WTMEC2YR, nest = TRUE, data = nhanes) - - svyCreateTableOneJS( - vars = c("HI_CHOL", "race", "agecat", "RIAGENDR"), - strata = "race", data = nhanesSvy, factorVars = c("HI_CHOL", "race", "RIAGENDR"), labeldata = a.label, Labels = T, pairwise = T - ) +nhanes$SDMVPSU <- as.factor(nhanes$SDMVPSU) +nhanes$race <- as.factor(nhanes$race) +nhanes$RIAGENDR <- as.factor(nhanes$RIAGENDR) +a.label <- mk.lev(nhanes) +a.label <- a.label %>% + dplyr::mutate(val_label = case_when( + variable == "race" & level == "1" ~ "White", + variable == "race" & level == "2" ~ "Black", + variable == "race" & level == "3" ~ "Hispanic", + variable == "race" & level == "4" ~ "Asian", + TRUE ~ val_label + )) +nhanesSvy <- svydesign(ids = ~SDMVPSU, strata = ~SDMVSTRA, weights = ~WTMEC2YR, nest = TRUE, data = nhanes) + +svyCreateTableOneJS( + vars = c("HI_CHOL", "race", "agecat", "RIAGENDR"), + strata = "race", data = nhanesSvy, factorVars = c("HI_CHOL", "race", "RIAGENDR"), labeldata = a.label, Labels = T, pairwise = T +) ``` - By setting pairwise.showtest option to TRUE, the table will display test used to calculate p-values for pairwise comparisons of stratified groups. ```{r} - svyCreateTableOneJS( - vars = c("HI_CHOL", "race", "agecat", "RIAGENDR"), - strata = "race", data = nhanesSvy, factorVars = c("HI_CHOL", "race", "RIAGENDR"), labeldata = a.label, Labels = T, pairwise = T, pairwise.showtest = T - ) -``` \ No newline at end of file +svyCreateTableOneJS( + vars = c("HI_CHOL", "race", "agecat", "RIAGENDR"), + strata = "race", data = nhanesSvy, factorVars = c("HI_CHOL", "race", "RIAGENDR"), labeldata = a.label, Labels = T, pairwise = T, pairwise.showtest = T +) +```