Title: | Extra Analysis Results Data Utilities |
---|---|
Description: | Create extra Analysis Results Data (ARD) summary objects. The package supplements the simple ARD functions from the 'cards' package, exporting functions to put statistical results in the ARD format. These objects are used and re-used to construct summary tables, visualizations, and written reports. |
Authors: | Daniel Sjoberg [aut, cre], Abinaya Yogasekaram [aut], Emily de la Rua [aut], F. Hoffmann-La Roche AG [cph, fnd] |
Maintainer: | Daniel Sjoberg <[email protected]> |
License: | Apache License 2.0 |
Version: | 0.2.1.9012 |
Built: | 2024-11-05 16:18:49 UTC |
Source: | https://github.com/insightsengineering/cardx |
Function takes a regression model object and calculates Wald
statistical test using aod::wald.test()
.
ard_aod_wald_test( x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ... )
ard_aod_wald_test( x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ... )
x |
regression model object |
tidy_fun |
( |
... |
arguments passed to |
data frame
lm(AGE ~ ARM, data = cards::ADSL) |> ard_aod_wald_test()
lm(AGE ~ ARM, data = cards::ADSL) |> ard_aod_wald_test()
Add variable attributes to an ARD data frame.
The label
attribute will be added for all columns, and when no label
is specified and no label has been set for a column using the label=
argument,
the column name will be placed in the label statistic.
The class
attribute will also be returned for all columns.
Any other attribute returned by attributes()
will also be added, e.g. factor levels.
## S3 method for class 'survey.design' ard_attributes(data, variables = everything(), label = NULL, ...)
## S3 method for class 'survey.design' ard_attributes(data, variables = everything(), label = NULL, ...)
data |
( |
variables |
( |
label |
(named |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_attributes( data = dclus1, variables = c(sname, dname), label = list(sname = "School Name", dname = "District Name") )
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_attributes( data = dclus1, variables = c(sname, dname), label = list(sname = "School Name", dname = "District Name") )
Function takes a regression model object and calculated ANOVA using car::Anova()
.
ard_car_anova(x, ...)
ard_car_anova(x, ...)
x |
regression model object |
... |
arguments passed to |
data frame
lm(AGE ~ ARM, data = cards::ADSL) |> ard_car_anova() glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial) |> ard_car_anova(test.statistic = "Wald")
lm(AGE ~ ARM, data = cards::ADSL) |> ard_car_anova() glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial) |> ard_car_anova(test.statistic = "Wald")
Function takes a regression model object and returns the variance inflation factor (VIF)
using car::vif()
and converts it to a ARD structure
ard_car_vif(x, ...)
ard_car_vif(x, ...)
x |
regression model object See car::vif() for details |
... |
arguments passed to |
data frame
lm(AGE ~ ARM + SEX, data = cards::ADSL) |> ard_car_vif()
lm(AGE ~ ARM + SEX, data = cards::ADSL) |> ard_car_vif()
Calculate confidence intervals for proportions.
ard_categorical_ci(data, ...) ## S3 method for class 'data.frame' ard_categorical_ci( data, variables, by = dplyr::group_vars(data), method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsoncc", "strat_wilson", "strat_wilsoncc", "agresti-coull", "jeffreys"), conf.level = 0.95, value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), strata = NULL, weights = NULL, max.iterations = 10, ... )
ard_categorical_ci(data, ...) ## S3 method for class 'data.frame' ard_categorical_ci( data, variables, by = dplyr::group_vars(data), method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsoncc", "strat_wilson", "strat_wilsoncc", "agresti-coull", "jeffreys"), conf.level = 0.95, value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), strata = NULL, weights = NULL, max.iterations = 10, ... )
data |
( |
... |
Arguments passed to methods. |
variables |
( |
by |
( |
method |
( |
conf.level |
( |
value |
( |
strata , weights , max.iterations
|
arguments passed to |
an ARD data frame
# compute CI for binary variables ard_categorical_ci(mtcars, variables = c(vs, am), method = "wilson") # compute CIs for each level of a categorical variable ard_categorical_ci(mtcars, variables = cyl, method = "jeffreys")
# compute CI for binary variables ard_categorical_ci(mtcars, variables = c(vs, am), method = "wilson") # compute CIs for each level of a categorical variable ard_categorical_ci(mtcars, variables = cyl, method = "jeffreys")
Confidence intervals for categorical variables calculated via
survey::svyciprop()
.
## S3 method for class 'survey.design' ard_categorical_ci( data, variables, by = NULL, method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), conf.level = 0.95, value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), df = survey::degf(data), ... )
## S3 method for class 'survey.design' ard_categorical_ci( data, variables, by = NULL, method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), conf.level = 0.95, value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), df = survey::degf(data), ... )
data |
( |
variables |
( |
by |
( |
method |
( |
conf.level |
( |
value |
( |
df |
( |
... |
arguments passed to |
ARD data frame
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_categorical_ci(dclus1, variables = sch.wide) ard_categorical_ci(dclus1, variables = sch.wide, value = sch.wide ~ "Yes", method = "xlogit")
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_categorical_ci(dclus1, variables = sch.wide) ard_categorical_ci(dclus1, variables = sch.wide, value = sch.wide ~ "Yes", method = "xlogit")
Compute tabulations on survey-weighted data.
The counts and proportion ("N"
, "n"
, "p"
) are calculated using survey::svytable()
,
and the standard errors and design effect ("p.std.error"
, "deff"
) are
calculated using survey::svymean()
.
The unweighted statistics are calculated with cards::ard_categorical.data.frame()
.
## S3 method for class 'survey.design' ard_categorical( data, variables, by = NULL, statistic = everything() ~ c("n", "N", "p", "p.std.error", "deff", "n_unweighted", "N_unweighted", "p_unweighted"), denominator = c("column", "row", "cell"), fmt_fn = NULL, stat_label = everything() ~ list(p = "%", p.std.error = "SE(%)", deff = "Design Effect", n_unweighted = "Unweighted n", N_unweighted = "Unweighted N", p_unweighted = "Unweighted %"), ... )
## S3 method for class 'survey.design' ard_categorical( data, variables, by = NULL, statistic = everything() ~ c("n", "N", "p", "p.std.error", "deff", "n_unweighted", "N_unweighted", "p_unweighted"), denominator = c("column", "row", "cell"), fmt_fn = NULL, stat_label = everything() ~ list(p = "%", p.std.error = "SE(%)", deff = "Design Effect", n_unweighted = "Unweighted n", N_unweighted = "Unweighted N", p_unweighted = "Unweighted %"), ... )
data |
( |
variables |
( |
by |
( |
statistic |
( |
denominator |
( |
fmt_fn |
( |
stat_label |
( |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_categorical(svy_titanic, variables = c(Class, Age), by = Survived)
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_categorical(svy_titanic, variables = c(Class, Age), by = Survived)
One-sample confidence intervals for continuous variable means and medians.
ard_continuous_ci(data, ...) ## S3 method for class 'data.frame' ard_continuous_ci( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, method = c("t.test", "wilcox.test"), ... )
ard_continuous_ci(data, ...) ## S3 method for class 'data.frame' ard_continuous_ci( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, method = c("t.test", "wilcox.test"), ... )
data |
( |
... |
arguments passed to |
variables |
( |
by |
( |
conf.level |
(scalar |
method |
( |
ARD data frame
ard_continuous_ci(mtcars, variables = c(mpg, hp), method = "wilcox.test") ard_continuous_ci(mtcars, variables = mpg, by = am, method = "t.test")
ard_continuous_ci(mtcars, variables = c(mpg, hp), method = "wilcox.test") ard_continuous_ci(mtcars, variables = mpg, by = am, method = "t.test")
One-sample confidence intervals for continuous variables' means and medians.
Confidence limits are calculated with survey::svymean()
and survey::svyquantile()
.
## S3 method for class 'survey.design' ard_continuous_ci( data, variables, by = NULL, method = c("svymean", "svymedian.mean", "svymedian.beta", "svymedian.xlogit", "svymedian.asin", "svymedian.score"), conf.level = 0.95, df = survey::degf(data), ... )
## S3 method for class 'survey.design' ard_continuous_ci( data, variables, by = NULL, method = c("svymean", "svymedian.mean", "svymedian.beta", "svymedian.xlogit", "svymedian.asin", "svymedian.score"), conf.level = 0.95, df = survey::degf(data), ... )
data |
( |
variables |
( |
by |
( |
method |
( |
conf.level |
(scalar |
df |
( |
... |
arguments passed to |
ARD data frame
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_continuous_ci(dclus1, variables = api00) ard_continuous_ci(dclus1, variables = api00, method = "svymedian.xlogit")
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_continuous_ci(dclus1, variables = api00) ard_continuous_ci(dclus1, variables = api00, method = "svymedian.xlogit")
Returns an ARD of weighted statistics using the {survey}
package.
## S3 method for class 'survey.design' ard_continuous( data, variables, by = NULL, statistic = everything() ~ c("median", "p25", "p75"), fmt_fn = NULL, stat_label = NULL, ... )
## S3 method for class 'survey.design' ard_continuous( data, variables, by = NULL, statistic = everything() ~ c("median", "p25", "p75"), fmt_fn = NULL, stat_label = NULL, ... )
data |
( |
variables |
( |
by |
( |
statistic |
( |
fmt_fn |
( |
stat_label |
( |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
The following statistics are available:
'mean', 'median', 'min', 'max', 'sum', 'var', 'sd', 'mean.std.error', 'deff', 'p##',
where 'p##' is are the percentiles and ##
is an integer between 0 and 100.
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_continuous( data = dclus1, variables = api00, by = stype )
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_continuous( data = dclus1, variables = api00, by = stype )
Compute Analysis Results Data (ARD) for dichotomous summary statistics.
## S3 method for class 'survey.design' ard_dichotomous( data, variables, by = NULL, value = cards::maximum_variable_value(data$variables[variables]), statistic = everything() ~ c("n", "N", "p", "p.std.error", "deff", "n_unweighted", "N_unweighted", "p_unweighted"), denominator = c("column", "row", "cell"), fmt_fn = NULL, stat_label = everything() ~ list(p = "%", p.std.error = "SE(%)", deff = "Design Effect", n_unweighted = "Unweighted n", N_unweighted = "Unweighted N", p_unweighted = "Unweighted %"), ... )
## S3 method for class 'survey.design' ard_dichotomous( data, variables, by = NULL, value = cards::maximum_variable_value(data$variables[variables]), statistic = everything() ~ c("n", "N", "p", "p.std.error", "deff", "n_unweighted", "N_unweighted", "p_unweighted"), denominator = c("column", "row", "cell"), fmt_fn = NULL, stat_label = everything() ~ list(p = "%", p.std.error = "SE(%)", deff = "Design Effect", n_unweighted = "Unweighted n", N_unweighted = "Unweighted N", p_unweighted = "Unweighted %"), ... )
data |
( |
variables |
( |
by |
( |
value |
(named |
statistic |
( |
denominator |
( |
fmt_fn |
( |
stat_label |
( |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
survey::svydesign(ids = ~1, data = mtcars, weights = ~1) |> ard_dichotomous(by = vs, variables = c(cyl, am), value = list(cyl = 4))
survey::svydesign(ids = ~1, data = mtcars, weights = ~1) |> ard_dichotomous(by = vs, variables = c(cyl, am), value = list(cyl = 4))
Analysis results data for paired and non-paired Cohen's D Effect Size Test
using effectsize::cohens_d()
.
ard_effectsize_cohens_d(data, by, variables, conf.level = 0.95, ...) ard_effectsize_paired_cohens_d(data, by, variables, id, conf.level = 0.95, ...)
ard_effectsize_cohens_d(data, by, variables, conf.level = 0.95, ...) ard_effectsize_paired_cohens_d(data, by, variables, id, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
conf.level |
(scalar |
... |
arguments passed to |
id |
( |
For the ard_effectsize_cohens_d()
function, the data is expected to be one row per subject.
The data is passed as effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)
.
For the ard_effectsize_paired_cohens_d()
function, the data is expected to be one row
per subject per by level. Before the effect size is calculated, the data are
reshaped to a wide format to be one row per subject.
The data are then passed as
effectsize::cohens_d(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)
.
ARD data frame
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_cohens_d(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> ard_effectsize_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID)
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_cohens_d(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> ard_effectsize_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID)
Analysis results data for paired and non-paired Hedge's G Effect Size Test
using effectsize::hedges_g()
.
ard_effectsize_hedges_g(data, by, variables, conf.level = 0.95, ...) ard_effectsize_paired_hedges_g(data, by, variables, id, conf.level = 0.95, ...)
ard_effectsize_hedges_g(data, by, variables, conf.level = 0.95, ...) ard_effectsize_paired_hedges_g(data, by, variables, id, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
conf.level |
(scalar |
... |
arguments passed to |
id |
( |
For the ard_effectsize_hedges_g()
function, the data is expected to be one row per subject.
The data is passed as effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)
.
For the ard_effectsize_paired_hedges_g()
function, the data is expected to be one row
per subject per by level. Before the effect size is calculated, the data are
reshaped to a wide format to be one row per subject.
The data are then passed as
effectsize::hedges_g(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)
.
ARD data frame
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_hedges_g(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> ard_effectsize_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID)
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_hedges_g(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> ard_effectsize_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID)
This function calculates least-squares mean differences using the 'emmeans' package using the following
emmeans::emmeans(object = <regression model>, specs = ~ <primary covariate>) |> emmeans::contrast(method = "pairwise") |> summary(infer = TRUE, level = <confidence level>)
The arguments data
, formula
, method
, method.args
, package
are used
to construct the regression model via cardx::construct_model()
.
ard_emmeans_mean_difference( data, formula, method, method.args = list(), package = "base", response_type = c("continuous", "dichotomous"), conf.level = 0.95, primary_covariate = getElement(attr(stats::terms(formula), "term.labels"), 1L) )
ard_emmeans_mean_difference( data, formula, method, method.args = list(), package = "base", response_type = c("continuous", "dichotomous"), conf.level = 0.95, primary_covariate = getElement(attr(stats::terms(formula), "term.labels"), 1L) )
data |
( |
formula |
( |
method |
( |
method.args |
(named Note that this list may contain non-standard evaluation components.
If you are wrapping this function in other functions, the argument
must be passed in a way that does not evaluate the list, e.g.
using rlang's embrace operator |
package |
( |
response_type |
( |
conf.level |
(scalar |
primary_covariate |
( |
ARD data frame
ard_emmeans_mean_difference( data = mtcars, formula = mpg ~ am + cyl, method = "lm" ) ard_emmeans_mean_difference( data = mtcars, formula = vs ~ am + mpg, method = "glm", method.args = list(family = binomial), response_type = "dichotomous" )
ard_emmeans_mean_difference( data = mtcars, formula = mpg ~ am + cyl, method = "lm" ) ard_emmeans_mean_difference( data = mtcars, formula = vs ~ am + mpg, method = "glm", method.args = list(family = binomial), response_type = "dichotomous" )
Compute Analysis Results Data (ARD) for statistics related to data missingness for survey objects
## S3 method for class 'survey.design' ard_missing( data, variables, by = NULL, statistic = everything() ~ c("N_obs", "N_miss", "N_nonmiss", "p_miss", "p_nonmiss", "N_obs_unweighted", "N_miss_unweighted", "N_nonmiss_unweighted", "p_miss_unweighted", "p_nonmiss_unweighted"), fmt_fn = NULL, stat_label = everything() ~ list(N_obs = "Total N", N_miss = "N Missing", N_nonmiss = "N not Missing", p_miss = "% Missing", p_nonmiss = "% not Missing", N_obs_unweighted = "Total N (unweighted)", N_miss_unweighted = "N Missing (unweighted)", N_nonmiss_unweighted = "N not Missing (unweighted)", p_miss_unweighted = "% Missing (unweighted)", p_nonmiss_unweighted = "% not Missing (unweighted)"), ... )
## S3 method for class 'survey.design' ard_missing( data, variables, by = NULL, statistic = everything() ~ c("N_obs", "N_miss", "N_nonmiss", "p_miss", "p_nonmiss", "N_obs_unweighted", "N_miss_unweighted", "N_nonmiss_unweighted", "p_miss_unweighted", "p_nonmiss_unweighted"), fmt_fn = NULL, stat_label = everything() ~ list(N_obs = "Total N", N_miss = "N Missing", N_nonmiss = "N not Missing", p_miss = "% Missing", p_nonmiss = "% not Missing", N_obs_unweighted = "Total N (unweighted)", N_miss_unweighted = "N Missing (unweighted)", N_nonmiss_unweighted = "N not Missing (unweighted)", p_miss_unweighted = "% Missing (unweighted)", p_nonmiss_unweighted = "% not Missing (unweighted)"), ... )
data |
( |
variables |
( |
by |
( |
statistic |
( |
fmt_fn |
( |
stat_label |
( |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_missing(svy_titanic, variables = c(Class, Age), by = Survived)
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_missing(svy_titanic, variables = c(Class, Age), by = Survived)
Function takes a regression model object and converts it to a ARD
structure using the broom.helpers
package.
ard_regression(x, ...) ## Default S3 method: ard_regression(x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ...)
ard_regression(x, ...) ## Default S3 method: ard_regression(x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ...)
x |
regression model object |
... |
Arguments passed to |
tidy_fun |
( |
data frame
lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression(add_estimate_to_reference_rows = TRUE)
lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression(add_estimate_to_reference_rows = TRUE)
A function that takes a regression model and provides basic statistics in an
ARD structure.
The default output is simpler than ard_regression()
.
The function primarily matches regression terms to underlying variable names
and levels.
The default arguments used are
broom.helpers::tidy_plus_plus( add_reference_rows = FALSE, add_estimate_to_reference_rows = FALSE, add_n = FALSE, intercept = FALSE )
ard_regression_basic( x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, stats_to_remove = c("term", "var_type", "var_label", "var_class", "label", "contrasts_type", "contrasts", "var_nlevels"), ... )
ard_regression_basic( x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, stats_to_remove = c("term", "var_type", "var_label", "var_class", "label", "contrasts_type", "contrasts", "var_nlevels"), ... )
x |
regression model object |
tidy_fun |
( |
stats_to_remove |
( |
... |
Arguments passed to |
data frame
lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression_basic()
lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression_basic()
Standardized mean difference calculated via smd::smd()
with na.rm = TRUE
.
Additionally, this function add a confidence interval to the SMD when
std.error=TRUE
, which the original smd::smd()
does not include.
ard_smd_smd(data, by, variables, std.error = TRUE, conf.level = 0.95, ...)
ard_smd_smd(data, by, variables, std.error = TRUE, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
std.error |
(scalar |
conf.level |
(scalar |
... |
arguments passed to |
ARD data frame
ard_smd_smd(cards::ADSL, by = SEX, variables = AGE) ard_smd_smd(cards::ADSL, by = SEX, variables = AGEGR1)
ard_smd_smd(cards::ADSL, by = SEX, variables = AGE) ard_smd_smd(cards::ADSL, by = SEX, variables = AGEGR1)
Prepare ANOVA results from the stats::anova()
function.
Users may pass a pre-calculated stats::anova()
object or a list of
formulas. In the latter case, the models will be constructed using the
information passed and models will be passed to stats::anova()
.
ard_stats_anova(x, ...) ## S3 method for class 'anova' ard_stats_anova(x, method_text = "ANOVA results from `stats::anova()`", ...) ## S3 method for class 'data.frame' ard_stats_anova( x, formulas, method, method.args = list(), package = "base", method_text = "ANOVA results from `stats::anova()`", ... )
ard_stats_anova(x, ...) ## S3 method for class 'anova' ard_stats_anova(x, method_text = "ANOVA results from `stats::anova()`", ...) ## S3 method for class 'data.frame' ard_stats_anova( x, formulas, method, method.args = list(), package = "base", method_text = "ANOVA results from `stats::anova()`", ... )
x |
( |
... |
These dots are for future extensions and must be empty. |
method_text |
( |
formulas |
( |
method |
( |
method.args |
(named Note that this list may contain non-standard evaluation components.
If you are wrapping this function in other functions, the argument
must be passed in a way that does not evaluate the list, e.g.
using rlang's embrace operator |
package |
( |
When a list of formulas is supplied to ard_stats_anova()
, these formulas
along with information from other arguments, are used to construct models
and pass those models to stats::anova()
.
The models are constructed using rlang::exec()
, which is similar to do.call()
.
rlang::exec(.fn = method, formula = formula, data = data, !!!method.args)
The above function is executed in withr::with_namespace(package)
, which
allows for the use of ard_stats_anova(method)
from packages,
e.g. package = 'lme4'
must be specified when method = 'glmer'
.
See example below.
ARD data frame
anova( lm(mpg ~ am, mtcars), lm(mpg ~ am + hp, mtcars) ) |> ard_stats_anova() ard_stats_anova( x = mtcars, formulas = list(am ~ mpg, am ~ mpg + hp), method = "glm", method.args = list(family = binomial) ) ard_stats_anova( x = mtcars, formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), method = "glmer", method.args = list(family = binomial), package = "lme4" )
anova( lm(mpg ~ am, mtcars), lm(mpg ~ am + hp, mtcars) ) |> ard_stats_anova() ard_stats_anova( x = mtcars, formulas = list(am ~ mpg, am ~ mpg + hp), method = "glm", method.args = list(family = binomial) ) ard_stats_anova( x = mtcars, formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), method = "glmer", method.args = list(family = binomial), package = "lme4" )
Analysis results data for Analysis of Variance.
Calculated with stats::aov()
ard_stats_aov(formula, data, ...)
ard_stats_aov(formula, data, ...)
formula |
A formula specifying the model. |
data |
A data frame in which the variables specified in the formula will be found. If missing, the variables are searched for in the standard way. |
... |
arguments passed to |
ARD data frame
ard_stats_aov(AGE ~ ARM, data = cards::ADSL)
ard_stats_aov(AGE ~ ARM, data = cards::ADSL)
Analysis results data for Pearson's Chi-squared Test.
Calculated with chisq.test(x = data[[variable]], y = data[[by]], ...)
ard_stats_chisq_test(data, by, variables, ...)
ard_stats_chisq_test(data, by, variables, ...)
data |
( |
by |
( |
variables |
( |
... |
additional arguments passed to |
ARD data frame
cards::ADSL |> ard_stats_chisq_test(by = "ARM", variables = "AGEGR1")
cards::ADSL |> ard_stats_chisq_test(by = "ARM", variables = "AGEGR1")
Analysis results data for Fisher's Exact Test.
Calculated with fisher.test(x = data[[variable]], y = data[[by]], ...)
ard_stats_fisher_test(data, by, variables, conf.level = 0.95, ...)
ard_stats_fisher_test(data, by, variables, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
conf.level |
(scalar |
... |
additional arguments passed to |
ARD data frame
cards::ADSL[1:30, ] |> ard_stats_fisher_test(by = "ARM", variables = "AGEGR1")
cards::ADSL[1:30, ] |> ard_stats_fisher_test(by = "ARM", variables = "AGEGR1")
Analysis results data for Kruskal-Wallis Rank Sum Test.
Calculated with kruskal.test(data[[variable]], data[[by]], ...)
ard_stats_kruskal_test(data, by, variables)
ard_stats_kruskal_test(data, by, variables)
data |
( |
by |
( |
variables |
( |
ARD data frame
cards::ADSL |> ard_stats_kruskal_test(by = "ARM", variables = "AGE")
cards::ADSL |> ard_stats_kruskal_test(by = "ARM", variables = "AGE")
Analysis results data for McNemar's statistical test. We have two functions depending on the structure of the data.
ard_stats_mcnemar_test()
is the structure expected by stats::mcnemar.test()
ard_stats_mcnemar_test_long()
is one row per ID per group
ard_stats_mcnemar_test(data, by, variables, ...) ard_stats_mcnemar_test_long(data, by, variables, id, ...)
ard_stats_mcnemar_test(data, by, variables, ...) ard_stats_mcnemar_test_long(data, by, variables, id, ...)
data |
( |
by |
( |
variables |
( |
... |
arguments passed to |
id |
( |
For the ard_stats_mcnemar_test()
function, the data is expected to be one row per subject.
The data is passed as stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)
.
Please use table(x = data[[variable]], y = data[[by]])
to check the contingency table.
ARD data frame
cards::ADSL |> ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") set.seed(1234) cards::ADSL[c("USUBJID", "TRT01P")] |> dplyr::mutate(TYPE = "PLANNED") |> dplyr::rename(TRT01 = TRT01P) %>% dplyr::bind_rows(dplyr::mutate(., TYPE = "ACTUAL", TRT01 = sample(TRT01))) |> ard_stats_mcnemar_test_long( by = TYPE, variable = TRT01, id = USUBJID )
cards::ADSL |> ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") set.seed(1234) cards::ADSL[c("USUBJID", "TRT01P")] |> dplyr::mutate(TYPE = "PLANNED") |> dplyr::rename(TRT01 = TRT01P) %>% dplyr::bind_rows(dplyr::mutate(., TYPE = "ACTUAL", TRT01 = sample(TRT01))) |> ard_stats_mcnemar_test_long( by = TYPE, variable = TRT01, id = USUBJID )
Analysis results data for Mood two sample test of scale. Note this not to be confused with the Brown-Mood test of medians.
ard_stats_mood_test(data, by, variables, ...)
ard_stats_mood_test(data, by, variables, ...)
data |
( |
by |
( |
variables |
( |
... |
arguments passed to |
For the ard_stats_mood_test()
function, the data is expected to be one row per subject.
The data is passed as mood.test(data[[variable]] ~ data[[by]], ...)
.
ARD data frame
cards::ADSL |> ard_stats_mood_test(by = "SEX", variables = "AGE")
cards::ADSL |> ard_stats_mood_test(by = "SEX", variables = "AGE")
Analysis results data for Testing Equal Means in a One-Way Layout.
calculated with oneway.test()
ard_stats_oneway_test(formula, data, ...)
ard_stats_oneway_test(formula, data, ...)
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
... |
additional arguments passed to |
ARD data frame
ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL)
ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL)
Analysis results data for exact tests of a simple null hypothesis about the rate parameter in Poisson distribution, or the comparison of two rate parameters.
ard_stats_poisson_test( data, variables, na.rm = TRUE, by = NULL, conf.level = 0.95, ... )
ard_stats_poisson_test( data, variables, na.rm = TRUE, by = NULL, conf.level = 0.95, ... )
data |
( |
variables |
( |
na.rm |
(scalar |
by |
( |
conf.level |
(scalar |
... |
arguments passed to |
For the ard_stats_poisson_test()
function, the data is expected to be one row per subject.
If by
is not specified, an exact Poisson test of the rate parameter will be performed. Otherwise, a
Poisson comparison of two rate parameters will be performed on the levels of by
. If by
has more than 2
levels, an error will occur.
an ARD data frame of class 'card'
# Exact test of rate parameter against null hypothesis cards::ADTTE |> ard_stats_poisson_test(variables = c(CNSR, AVAL)) # Comparison test of ratio of 2 rate parameters against null hypothesis cards::ADTTE |> dplyr::filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_poisson_test(by = TRTA, variables = c(CNSR, AVAL))
# Exact test of rate parameter against null hypothesis cards::ADTTE |> ard_stats_poisson_test(variables = c(CNSR, AVAL)) # Comparison test of ratio of 2 rate parameters against null hypothesis cards::ADTTE |> dplyr::filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_poisson_test(by = TRTA, variables = c(CNSR, AVAL))
Analysis results data for a 2-sample test or proportions using stats::prop.test()
.
ard_stats_prop_test(data, by, variables, conf.level = 0.95, ...)
ard_stats_prop_test(data, by, variables, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
conf.level |
(scalar |
... |
arguments passed to |
ARD data frame
mtcars |> ard_stats_prop_test(by = vs, variables = am)
mtcars |> ard_stats_prop_test(by = vs, variables = am)
Analysis results data for paired and non-paired t-tests.
ard_stats_t_test(data, variables, by = NULL, conf.level = 0.95, ...) ard_stats_paired_t_test(data, by, variables, id, conf.level = 0.95, ...)
ard_stats_t_test(data, variables, by = NULL, conf.level = 0.95, ...) ard_stats_paired_t_test(data, by, variables, id, conf.level = 0.95, ...)
data |
( |
variables |
( |
by |
( |
conf.level |
(scalar |
... |
arguments passed to |
id |
( |
For the ard_stats_t_test()
function, the data is expected to be one row per subject.
The data is passed as t.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)
.
For the ard_stats_paired_t_test()
function, the data is expected to be one row
per subject per by level. Before the t-test is calculated, the data are
reshaped to a wide format to be one row per subject.
The data are then passed as
t.test(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)
.
ARD data frame
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> ard_stats_paired_t_test(by = ARM, variables = AGE, id = USUBJID)
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> ard_stats_paired_t_test(by = ARM, variables = AGE, id = USUBJID)
Analysis results data for one-sample t-tests.
Result may be stratified by including the by
argument.
ard_stats_t_test_onesample( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ... )
ard_stats_t_test_onesample( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ... )
data |
( |
variables |
( |
by |
( |
conf.level |
(scalar |
... |
arguments passed to |
ARD data frame
cards::ADSL |> ard_stats_t_test_onesample(by = ARM, variables = AGE)
cards::ADSL |> ard_stats_t_test_onesample(by = ARM, variables = AGE)
Analysis results data for paired and non-paired Wilcoxon Rank-Sum tests.
ard_stats_wilcox_test(data, variables, by = NULL, conf.level = 0.95, ...) ard_stats_paired_wilcox_test(data, by, variables, id, conf.level = 0.95, ...)
ard_stats_wilcox_test(data, variables, by = NULL, conf.level = 0.95, ...) ard_stats_paired_wilcox_test(data, by, variables, id, conf.level = 0.95, ...)
data |
( |
variables |
( |
by |
( |
conf.level |
(scalar |
... |
arguments passed to |
id |
( |
For the ard_stats_wilcox_test()
function, the data is expected to be one row per subject.
The data is passed as wilcox.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)
.
For the ard_stats_paired_wilcox_test()
function, the data is expected to be one row
per subject per by level. Before the test is calculated, the data are
reshaped to a wide format to be one row per subject.
The data are then passed as
wilcox.test(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)
.
ARD data frame
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_wilcox_test(by = "ARM", variables = "AGE") # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> ard_stats_paired_wilcox_test(by = ARM, variables = AGE, id = USUBJID)
cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> ard_stats_wilcox_test(by = "ARM", variables = "AGE") # constructing a paired data set, # where patients receive both treatments cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> ard_stats_paired_wilcox_test(by = ARM, variables = AGE, id = USUBJID)
Analysis results data for one-sample Wilcox Rank-sum.
Result may be stratified by including the by
argument.
ard_stats_wilcox_test_onesample( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ... )
ard_stats_wilcox_test_onesample( data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ... )
data |
( |
variables |
( |
by |
( |
conf.level |
(scalar |
... |
arguments passed to |
ARD data frame
cards::ADSL |> ard_stats_wilcox_test_onesample(by = ARM, variables = AGE)
cards::ADSL |> ard_stats_wilcox_test_onesample(by = ARM, variables = AGE)
Analysis results data for survey Chi-Square test using survey::svychisq()
.
Only two-way comparisons are supported.
ard_survey_svychisq(data, by, variables, statistic = "F", ...)
ard_survey_svychisq(data, by, variables, statistic = "F", ...)
data |
( |
by |
( |
variables |
( |
statistic |
( |
... |
arguments passed to |
ARD data frame
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F")
data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F")
Analysis results data for survey wilcox test using survey::svyranktest()
.
ard_survey_svyranktest(data, by, variables, test, ...)
ard_survey_svyranktest(data, by, variables, test, ...)
data |
( |
by |
( |
variables |
( |
test |
( |
... |
arguments passed to |
ARD data frame
data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis")
data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis")
Analysis results data for survey t-test using survey::svyttest()
.
ard_survey_svyttest(data, by, variables, conf.level = 0.95, ...)
ard_survey_svyttest(data, by, variables, conf.level = 0.95, ...)
data |
( |
by |
( |
variables |
( |
conf.level |
( |
... |
arguments passed to |
ARD data frame
data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9)
data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9)
Analysis results data for comparison of survival using survival::survdiff()
.
ard_survival_survdiff(formula, data, rho = 0, ...)
ard_survival_survdiff(formula, data, rho = 0, ...)
formula |
( |
data |
( |
rho |
( |
... |
additional arguments passed to |
an ARD data frame of class 'card'
library(survival) library(ggsurvfit) ard_survival_survdiff(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE)
library(survival) library(ggsurvfit) ard_survival_survdiff(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE)
Analysis results data for survival quantiles and x-year survival estimates, extracted
from a survival::survfit()
model.
ard_survival_survfit(x, ...) ## S3 method for class 'survfit' ard_survival_survfit(x, times = NULL, probs = NULL, type = NULL, ...) ## S3 method for class 'data.frame' ard_survival_survfit( x, y, variables, times = NULL, probs = NULL, type = NULL, method.args = list(conf.int = 0.95), ... )
ard_survival_survfit(x, ...) ## S3 method for class 'survfit' ard_survival_survfit(x, times = NULL, probs = NULL, type = NULL, ...) ## S3 method for class 'data.frame' ard_survival_survfit( x, y, variables, times = NULL, probs = NULL, type = NULL, method.args = list(conf.int = 0.95), ... )
x |
( |
|||||||||
... |
These dots are for future extensions and must be empty. |
|||||||||
times |
( |
|||||||||
probs |
( |
|||||||||
type |
(
|
|||||||||
y |
( |
|||||||||
variables |
( |
|||||||||
method.args |
(named |
Only one of either the times
or probs
parameters can be specified.
Times should be provided using the same scale as the time variable used to fit the provided survival fit model.
an ARD data frame of class 'card'
When passing a survival::survfit()
object to ard_survival_survfit()
,
the survfit()
call must use an evaluated formula and not a stored formula.
Including a proper formula in the call allows the function to accurately
identify all variables included in the estimation. See below for examples:
library(cardx) library(survival) # include formula in `survfit()` call survfit(Surv(time, status) ~ sex, lung) |> ard_survival_survfit(time = 500) # you can also pass a data frame to `ard_survival_survfit()` as well. lung |> ard_survival_survfit(y = Surv(time, status), variables = "sex", time = 500)
You cannot, however, pass a stored formula, e.g. survfit(my_formula, lung)
When the survfit
method is called, the class of the stratifying variables
will be returned as a factor.
When the data frame method is called, the original classes are retained in the resulting ARD.
library(survival) library(ggsurvfit) survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) |> ard_survival_survfit(times = c(60, 180)) survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE, conf.int = 0.90) |> ard_survival_survfit(probs = c(0.25, 0.5, 0.75)) cards::ADTTE |> ard_survival_survfit(y = Surv_CNSR(AVAL, CNSR), variables = c("TRTA", "SEX"), times = 90) # Competing Risks Example --------------------------- set.seed(1) ADTTE_MS <- cards::ADTTE %>% dplyr::mutate( CNSR = dplyr::case_when( CNSR == 0 ~ "censor", runif(dplyr::n()) < 0.5 ~ "death from cancer", TRUE ~ "death other causes" ) %>% factor() ) survfit(Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% ard_survival_survfit(times = c(60, 180))
library(survival) library(ggsurvfit) survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) |> ard_survival_survfit(times = c(60, 180)) survfit(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE, conf.int = 0.90) |> ard_survival_survfit(probs = c(0.25, 0.5, 0.75)) cards::ADTTE |> ard_survival_survfit(y = Surv_CNSR(AVAL, CNSR), variables = c("TRTA", "SEX"), times = 90) # Competing Risks Example --------------------------- set.seed(1) ADTTE_MS <- cards::ADTTE %>% dplyr::mutate( CNSR = dplyr::case_when( CNSR == 0 ~ "censor", runif(dplyr::n()) < 0.5 ~ "death from cancer", TRUE ~ "death other causes" ) %>% factor() ) survfit(Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% ard_survival_survfit(times = c(60, 180))
Calculate differences in the Kaplan-Meier estimator of survival using the
results from survival::survfit()
.
ard_survival_survfit_diff(x, times, conf.level = 0.95)
ard_survival_survfit_diff(x, times, conf.level = 0.95)
x |
( |
times |
( |
conf.level |
(scalar |
an ARD data frame of class 'card'
library(ggsurvfit) library(survival) survfit(Surv_CNSR() ~ TRTA, data = cards::ADTTE) |> ard_survival_survfit_diff(times = c(25, 50))
library(ggsurvfit) library(survival) survfit(Surv_CNSR() ~ TRTA, data = cards::ADTTE) |> ard_survival_survfit_diff(times = c(25, 50))
Returns the total N for a survey object.
The placeholder variable name returned in the object is "..ard_total_n.."
## S3 method for class 'survey.design' ard_total_n(data, ...)
## S3 method for class 'survey.design' ard_total_n(data, ...)
data |
( |
... |
These dots are for future extensions and must be empty. |
an ARD data frame of class 'card'
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_total_n(svy_titanic)
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) ard_total_n(svy_titanic)
These functions help construct calls to various types of models.
construct_model(data, ...) ## S3 method for class 'data.frame' construct_model( data, formula, method, method.args = list(), package = "base", env = caller_env(), ... ) ## S3 method for class 'survey.design' construct_model( data, formula, method, method.args = list(), package = "survey", env = caller_env(), ... ) reformulate2( termlabels, response = NULL, intercept = TRUE, env = parent.frame(), pattern_term = NULL, pattern_response = NULL ) bt(x, pattern = NULL) bt_strip(x)
construct_model(data, ...) ## S3 method for class 'data.frame' construct_model( data, formula, method, method.args = list(), package = "base", env = caller_env(), ... ) ## S3 method for class 'survey.design' construct_model( data, formula, method, method.args = list(), package = "survey", env = caller_env(), ... ) reformulate2( termlabels, response = NULL, intercept = TRUE, env = parent.frame(), pattern_term = NULL, pattern_response = NULL ) bt(x, pattern = NULL) bt_strip(x)
data |
|
... |
These dots are for future extensions and must be empty. |
formula |
( |
method |
( |
method.args |
(named Note that this list may contain non-standard evaluation components.
If you are wrapping this function in other functions, the argument
must be passed in a way that does not evaluate the list, e.g.
using rlang's embrace operator |
package |
( |
env |
The environment in which to evaluate |
termlabels |
character vector giving the right-hand side of a model formula. Cannot be zero-length. |
response |
character string, symbol or call giving the left-hand
side of a model formula, or |
intercept |
logical: should the formula have an intercept? |
x |
( |
pattern , pattern_term , pattern_response
|
DEPRECATED |
construct_model()
: Builds models of the form method(data = data, formula = formula, method.args!!!)
.
If the package
argument is specified, that package is temporarily attached
when the model is evaluated.
reformulate2()
: This is a copy of reformulate()
except that variable
names that contain a space are wrapped in backticks.
bt()
: Adds backticks to a character vector.
bt_strip()
: Removes backticks from a string if it begins and ends with a backtick.
depends on the calling function
construct_model( data = mtcars, formula = am ~ mpg + (1 | vs), method = "glmer", method.args = list(family = binomial), package = "lme4" ) |> broom.mixed::tidy() construct_model( data = mtcars |> dplyr::rename(`M P G` = mpg), formula = reformulate2(c("M P G", "cyl"), response = "hp"), method = "lm" ) |> ard_regression() |> dplyr::filter(stat_name %in% c("term", "estimate", "p.value"))
construct_model( data = mtcars, formula = am ~ mpg + (1 | vs), method = "glmer", method.args = list(family = binomial), package = "lme4" ) |> broom.mixed::tidy() construct_model( data = mtcars |> dplyr::rename(`M P G` = mpg), formula = reformulate2(c("M P G", "cyl"), response = "hp"), method = "lm" ) |> ard_regression() |> dplyr::filter(stat_name %in% c("term", "estimate", "p.value"))
Functions to calculate different proportion confidence intervals for use in ard_proportion()
.
proportion_ci_wald(x, conf.level = 0.95, correct = FALSE) proportion_ci_wilson(x, conf.level = 0.95, correct = FALSE) proportion_ci_clopper_pearson(x, conf.level = 0.95) proportion_ci_agresti_coull(x, conf.level = 0.95) proportion_ci_jeffreys(x, conf.level = 0.95) proportion_ci_strat_wilson( x, strata, weights = NULL, conf.level = 0.95, max.iterations = 10L, correct = FALSE ) is_binary(x)
proportion_ci_wald(x, conf.level = 0.95, correct = FALSE) proportion_ci_wilson(x, conf.level = 0.95, correct = FALSE) proportion_ci_clopper_pearson(x, conf.level = 0.95) proportion_ci_agresti_coull(x, conf.level = 0.95) proportion_ci_jeffreys(x, conf.level = 0.95) proportion_ci_strat_wilson( x, strata, weights = NULL, conf.level = 0.95, max.iterations = 10L, correct = FALSE ) is_binary(x)
x |
vector of a binary values, i.e. a logical vector, or numeric with values |
conf.level |
( |
correct |
( |
strata |
( |
weights |
( |
max.iterations |
( |
Confidence interval of a proportion.
proportion_ci_wald()
: Calculates the Wald interval by following the usual textbook definition
for a single proportion confidence interval using the normal approximation.
proportion_ci_wilson()
: Calculates the Wilson interval by calling stats::prop.test()
.
Also referred to as Wilson score interval.
proportion_ci_clopper_pearson()
: Calculates the Clopper-Pearson interval by calling stats::binom.test()
.
Also referred to as the exact
method.
proportion_ci_agresti_coull()
: Calculates the Agresti-Coull
interval (created by Alan Agresti
and Brent Coull
) by
(for 95% CI) adding two successes and two failures to the data and then using the Wald formula to construct a CI.
proportion_ci_jeffreys()
: Calculates the Jeffreys interval, an equal-tailed interval based on the
non-informative Jeffreys prior for a binomial proportion.
proportion_ci_strat_wilson()
: Calculates the stratified Wilson confidence
interval for unequal proportions as described in
Xin YA, Su XG. Stratified Wilson and Newcombe confidence intervals
for multiple binomial proportions. Statistics in Biopharmaceutical Research. 2010;2(3).
is_binary()
: Helper to determine if vector is binary (logical or 0/1)
x <- c( TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) proportion_ci_wald(x, conf.level = 0.9) proportion_ci_wilson(x, correct = TRUE) proportion_ci_clopper_pearson(x) proportion_ci_agresti_coull(x) proportion_ci_jeffreys(x) # Stratified Wilson confidence interval with unequal probabilities set.seed(1) rsp <- sample(c(TRUE, FALSE), 100, TRUE) strata_data <- data.frame( "f1" = sample(c("a", "b"), 100, TRUE), "f2" = sample(c("x", "y", "z"), 100, TRUE), stringsAsFactors = TRUE ) strata <- interaction(strata_data) n_strata <- ncol(table(rsp, strata)) # Number of strata proportion_ci_strat_wilson( x = rsp, strata = strata, conf.level = 0.90 ) # Not automatic setting of weights proportion_ci_strat_wilson( x = rsp, strata = strata, weights = rep(1 / n_strata, n_strata), conf.level = 0.90 )
x <- c( TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE ) proportion_ci_wald(x, conf.level = 0.9) proportion_ci_wilson(x, correct = TRUE) proportion_ci_clopper_pearson(x) proportion_ci_agresti_coull(x) proportion_ci_jeffreys(x) # Stratified Wilson confidence interval with unequal probabilities set.seed(1) rsp <- sample(c(TRUE, FALSE), 100, TRUE) strata_data <- data.frame( "f1" = sample(c("a", "b"), 100, TRUE), "f2" = sample(c("x", "y", "z"), 100, TRUE), stringsAsFactors = TRUE ) strata <- interaction(strata_data) n_strata <- ncol(table(rsp, strata)) # Number of strata proportion_ci_strat_wilson( x = rsp, strata = strata, conf.level = 0.90 ) # Not automatic setting of weights proportion_ci_strat_wilson( x = rsp, strata = strata, weights = rep(1 / n_strata, n_strata), conf.level = 0.90 )