plot_forest: Forest the results from regression

View source: R/plot_forest.r

plot_forestR Documentation

Forest the results from regression

Description

Forest the results from regression

Usage

plot_forest(
  reg,
  reg_res,
  log = TRUE,
  var_label = list(group = "Dementia", age = "Age at baseline (years)", gender =
    "Gender", smi = "Severe mental illness (= yes)", `gender:smi` = "Gender(= male)xSMI",
    mari_stat = "Marital status", imd_cat = "Social-economic status", ethnic =
    "Ethnicity", mmse = "Dementia severity", charlson = "Physical comordity"),
  value_label = list(mari_stat = c("Single/divorced/widowed", "Cohabiting/married"),
    detention = c(TRUE, FALSE), `gender:smi` = c(TRUE, FALSE), imd_cat =
    c("1(Most deprived)", "2", "3", "4", "5(Most affluent)"), smi = c(TRUE, FALSE)),
  comb_title = "Hazard Ratio (95%CI)",
  layout_matrix = matrix(c(1, 1, 2, 2, 3, 3, 3, 4), nrow = 1),
  shadow = c("white", "white"),
  plot_out = FALSE,
  num_space = 1,
  ...
)

Arguments

reg

the regression result, like the result of lm or glm

reg_res

result form reg_comb

log

if log x axis for plot 3

var_label

list. full name of the variables

value_label

list. labels of values of variables. Primary use for logical. Could also use for character and factor

comb_title

title of plot 2 or combined result.

layout_matrix

matrix of the final combined plot

shadow

shadow of lines. still under test.

plot_out

output plot or list of plot_1, plot_2, plot_3, plot_4

Author(s)

Shanquan CHEN shanquan0301@gmial.com

Examples

#cox regression-----------
reg <- coxph(Surv(follow_up, detention) ~ group + cluster(rid) +
               age + gender + mari_stat + ethnic + imd_cat + mmse + charlson + smi,
               data = dat_mha %>% filter(group != "PDD"))
reg_res <- reg_comb(reg = reg,
                    exp_transfer = TRUE,
                    coef = "coef",
                    round_ci = 2,
                    round_p = 4,
                    comb_ci = "coef(ci_low-ci_high)")
plot_forest(reg = reg,
            reg_res = reg_res,
            var_label = list(group = "Dementia",
                             age = "Age at baseline (years)",
                             gender = "Gender",
                             mari_stat = "Marital status",
                             ethnic = "Ethnicity",
                             imd_cat = "Social-economic status",
                             mmse = "Dementia severity",
                             charlson = "Physical comordity",
                             smi = "Severe mental illness (= yes)"),
            value_label = list(mari_stat = c("Single/divorced/widowed", "Cohabiting/married"),
                               imd_cat = c("1(Most deprived)", "2", "3", "4", "5(Most affluent)"),
                               smi = c(TRUE, FALSE)))
#cox regression with interaction-----------------------
reg <- coxph(Surv(follow_up, death) ~ detention*group +  cluster(id) +
              age + gender + mari_stat + ethnic + imd_cat  + mmse + charlson + smi,
              data = dat_reg)
reg_res <- reg_comb(reg = reg,
                    exp_transfer = TRUE,
                    coef = "coef",
                    round_ci = 2,
                    round_p = 4,
                    comb_ci = "coef(ci_low-ci_high)")
plot_forest(reg = reg,
            reg_res = reg_res,
            var_label = list(detention = "Compulsory admission (= yes)",
                             group = "Dementia",
                             `detention:group` = "Compulsory admission (= yes)xDLB",
                             age = "Age at baseline (years)",
                             gender = "Gender",
                             mari_stat = "Marital status",
                             ethnic = "Ethnicity",
                             imd_cat = "Social-economic status",
                             mmse = "Dementia severity",
                             charlson = "Physical comordity",
                             smi = "Severe mental illness (= yes)"),
            value_label = list(mari_stat = c("Single/divorced/widowed", "Cohabiting/married"),
                               detention = c(TRUE, FALSE),
                               `detention:group` = c(TRUE, FALSE),
                               imd_cat = c("1(Most deprived)", "2", "3", "4", "5(Most affluent)"),
                               smi = c(TRUE, FALSE)))
reg <- glm(detention ~ group +
           age + gender*smi + mari_stat + ethnic + imd_cat + mmse + charlson + smi,
           family = binomial(),
           data = dat_mha)
reg_res <- reg_comb(reg = reg,
                    exp_transfer = TRUE,
                    coef = "Estimate",
                    round_ci = 2,
                    round_p = 4,
                    comb_ci = "coef(ci_low-ci_high)")
plot_forest(reg = reg,
            reg_res = reg_res,
            var_label = list(group = "Dementia",
                             age = "Age at baseline (years)",
                             gender = "Gender",
                             `gender:smi` = "GenderxSMI",
                             mari_stat = "Marital status",
                             ethnic = "Ethnicity",
                             imd_cat = "Social-economic status",
                             mmse = "Dementia severity",
                             charlson = "Physical comordity",
                             smi = "Severe mental illness (= yes)"),
            value_label = list(mari_stat = c("Single/divorced/widowed", "Cohabiting/married"),
                               `gender:smi` = c(TRUE, FALSE),
                               imd_cat = c("1(Most deprived)", "2", "3", "4", "5(Most affluent)"),
                               smi = c(TRUE, FALSE)),
            shadow = pal_nejm("default", alpha = 0.6)(8)[1:2])


shanquan0301/DataDescription documentation built on March 13, 2024, 2:49 a.m.