Skip to content

Commit

Permalink
add type = "geomean"
Browse files Browse the repository at this point in the history
  • Loading branch information
stopsack committed Aug 5, 2023
1 parent cd1e332 commit 4e6e786
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions R/estimate_outcome_continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ estimate_outcome_continuous <- function(
digits = digits),
")"))
},
"geomean" = {
data %>%
dplyr::summarize(
res = format_round(
exp(mean(log(.data$.outcome))),
digits = digits))
},
"median" = {
data %>%
dplyr::summarize(res = format_round(
Expand Down
1 change: 1 addition & 0 deletions R/fill_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ fill_cells <- function(
"mean (sd)" =,
"sd" =,
"mean (ci)" =,
"geomean" =,
"median" =,
"median (iqr)" =,
"range" = "outcome_continuous",
Expand Down
3 changes: 2 additions & 1 deletion R/rifttable.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@
#' survival for censoring.
#' * \code{"medfu (iqr)"} Median and interquartile range for follow-up.
#' * \code{"maxfu"} Maximum follow-up time.
#' * \code{"mean"} Mean.
#' * \code{"mean"} Mean (arithmetic mean).
#' * \code{"mean (ci)"} Mean and 95% CI.
#' * \code{"mean (sd)"} Mean and standard deviation.
#' * \code{"geomean"} Geometric mean.
#' * \code{"median"} Median.
#' * \code{"median (iqr)"} Median and interquartile range.
#' * \code{"range"} Range: Minimum to maximum value.
Expand Down
3 changes: 2 additions & 1 deletion man/rifttable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vignettes/estimators.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ knitr::opts_chunk$set(
`type` | Description | Options (`arguments = `)
-------+-------------+--------------
`"range"` | Range: Minimum to maximum value.
`"mean"` | Mean.
`"mean"` | Mean (arithmetic mean).
`"mean (ci)"` | Mean and 95% CI.
`"mean (sd)"` | Mean and standard deviation.
`"geomean"` | Geometric mean.
`"median"` | Median.
`"median (iqr)"` | Median and interquartile range.

Expand Down
17 changes: 10 additions & 7 deletions vignettes/faq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,22 @@ Three types of ratios for continuous outcomes are implemented in `rifttable()`:

`type =` | Ratio of ... | Model | Use
-------|----------|-----------------------|-----------------------------
`"fold"` | Arithmetric means | Generalized linear model with Gaussian distribution and log link: `glm(y ~ x, family = gaussian(link = "log"))` | Tolerates `0` in the `outcome` variable. Best fit if outcome is normally distributed without transformation.
`"irrrob"` | Arithmetric means | Generalized linear model with Poisson distribution and log link: `glm(y ~ x, family = poisson())`, with robust (sandwich) standard errors | Tolerates `0` in the `outcome` variable. (Note, `stats::glm()` may issue warnings that the outcome is "non-integer." This warning can be ignored here.)
`"foldlog"` | Geometric means | Linear model with log-transformed outcome: `lm(log(y) ~ x)` | Does not tolerate `0` in the `outcome` variable, as `log(0)` is undefined (R returns `-Inf`). Best fit if outcome is normally distributed after log transformation.
`"fold"` | Arithmetric means | Generalized linear model with Gaussian distribution and log link: `glm(y ~ x, family = gaussian(link = "log"))` | Tolerates `0` in the `outcome` variable. May be informative if outcome is normally distributed without transformation.
`"irrrob"` | Arithmetric means | Generalized linear model with Poisson distribution and log link: `glm(y ~ x, family = poisson())`, with robust (sandwich) standard errors | Tolerates `0` in the `outcome` variable. May be informative if outcome is normally distributed without transformation.
`"foldlog"` | Geometric means | Linear model with log-transformed outcome: `lm(log(y) ~ x)` | Does not tolerate `0` in the `outcome` variable, as `log(0)` is undefined (R returns `-Inf`). May be informative if outcome is normally distributed after log transformation.

In all models, beta coefficients can be interpreted as ratios after exponentiation. `rifttable`()` automatically does all nessary transformations.
In all models, after exponentiation, beta coefficients can be interpreted as ratios. rifttable automatically does all necessary transformations.

In the `cancer` data (see previous question), ratios of usual (arithmetric) means of age could be considered informative, given that `hist(cancer$age)` etc. does not show a major skew in this outcome.
In the `cancer` data (see previous question), ratios of usual (arithmetic) means of age could be considered informative, given that `hist(cancer$age)` etc. does not show a major skew in this outcome.

```{r table2_ratio}
tribble(
~label, ~type,
"Observations", "total",
"Mean age", "mean",
"Mean age", "",
" Arithmetic mean", "mean",
" Geometric mean", "geomean",
"Mean ratio", "",
" Ratio of arithmetric means", "fold",
" Ratio of arithmetric means, empirical SE", "irrrob",
" Ratio of geometric means", "foldlog") %>%
Expand All @@ -350,4 +353,4 @@ tribble(
rt_gt() # obtain formatted output
```

Patients with ECOG performance status of 2, compared to those with performance status 0, are on average 8% older, based on comparing arithmetric means (9% based on geometric means).
Patients with ECOG performance status of 2, compared to those with performance status 0, are on average 8% older (or 9%, if based on geometric means).

0 comments on commit 4e6e786

Please sign in to comment.