mtab2df {sjtable2df}R Documentation

mtab2df

Description

Convert table from 'sjPlot::tab_model' to R data.frame or 'knitr::kable'

Usage

mtab2df(mtab, n_models, output = "data.table", ...)

Arguments

mtab

A model table, created with 'sjPlot::tab_model'.

n_models

An integer, specifiying the number of models in the table.

output

A character vector. Allowed values are: "data.table" (default), "data.frame" or "kable". The function's return value is of the respective type.

...

Further arguments to be passed to 'kableExtra::kbl'.

Value

The table is returned as an R object of the type specified with the 'output' argument.

Examples


set.seed(1)
dataset <- data.table::data.table(
  "var1" = factor(sample(
    x = c("yes", "no"),
    size = 100,
    replace = TRUE,
    prob = c(.3, .7)
  )),
  "var2" = factor(sample(
    x = c("yes", "no"),
    size = 100,
    replace = TRUE
  )),
  "var3" = rnorm(100)
)

# models
m0 <- stats::glm(
  var1 ~ 1,
  data = dataset,
  family = binomial(link = "logit")
)
m1 <- stats::glm(
  var1 ~ var2,
  data = dataset,
  family = binomial(link = "logit")
)
m2 <- stats::glm(
  var1 ~ var2 + var3,
  data = dataset,
  family = binomial(link = "logit")
)

m_table <- sjPlot::tab_model(m0, m1, m2, show.aic = TRUE)

final_tab <- sjtable2df::mtab2df(mtab = m_table, n_models = 3)


[Package sjtable2df version 0.0.3 Index]