Permuate explanatory variables to produce multiple output tables for common regression models

ff_permute(
  .data,
  dependent = NULL,
  explanatory_base = NULL,
  explanatory_permute = NULL,
  multiple_tables = FALSE,
  include_base_model = TRUE,
  include_full_model = TRUE,
  base_on_top = TRUE,
  ...
)

finalfit_permute(
  .data,
  dependent = NULL,
  explanatory_base = NULL,
  explanatory_permute = NULL,
  multiple_tables = FALSE,
  include_base_model = TRUE,
  include_full_model = TRUE,
  base_on_top = TRUE,
  ...
)

Arguments

.data

Data frame or tibble.

dependent

Character vector of length 1: quoted name of dependent variable. Can be continuous, a binary factor, or a survival object of form Surv(time, status).

explanatory_base

Character vector of any length: quoted name(s) of base model explanatory variables.

explanatory_permute

Character vector of any length: quoted name(s) of explanatory variables to permute through models.

multiple_tables

Logical. Multiple model tables as a list, or a single table including multiple models.

include_base_model

Logical. Include model using explanatory_base variables only.

include_full_model

Logical. Include model using all explanatory_base and explanatory_permute variables.

base_on_top

Logical. Base variables at top of table, or bottom of table.

...

Other arguments to finalfit

Value

Returns a list of data frame with the final model table.

Examples

explanatory_base = c("age.factor", "sex.factor")
explanatory_permute = c("obstruct.factor", "perfor.factor", "node4.factor")

# Linear regression
colon_s %>%
  finalfit_permute("nodes", explanatory_base, explanatory_permute)
#> Note: dependent includes missing data. These are dropped.
#> Note: dependent includes missing data. These are dropped.
#> Note: dependent includes missing data. These are dropped.
#> Note: dependent includes missing data. These are dropped.
#> Note: dependent includes missing data. These are dropped.
#> Note: dependent includes missing data. These are dropped.
#>   Dependent: nodes                  unit     value
#>                Age   <40 years Mean (sd) 4.7 (4.5)
#>                    40-59 years Mean (sd) 3.6 (3.3)
#>                      60+ years Mean (sd) 3.6 (3.6)
#>                Sex      Female Mean (sd) 3.7 (3.6)
#>                           Male Mean (sd) 3.6 (3.6)
#>        Obstruction          No Mean (sd) 3.7 (3.7)
#>                            Yes Mean (sd) 3.5 (3.2)
#>        Perforation          No Mean (sd) 3.7 (3.6)
#>                            Yes Mean (sd) 3.9 (2.8)
#>  >4 positive nodes          No Mean (sd) 2.0 (1.1)
#>                            Yes Mean (sd) 8.2 (4.1)
#>                 OR (univariable)            OR (multivariable) 1
#>                                -                               -
#>  -1.14 (-2.08 to -0.21, p=0.016) -1.14 (-2.07 to -0.20, p=0.017)
#>  -1.19 (-2.10 to -0.28, p=0.010) -1.18 (-2.09 to -0.27, p=0.011)
#>                                -                               -
#>   -0.14 (-0.60 to 0.33, p=0.565)  -0.12 (-0.58 to 0.35, p=0.626)
#>                                -                               -
#>   -0.24 (-0.83 to 0.36, p=0.435)                               -
#>                                -                               -
#>    0.24 (-1.13 to 1.61, p=0.735)                               -
#>                                -                               -
#>     6.19 (5.84 to 6.53, p<0.001)                               -
#>             OR (multivariable) 2            OR (multivariable) 3
#>                                -                               -
#>  -1.21 (-2.16 to -0.26, p=0.012) -1.14 (-2.07 to -0.20, p=0.017)
#>  -1.25 (-2.17 to -0.33, p=0.008) -1.18 (-2.09 to -0.27, p=0.011)
#>                                -                               -
#>   -0.07 (-0.54 to 0.40, p=0.779)  -0.12 (-0.58 to 0.35, p=0.627)
#>                                -                               -
#>   -0.30 (-0.90 to 0.30, p=0.327)                               -
#>                                -                               -
#>                                -   0.24 (-1.13 to 1.60, p=0.736)
#>                                -                               -
#>                                -                               -
#>             OR (multivariable) 4            OR (multivariable) 5
#>                                -                               -
#>  -0.63 (-1.24 to -0.02, p=0.042) -0.64 (-1.26 to -0.02, p=0.043)
#>   -0.47 (-1.06 to 0.13, p=0.123)  -0.48 (-1.08 to 0.12, p=0.119)
#>                                -                               -
#>    0.10 (-0.20 to 0.40, p=0.527)   0.13 (-0.17 to 0.44, p=0.391)
#>                                -                               -
#>                                -  -0.13 (-0.53 to 0.26, p=0.500)
#>                                -                               -
#>                                -   0.50 (-0.40 to 1.39, p=0.277)
#>                                -                               -
#>     6.18 (5.84 to 6.52, p<0.001)    6.19 (5.84 to 6.54, p<0.001)

