Skip to content

Commit

Permalink
Merge pull request #63 from sl-eeper/master
Browse files Browse the repository at this point in the history
add documents for explanation on github page
  • Loading branch information
jinseob2kim authored Dec 12, 2024
2 parents d3eddc1 + a7b414f commit fd0d638
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^CRAN-RELEASE$
^\.github$
^CRAN-SUBMISSION$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ inst/doc
.Rhistory
.RData
.Ruserdata
/doc/
/Meta/
1 change: 0 additions & 1 deletion tests/testthat/test-forestcox.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ test_that("Run TableSubgroupMultiCox", {
TRUE ~ val_label
)
)
lung.label
expect_is(TableSubgroupMultiCox(Surv(time, status) ~ sex, time_eventrate = 100, data = lung), "data.frame")
expect_warning(TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100))
expect_warning(TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = lung, time_eventrate = 100, line = TRUE))
Expand Down
48 changes: 48 additions & 0 deletions vignettes/jstable_competing_risk_analysis.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "Competing risk analysis"
author: "Jinseob Kim"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
css: vignette-styles.css
vignette: >
%\VignetteIndexEntry{Competing risk analysis}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
echo = TRUE, message = F, warning = F
)
library(jstable)
library(survival)
library(dplyr)
```

# Display results of comepting risk analysis using jstable(Fine-Gray Method)

## TableSubgroupMultiCox
- 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'))
```

## 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)
cox2.display(fgfit)
```

113 changes: 113 additions & 0 deletions vignettes/jstable_options.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
title: "Introducing jstable options"
author: "Jinseob Kim"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
css: vignette-styles.css
vignette: >
%\VignetteIndexEntry{Introducing jstable options}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
echo = TRUE, message = F, warning = F
)
library(jstable)
library(survival)
library(dplyr)
```

# Introducing count_by, event options in TableSubgroupMultiCox

## 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
)
)
```

## Counting the Number of Independent Variables for Comparison
- The default option for count_by is set to NULL. By specifying an independent variable in the count_by option, the table will display the counts for each level of the independent 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 = FALSE, count_by = "sex", labeldata = lung.label)
```

## 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)
```

## 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)
```
# Introducing pairwise option

## Introducing pairwise, pairwise.showtest option in CreateTableOneJS
- 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}
CreateTableOneJS(vars = names(lung), strata = "ph.ecog", data = lung, showAllLevels = F, labeldata = lung.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. 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)
```

## 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)
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
)
```
- 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
)
```
109 changes: 109 additions & 0 deletions vignettes/vignette-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

body {
font-family: 'Roboto', sans-serif;
background-color: #fdfdfd;
color: #444;
line-height: 1.7;
margin: 0;
padding: 20px;
}


h1 {
color: #2a9d8f;
border-bottom: 2px solid #e9c46a;
padding-bottom: 10px;
margin-bottom: 20px;
font-size: 28px;
}

h2 {
color: #264653;
border-left: 4px solid #2a9d8f;
padding-left: 10px;
margin-top: 30px;
margin-bottom: 10px;
font-size: 22px;
}

h3 {
color: #e76f51;
margin-top: 20px;
font-size: 18px;
}


p {
margin: 10px 0;
font-size: 16px;
}


pre {
background-color: #f4f4f4;
border: 1px solid #ccc;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
font-family: 'Courier New', monospace;
}

code {
background-color: #f0f0f0;
padding: 2px 5px;
border-radius: 3px;
color: #d62828;
font-family: 'Courier New', monospace;
}


table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}

table th {
background-color: #264653;
color: #fff;
padding: 10px;
text-align: left;
border-bottom: 2px solid #2a9d8f;
}

table td {
padding: 10px;
border-bottom: 1px solid #ddd;
}

table tr:nth-child(even) {
background-color: #f9f9f9;
}


ul {
margin: 20px 0;
padding-left: 20px;
}

ul li {
margin-bottom: 10px;
}


blockquote {
border-left: 4px solid #2a9d8f;
background-color: #f9f9f9;
margin: 20px 0;
padding: 10px 20px;
font-style: italic;
color: #555;
}


footer {
text-align: center;
font-size: 14px;
color: #888;
margin-top: 40px;
}

0 comments on commit fd0d638

Please sign in to comment.