Skip to content

Commit

Permalink
Merge pull request #5 from insightsengineering/2_fix_build
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinteractive authored Apr 28, 2023
2 parents 39f434a + 650b164 commit 397d3ee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 91 deletions.
3 changes: 0 additions & 3 deletions staged_dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@ upstream_repos:
insightsengineering/rtables:
repo: insightsengineering/rtables
host: https://github.com
insightsengineering/helios:
repo: insightsengineering/helios
host: https://github.com
downstream_repos:
28 changes: 8 additions & 20 deletions tables/cmt01.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,20 @@ adtte <- scda::synthetic_cdisc_data("rcd_2022_06_27")$adtte %>%

## Table

The model is fitted using the function `fit_coxreg_univar()` specifying the time, event and covariate in a `variables` list, as well as the `data` where these variables live.
The `summarize_coxreg()` function in `tern` takes the same `variables`, `at`, and `control` arguments that are used to fit a model using the `fit_coxreg_univar()` function - specifying the time, event and covariate in a `variables` list, and `control` and `at` with any further customizations to the model.
Note that the default confidence level is 95% but this can be customized via the `conf_level` element in `control`.

Rather than fitting the model and then tidying the output via the `broom::tidy()` function, we can directly input these three arguments into the `summarize_coxreg()` function to summarize the model fit in a table layout, building the table with our pre-processed `adtte` data set.

```{r}
model <- fit_coxreg_univar(
variables = list(
lyt <- basic_table() %>%
summarize_coxreg(variables = list(
time = "AVAL",
event = "event",
covariates = "COUNTRY"
),
data = adtte
)
```

After fitting, the model is tidied with `broom::tidy()` and then arranged in a table layout.

Note that the `conf_level` argument in the `summarize_coxreg()` call specifies the label that will be used in the table (95% is the default confidence interval used in `fit_coxreg_univar()`).
In addition, the option `multivar = TRUE` should be used to tabulate the covariate effect estimates (see further documentation by typing `?fit_coxreg_univar`).

```{r}
df <- broom::tidy(model)
lyt <- basic_table() %>%
split_rows_by("term", child_labels = "hidden") %>%
summarize_coxreg(multivar = TRUE, conf_level = 0.95)
))
build_table(lyt, df)
build_table(lyt, adtte)
```

{{< include ../session_info.qmd >}}
Expand Down
73 changes: 27 additions & 46 deletions tables/cmt02.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,25 @@ adtte <- scda::synthetic_cdisc_data("rcd_2022_06_27")$adtte %>%

## Table

The multivariate Cox Proportional Hazards model is fitted using the function `fit_coxreg_multivar()` specifying the time, event, arm and covariates in a `variables` list, as well as the `data` where these variables live.
The multivariate Cox Proportional Hazards model can be displayed in a summary table using the `summarize_coxreg` function from `tern` with the `multivar` argument set to `TRUE`.
Like the corresponding model fitting function `fit_coxreg_multivar()`, we specify the time, event, arm and covariates in a `variables` list, and any further customizations via the `control` argument.
Note that the default confidence level is 95% but this can be customized via the `conf_level` element in `control`.

```{r}
multivar_model <- fit_coxreg_multivar(
variables = list(
time = "AVAL",
event = "is_event",
arm = "ARM",
covariates = c("AGE", "BMRKR1", "BMRKR2")
),
data = adtte
)
```

After fitting, the models are tidied with `broom::tidy()` and then arranged in a table layout.

Note that the `conf_level` argument in the `summarize_coxreg()` call specifies the label that will be used in the table (95% is the default confidence interval used in `fit_coxreg_multivar()`).
We also need to use the option `multivar = TRUE` to ensure that the results are tabulated correctly (see further documentation by typing `?fit_coxreg_multivar`).
Rather than fitting the model and then tidying the output via the `broom::tidy()` function, we can directly input these three arguments into the `summarize_coxreg()` function to summarize the model fit in a table layout, building the table with our pre-processed `adtte` data set.

