| Title: | Tables and Graphs for Generalized Estimating Equations (GEE) Model Fits |
|---|---|
| Description: | Generalized estimating equations (GEE) are a popular choice for analyzing longitudinal binary outcomes. This package provides an interface for fitting GEE, currently for logistic regression, within the 'tern' <https://cran.r-project.org/package=tern> framework (Zhu, Sabanés Bové et al., 2023) and tabulate results easily using 'rtables' <https://cran.r-project.org/package=rtables> (Becker, Waddell et al., 2023). It builds on 'geepack' <doi:10.18637/jss.v015.i02> (Højsgaard, Halekoh and Yan, 2006) for the actual GEE model fitting. |
| Authors: | Daniel Sabanés Bové [aut], Joe Zhu [aut, cre], Emily de la Rua [aut], F. Hoffmann-La Roche AG [cph, fnd] |
| Maintainer: | Joe Zhu <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.1.5 |
| Built: | 2026-05-21 03:19:44 UTC |
| Source: | https://github.com/insightsengineering/tern.gee |
tern.gee PackageCreate tables and graphs for GEE model fits.
Maintainer: Joe Zhu [email protected]
Authors:
Daniel Sabanés Bové [email protected]
Emily de la Rua [email protected]
Other contributors:
F. Hoffmann-La Roche AG [copyright holder, funder]
Useful links:
Report bugs at https://github.com/insightsengineering/tern.gee/issues
tern.gee package.Measurements of FEV1 (forced expired volume in one second) is a measure of how quickly the lungs can be emptied. Low levels of FEV1 may indicate chronic obstructive pulmonary disease (COPD).
fev_datafev_data
A tibble with 800 rows and 7 variables:
USUBJID: unique subject identifier.
AVISIT: visit number.
ARMCD: treatment, TRT or PBO.
RACE: 3-category race.
SEX: sex.
FEV1_BL: FEV1 at baseline (%).
FEV1: FEV1 at study visits.
Fit a GEE Model
fit_gee( vars = vars_gee(), data, regression = c("logistic"), cor_struct = c("unstructured", "toeplitz", "compound symmetry", "auto-regressive") )fit_gee( vars = vars_gee(), data, regression = c("logistic"), cor_struct = c("unstructured", "toeplitz", "compound symmetry", "auto-regressive") )
vars |
( |
data |
( |
regression |
( |
cor_struct |
( |
The correlation structure can be:
unstructured: No constraints are placed on the correlations.
toeplitz: Assumes a banded correlation structure, i.e. the correlation
between two time points depends on the distance between the time indices.
compound symmetry: Constant correlation between all time points.
auto-regressive: Auto-regressive order 1 correlation matrix.
Object of class tern_gee as well as specific to the kind of regression
which was used.
df <- fev_data df$AVAL <- as.integer(fev_data$FEV1 > 30) fit_gee(vars = vars_gee(arm = "ARMCD"), data = df) fit_gee(vars = vars_gee(arm = "ARMCD"), data = df, cor_struct = "compound symmetry")df <- fev_data df$AVAL <- as.integer(fev_data$FEV1 > 30) fit_gee(vars = vars_gee(arm = "ARMCD"), data = df) fit_gee(vars = vars_gee(arm = "ARMCD"), data = df, cor_struct = "compound symmetry")
Additional methods which can simplify working with the GEE result object.
## S3 method for class 'tern_gee' VarCorr(x, sigma = 1, ...) ## S3 method for class 'tern_gee' QIC(object, ...)## S3 method for class 'tern_gee' VarCorr(x, sigma = 1, ...) ## S3 method for class 'tern_gee' QIC(object, ...)
x |
( |
sigma |
an optional numeric value used as a multiplier for the
standard deviations. The default is |
... |
further optional arguments passed to other methods (none for the methods documented here). |
object |
( |
VarCorr() returns the estimated covariance matrix, and
QIC() returns the QIC value.
Extract Least Square Means from a GEE Model
lsmeans( object, conf_level = 0.95, weights = "proportional", specs = object$vars$arm, ... ) ## S3 method for class 'tern_gee_logistic' lsmeans( object, conf_level = 0.95, weights = "proportional", specs = object$vars$arm, ... )lsmeans( object, conf_level = 0.95, weights = "proportional", specs = object$vars$arm, ... ) ## S3 method for class 'tern_gee_logistic' lsmeans( object, conf_level = 0.95, weights = "proportional", specs = object$vars$arm, ... )
object |
( |
conf_level |
( |
weights |
( |
specs |
( |
... |
additional arguments for methods |
A data.frame with least-square means and contrasts. Additional
classes allow to dispatch downstream methods correctly, too.
df <- fev_data df$AVAL <- rbinom(n = nrow(df), size = 1, prob = 0.5) fit <- fit_gee(vars = vars_gee(arm = "ARMCD"), data = df) lsmeans(fit) lsmeans(fit, conf_level = 0.90, weights = "equal")df <- fev_data df$AVAL <- rbinom(n = nrow(df), size = 1, prob = 0.5) fit <- fit_gee(vars = vars_gee(arm = "ARMCD"), data = df) lsmeans(fit) lsmeans(fit, conf_level = 0.90, weights = "equal")
Functions to produce tables from a fitted GEE produced with fit_gee().
## S3 method for class 'tern_gee' as.rtable(x, type = c("coef", "cov"), ...) s_lsmeans_logistic(df, .in_ref_col) a_lsmeans_logistic(df, .in_ref_col) summarize_gee_logistic( lyt, ..., table_names = "lsmeans_logistic_summary", .stats = NULL, .formats = NULL, .indent_mods = NULL, .labels = NULL )## S3 method for class 'tern_gee' as.rtable(x, type = c("coef", "cov"), ...) s_lsmeans_logistic(df, .in_ref_col) a_lsmeans_logistic(df, .in_ref_col) summarize_gee_logistic( lyt, ..., table_names = "lsmeans_logistic_summary", .stats = NULL, .formats = NULL, .indent_mods = NULL, .labels = NULL )
x |
( |
type |
( |
... |
additional arguments for methods. |
df |
( |
.in_ref_col |
( |
lyt |
( |
table_names |
( |
.stats |
( |
.formats |
(named |
.indent_mods |
(named |
.labels |
(named |
The functions have different purposes:
as.rtable() returns either the coefficient table or the covariance matrix as an
rtables object.
s_lsmeans_logistic() returns several least square mean statistics from the GEE.
a_lsmeans_logistic() is the formatted analysis function and returns the formatted statistics.
summarize_gee_logistic() is the analyze function and returns the modified rtables layout.
as.rtable(tern_gee): Extracts the coefficient table or covariance matrix estimate from a tern_gee object.
s_lsmeans_logistic(): Statistics function which extracts estimates from a
lsmeans() data frame based on a logistic GEE model.
a_lsmeans_logistic(): Formatted Analysis function which can be further customized by calling
rtables::make_afun() on it. It is used as afun in rtables::analyze().
summarize_gee_logistic(): Analyze function for tabulating least-squares means estimates
from logistic GEE least square mean results.
library(dplyr) df <- fev_data %>% mutate(AVAL = as.integer(fev_data$FEV1 > 30)) df_counts <- df %>% select(USUBJID, ARMCD) %>% unique() lsmeans_df <- lsmeans(fit_gee(vars = vars_gee(arm = "ARMCD"), data = df)) s_lsmeans_logistic(lsmeans_df[1, ], .in_ref_col = TRUE) s_lsmeans_logistic(lsmeans_df[2, ], .in_ref_col = FALSE) basic_table() %>% split_cols_by("ARMCD") %>% add_colcounts() %>% summarize_gee_logistic( .in_ref_col = FALSE ) %>% build_table(lsmeans_df, alt_counts_df = df_counts)library(dplyr) df <- fev_data %>% mutate(AVAL = as.integer(fev_data$FEV1 > 30)) df_counts <- df %>% select(USUBJID, ARMCD) %>% unique() lsmeans_df <- lsmeans(fit_gee(vars = vars_gee(arm = "ARMCD"), data = df)) s_lsmeans_logistic(lsmeans_df[1, ], .in_ref_col = TRUE) s_lsmeans_logistic(lsmeans_df[2, ], .in_ref_col = FALSE) basic_table() %>% split_cols_by("ARMCD") %>% add_colcounts() %>% summarize_gee_logistic( .in_ref_col = FALSE ) %>% build_table(lsmeans_df, alt_counts_df = df_counts)
Set Variables to Use in GEE Model
vars_gee( response = "AVAL", covariates = c(), id = "USUBJID", arm = "ARM", visit = "AVISIT" )vars_gee( response = "AVAL", covariates = c(), id = "USUBJID", arm = "ARM", visit = "AVISIT" )
response |
( |
covariates |
( |
id |
( |
arm |
( |
visit |
( |
A list of variables that can be used as the vars argument in fit_gee().
vars_gee() vars_gee( response = "CHG", covariates = c("SEX", "RACE"), id = "SUBJID", arm = "ARMCD", visit = "AVISITN" )vars_gee() vars_gee( response = "CHG", covariates = c("SEX", "RACE"), id = "SUBJID", arm = "ARMCD", visit = "AVISITN" )