6.10 Finalfit approach

The finalfit package provides an easy to use interface for performing non-parametric hypothesis tests. Any number of explanatory variables can be tested against a so-called dependent variable. In this case, this is equivalent to a typical Table 1 in healthcare study.

dependent <- "year"
explanatory <- c("lifeExp", "pop", "gdpPercap")
africa_data %>%         
  mutate(
    year = factor(year)
  ) %>% 
  summary_factorlist(dependent, explanatory,
                     cont = "median", p = TRUE)

Note that the p-values above have not been corrected for multiple testing.

TABLE 6.5: Life expectancy, population and GDPperCap in Africa 1982 vs 2007.
label levels 1982 2007 p
lifeExp Median (IQR) 50.8 (11.0) 52.9 (11.6) 0.149
pop Median (IQR) 5668228.5 (8218654.0) 10093310.5 (16454428.0) 0.033
gdpPercap Median (IQR) 1323.7 (1958.9) 1452.3 (3130.6) 0.503

There are many other options available for this function which are covered throughout this book. For instance, If you wish to consider only some variables as non-parametric and summarise with a median, then this can be specified using

dependent <- "year"
explanatory <- c("lifeExp", "pop", "gdpPercap")
africa_data %>%         
  mutate(
    year = factor(year)
  ) %>% 
  summary_factorlist(dependent, explanatory,
                     cont_nonpara =  c(1, 3),         # variable 1&3 are non-parametric
                     cont_range = TRUE,               # lower and upper quartile
                     p = TRUE,                        # include hypothesis test
                     p_cont_para = "t.test",          # use t.test/aov for parametric
                     add_row_totals = TRUE,           # row totals
                     include_row_missing_col = FALSE, # missing values row totals
                     add_dependent_label = TRUE)      # dependent label 
TABLE 6.6: Life expectancy, population and GDPperCap in Africa 1982 vs 2007.
Dependent: year Total N 1982 2007 p
lifeExp 104 Median (IQR) 50.8 (45.6 to 56.6) 52.9 (47.8 to 59.4) 0.149
pop 104 Mean (SD) 9602857.4 (13456243.4) 17875763.3 (24917726.2) 0.038
gdpPercap 104 Median (IQR) 1323.7 (828.7 to 2787.6) 1452.3 (863.0 to 3993.5) 0.503