Skip to content

Commit

Permalink
Apply automatic stylistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 12, 2024
1 parent fd0d638 commit 98c725d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
19 changes: 10 additions & 9 deletions vignettes/jstable_competing_risk_analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

94 changes: 47 additions & 47 deletions vignettes/jstable_options.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
)
```
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
)
```

0 comments on commit 98c725d

Please sign in to comment.