Obtain a tibble (data frame) with parameters, coefficients, standard errors, confidence limits, and p-values. A column with the type of model fitted is added.
Usage
# S3 method for risks
tidy(
x,
conf.int = TRUE,
conf.level = 0.95,
bootrepeats = 1000,
bootci = c("bca", "normal", "nonpar"),
bootverbose = FALSE,
exponentiate = FALSE,
default = TRUE,
...
)
Arguments
- x
Model
- conf.int
Show confidence intervals?
- conf.level
Optional. Confidence level. Defaults to
0.95
.- bootrepeats
Optional. Number of bootstrap repeats. Applicable to models fitted via marginal standardization and bootstrapping (
approach = "margstd_boot"
). Defaults to 1000. Strongly recommended to increase repeats to >>1000.- bootci
Optional and applicable for
approach = "margstd_boot"
only. Type of bootstrap confidence interval:"bca"
Default. Parametric BCa (bias-corrected accelerated) confidence intervals."normal"
Parametric normality-based confidence intervals, which require lower repeat numbers but are less accurate and may result in invalid results for ratios."nonpar"
Non-parametric BCa confidence intervals, which should be used with caution because of the risk of sparse-data bias with non-parametric bootstrapping.
- bootverbose
Optional. Add values of
bootrepeats
andbootci
parameters and the jackknife-based Monte-Carlo error for the confidence limits (only fortype = "bca"
) to the returned tibble? Defaults toFALSE
.- exponentiate
Optional. Exponentiate coefficients and confidence limits? Defaults to FALSE. Setting
exponentiate = TRUE
is useful for relative risk models (log links).- default
Use default, normality-based confidence intervals? Defaults to TRUE. With
default = FALSE
, for binomial models only, profile likelihood-based confidence intervals can be calculated.- ...
Passed on
Details
If multiple types of models are fitted, tidy()
can be used
to parameters for all models at once, in one tibble. The last
column of the tibble includes the name of the model. See examples.
Examples
# Define example data
library(broom) # provides tidy() function
dat <- tibble::tibble(
death = c(rep(1, 54), rep(0, 138)),
stage = c(rep("Stage I", 7), rep("Stage II", 26), rep("Stage III", 21),
rep("Stage I", 60), rep("Stage II", 70), rep("Stage III", 8)),
receptor = c(rep("Low", 2), rep("High", 5), rep("Low", 9), rep("High", 17),
rep("Low", 12), rep("High", 9), rep("Low", 10), rep("High", 50),
rep("Low", 13), rep("High", 57), rep("Low", 2), rep("High", 6)))
# Fit and tidy the model
fit_rr <- riskratio(formula = death ~ stage + receptor, data = dat)
tidy(fit_rr)
#> # A tibble: 3 × 8
#> term estimate std.error statistic p.value conf.low conf.high model
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 stageStage I 0 0 NaN NaN 0 0 marg…
#> 2 stageStage II 0.899 0.387 2.32 2.03e-2 0.140 1.66 marg…
#> 3 stageStage III 1.81 0.378 4.78 1.75e-6 1.07 2.55 marg…
# Marginal standardization,
# increase number of bootstrap repeats:
# \donttest{
fit_rr <- riskratio(
formula = death ~ stage + receptor, data = dat,
approach = "margstd_boot")
tidy(fit_rr, bootrepeats = 2000)
#> # A tibble: 3 × 8
#> term estimate std.error statistic p.value conf.low conf.high model
#> <chr> <dbl[1d> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 stageStage I 0 0 NaN NaN NA NA marg…
#> 2 stageStage II 0.899 0.441 2.04 4.15e-2 0.0966 1.78 marg…
#> 3 stageStage III 1.81 0.425 4.25 2.11e-5 1.07 2.69 marg…
# }
# Multiple types of models fitted:
# \donttest{
fit_rr <- riskratio(formula = death ~ stage + receptor, data = dat,
approach = "all")
#> Loading required package: doParallel
#> Loading required package: foreach
#> Loading required package: iterators
#> Loading required package: parallel
#> Loading required package: numDeriv
#> Loading required package: quantreg
#> Loading required package: SparseM
#>
#> Attaching package: ‘SparseM’
#> The following object is masked from ‘package:base’:
#>
#> backsolve
#>
#> Attaching package: ‘turboEM’
#> The following objects are masked from ‘package:numDeriv’:
#>
#> grad, hessian
tidy(fit_rr)
#> # A tibble: 34 × 8
#> term estimate std.error statistic p.value conf.low conf.high model
#> <chr> <dbl[1d> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) -2.37 0.360 -6.57 5.08e-11 -3.07 -1.66 robp…
#> 2 stageStage II 0.925 0.393 2.35 1.87e- 2 0.154 1.70 robp…
#> 3 stageStage III 1.78 0.386 4.61 4.03e- 6 1.02 2.53 robp…
#> 4 receptorLow 0.489 0.213 2.30 2.16e- 2 0.0718 0.906 robp…
#> 5 (Intercept) -2.35 0.360 -6.53 6.55e-11 -3.06 -1.65 glm_…
#> 6 stageStage II 0.931 0.393 2.37 1.78e- 2 0.161 1.70 glm_…
#> 7 stageStage III 1.77 0.385 4.60 4.33e- 6 1.01 2.52 glm_…
#> 8 receptorLow 0.444 0.197 2.25 2.42e- 2 0.0578 0.829 glm_…
#> 9 (Intercept) -2.35 0.360 -6.53 6.55e-11 -3.06 -1.65 logb…
#> 10 stageStage II 0.931 0.393 2.37 1.78e- 2 0.161 1.70 logb…
#> # ℹ 24 more rows
# }