R/forest.R
make_gmr_data.RdThis function is intended to calculate and output geometric means (GM) and
geometric mean ratios (GMR) into a data.frame suitable for plotting using
the make_forestplot function.
make_gmr_data(
data,
x_var,
id_var,
by = NULL,
covariates,
labels,
ref_levels,
paired = FALSE,
var.equal = TRUE,
ci = 0.9,
sep = "\t",
digits = 3L,
silent = FALSE
)a data.frame of data provided in wide-form and expected to contain one record per individual
the variable(s) in data for which the GM and GMRs must be
calculated
the variable in data differentiating individual data
a stratification variable in data
a vector of variables in data. They are expected to
be categorical variables (either logical, character, or factor) and define
the group for which the GM and GMRs of x_var are calculated
a vector of character or expression which defines the labels
for the variables set in covariates. Expected to have the same
length as covariates
a vector of integer defining the reference level to be used
in the calculation of GMRs for the variables set in covariates.
Expected to have the same length as covariates
a logical value indicating if the results to be compared in the calculation of GMRs are paired (TRUE) or not (FALSE, default)
a logical value indicating if equal variance on the linear scale must be assumed (TRUE, default) or not (FALSE)
a numerical value between 0 and 1 defining the width of the confidence interval around the calculated GMRs
the character that separates counts from GMR + confidence interval
in the gmr_n_label output variable
the number of significant digits to apply when creating result labels (see Results)
a logical value indicating whether information messages should be shown (FALSE) or hidden (TRUE)
This function returns a data.frame with one row per variable in
covariates and level in these variables. The variables in this
data.frame are:
one of the variables defined in x_var,
one of the variables defined in covariates,
the label associated with each variables defined in
covariates; one of the label defined in labels, or, if this
argument was not defined, either the name of the variables and its 'label'
attributes in data,
one of the level of the by variable,
one of the level of the covariates variables
the number of individuals included in this particular level of
y_var and by; records with missing value of x_var are
excluded
a logical variable defining whether this particular
level of y_var is the reference for the calculation of GMRs
the GM value for this particular level of y_var and
by
the lower limit of the GM confidence interval
the upper limit of the GM confidence interval
the GM label; structured as X1 [X2, X3], where X1 is
gm, X2 is gm_lo, X3 is gm_hi, and X1, X2, and X3 are
formatted to digits significant digits
the GMR value for
this particular level of y_var and by
with respect to the reference level
the lower limit of the GMR confidence interval
the upper limit of the GMR confidence interval
the GMR label; structured as X1 [X2, X3], where X1 is
gmr, X2 is gmr_lo, X3 is gmr_hi, and X1, X2, and X3 are
formatted to digits significant digits
the GMR label with n; structured as X1 [X2, X3] n = X4,
where X1 is gmr, X2 is gmr_lo, X3 is gmr_hi, X4 is
n, and X1, X2, and X3 are formatted to digits significant
digits
y_var, y_label, and value are coerced to factors to
facilitate plotting using make_forestplot.
if (FALSE) { # \dontrun{
# Use expo dataset provided in the ggcognigen package
make_gmr_data(
data = expo,
x_var = c('CMAXSS', 'AUCSS', 'CMINSS'),
id_var = 'ID',
by = NULL,
covariates = c('AGE', 'WTKG', 'BMI', 'SEXF', 'RFCAT', 'CPCAT'),
labels = c(
expression('Age'~'(y)'),
expression('Body'~'Weight'~'(kg)'),
expression('Body'~'Mass'~'Index'~'(kg/'*m^2*')'),
expression('Sex'),
expression('Renal'~'Function'),
expression('Hepatic'~'Function')
),
ref_levels = c(2, 3, 2, 1, 1, 1),
digits = 3,
silent = TRUE
)
# same example with tidyverse syntax
expo %>%
make_gmr_data(
x_var = c(CMAXSS, AUCSS, CMINSS),
id_var = ID,
by = NULL,
covariates = c(AGE, WTKG, BMI, SEXF, RFCAT, CPCAT),
labels = c(
expression('Age'~'(y)'),
expression('Body'~'Weight'~'(kg)'),
expression('Body'~'Mass'~'Index'~'(kg/'*m^2*')'),
expression('Sex'),
expression('Renal'~'Function'),
expression('Hepatic'~'Function')
),
ref_levels = c(2, 3, 2, 1, 1, 1),
digits = 3,
silent = TRUE
)
} # }