# Cox proportional hazards regression
colon_s %>%
  finalfit_permute("Surv(time, status)", explanatory_base, explanatory_permute)
#>  Dependent: Surv(time, status)                    all          HR (univariable)
#>                            Age   <40 years   70 (7.5)                         -
#>                                40-59 years 344 (37.0) 0.76 (0.53-1.09, p=0.132)
#>                                  60+ years 515 (55.4) 0.93 (0.66-1.31, p=0.668)
#>                            Sex      Female 445 (47.9)                         -
#>                                       Male 484 (52.1) 1.01 (0.84-1.22, p=0.888)
#>                    Obstruction          No 732 (80.6)                         -
#>                                        Yes 176 (19.4) 1.29 (1.03-1.62, p=0.028)
#>                    Perforation          No 902 (97.1)                         -
#>                                        Yes   27 (2.9) 1.17 (0.70-1.95, p=0.556)
#>              >4 positive nodes          No 674 (72.6)                         -
#>                                        Yes 255 (27.4) 2.60 (2.15-3.14, p<0.001)
#>       HR (multivariable) 1      HR (multivariable) 2      HR (multivariable) 3
#>                          -                         -                         -
#>  0.76 (0.53-1.08, p=0.129) 0.79 (0.55-1.13, p=0.198) 0.76 (0.53-1.08, p=0.127)
#>  0.93 (0.66-1.31, p=0.660) 0.98 (0.69-1.40, p=0.931) 0.92 (0.65-1.31, p=0.656)
#>                          -                         -                         -
#>  1.02 (0.85-1.23, p=0.847) 1.02 (0.85-1.24, p=0.803) 1.02 (0.85-1.22, p=0.854)
#>                          -                         -                         -
#>                          - 1.31 (1.04-1.64, p=0.022)                         -
#>                          -                         -                         -
#>                          -                         - 1.18 (0.70-1.97, p=0.535)
#>                          -                         -                         -
#>                          -                         -                         -
#>       HR (multivariable) 4      HR (multivariable) 5
#>                          -                         -
#>  0.85 (0.59-1.22, p=0.379) 0.90 (0.63-1.30, p=0.590)
#>  1.09 (0.77-1.55, p=0.615) 1.19 (0.83-1.69, p=0.346)
#>                          -                         -
#>  1.04 (0.87-1.26, p=0.647) 1.05 (0.87-1.27, p=0.597)
#>                          -                         -
#>                          - 1.35 (1.07-1.70, p=0.011)
#>                          -                         -
#>                          - 1.16 (0.69-1.94, p=0.581)
#>                          -                         -
#>  2.64 (2.18-3.19, p<0.001) 2.68 (2.21-3.26, p<0.001)

# Logistic regression
# colon_s %>%
#   finalfit_permute("mort_5yr", explanatory_base, explanatory_permute)

# Logistic regression with random effect (glmer)
# colon_s %>%
#   finalfit_permute("mort_5yr", explanatory_base, explanatory_permute,
#     random_effect = "hospital")