```{r}
df <- broom::tidy(multivar_model)
attr(df$term, which = "label") <- "Effect/Covariate Included in the Model"
result <- basic_table() %>%
split_rows_by("term", child_labels = "hidden", split_fun = drop_split_levels) %>%
append_varlabels(df, "term") %>%
summarize_coxreg(multivar = TRUE, conf_level = .95) %>%
build_table(df)
summarize_coxreg(
variables = list(
time = "AVAL",
event = "is_event",
arm = "ARM",
covariates = c("AGE", "BMRKR1", "BMRKR2")
),
multivar = TRUE
) %>%
append_topleft("Effect/Covariate Included in the Model") %>%
build_table(adtte)
result
```
Expand All @@ -80,30 +70,21 @@ adtte2 <- adtte %>%
)
```

```{r}
multivar_model2 <- fit_coxreg_multivar(
variables = list(
time = "AVAL",
event = "is_event",
arm = "ARM",
covariates = c("AGE", "BMRKR1", "BMRKR2")
),
data = adtte2
)
```

After fitting, we can proceed in the same way as in CMT2 above.
Now we can proceed in the same way as in CMT2 above.

```{r}
df2 <- broom::tidy(multivar_model2)
attr(df2$term, which = "label") <- "Effect/Covariate Included in the Model"
result <- basic_table() %>%
split_rows_by("term", child_labels = "hidden", split_fun = drop_split_levels) %>%
append_varlabels(df2, "term") %>%
summarize_coxreg(multivar = TRUE, conf_level = .95) %>%
build_table(df2)
summarize_coxreg(
variables = list(
time = "AVAL",
event = "is_event",
arm = "ARM",
covariates = c("AGE", "BMRKR1", "BMRKR2")
),
multivar = TRUE
) %>%
append_topleft("Effect/Covariate Included in the Model") %>%
build_table(adtte2)
result
```
Expand Down
35 changes: 13 additions & 22 deletions tables/cmt03.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,23 @@ adtte <- scda::synthetic_cdisc_data("rcd_2022_06_27")$adtte %>%

## Table

The separate Cox Proportional Hazards models for each covariate are fitted using the function `fit_coxreg_univar()` specifying the time and event variables and covariates in a `variables` list, as well as the `data` where these variables live.
The separate Cox Proportional Hazards models for each covariate can be fitted and summarized in a table using the `summarize_coxreg()` function in `tern`.
This function takes the same `variables`, `at`, and `control` arguments that are used to fit a model using the `fit_coxreg_univar()` function - specifying the time, event and covariate in a `variables` list, and `control` and `at` with any further customizations to the model.
Note that the default confidence level is 95% but this can be customized via the `conf_level` element in `control`.

```{r}
model <- fit_coxreg_univar(
variables = list(
time = "AVAL",
event = "event",
covariates = c("COUNTRY", "AGE")
),
data = adtte
)
```

After fitting, the models are tidied with `broom::tidy()` and then arranged in a table layout.

Note that the `conf_level` argument in the `summarize_coxreg()` call specifies the label that will be used in the table (95% is the default confidence interval used in `fit_coxreg_univar()`).
In addition, the option `multivar = TRUE` should be used to tabulate the separate covariate effect estimates (see further documentation by typing `?fit_coxreg_univar`).

```{r, results = "hide"}
df <- broom::tidy(model)
We input these three arguments into the `summarize_coxreg()` function to summarize the model fit in a table layout, and then build the table with our pre-processed `adtte` data set.

```{r}
lyt <- basic_table() %>%
split_rows_by("term", child_labels = "hidden") %>%
summarize_coxreg(multivar = TRUE, conf_level = 0.95)
summarize_coxreg(
variables = list(
time = "AVAL",
event = "event",
covariates = c("COUNTRY", "AGE")
)
)
build_table(lyt = lyt, df = df)
build_table(lyt = lyt, df = adtte)
```

{{< include ../session_info.qmd >}}
Expand Down

0 comments on commit 397d3ee

Please sign in to comment.