mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2025-09-12 01:49:39 +02:00
109 lines
2.5 KiB
R
109 lines
2.5 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/regression_table.R
|
|
\name{regression_table}
|
|
\alias{regression_table}
|
|
\title{Create table of regression model}
|
|
\usage{
|
|
regression_table(x, ...)
|
|
}
|
|
\arguments{
|
|
\item{x}{regression model}
|
|
|
|
\item{...}{passed to methods}
|
|
|
|
\item{args.list}{list of arguments passed to 'fun'.}
|
|
|
|
\item{fun}{function to use for table creation. Default is "gtsummary::tbl_regression".}
|
|
}
|
|
\value{
|
|
object of standard class for fun
|
|
}
|
|
\description{
|
|
Create table of regression model
|
|
}
|
|
\examples{
|
|
\dontrun{
|
|
tbl <- gtsummary::trial |>
|
|
regression_model(
|
|
outcome.str = "stage",
|
|
fun = "MASS::polr"
|
|
) |>
|
|
regression_table(args.list = list("exponentiate" = TRUE))
|
|
gtsummary::trial |>
|
|
regression_model(
|
|
outcome.str = "age",
|
|
fun = "stats::lm",
|
|
formula.str = "{outcome.str}~.",
|
|
args.list = NULL
|
|
) |>
|
|
regression_table() |> plot()
|
|
gtsummary::trial |>
|
|
regression_model(
|
|
outcome.str = "trt",
|
|
fun = "stats::glm",
|
|
args.list = list(family = binomial(link = "logit"))
|
|
) |>
|
|
regression_table()
|
|
gtsummary::trial |>
|
|
regression_model_uv(
|
|
outcome.str = "trt",
|
|
fun = "stats::glm",
|
|
args.list = list(family = stats::binomial(link = "logit"))
|
|
) |>
|
|
regression_table()
|
|
gtsummary::trial |>
|
|
regression_model_uv(
|
|
outcome.str = "stage",
|
|
args.list = list(family = stats::binomial(link = "logit"))
|
|
) |>
|
|
regression_table()
|
|
|
|
list(
|
|
"Univariable" = regression_model_uv,
|
|
"Multivariable" = regression_model
|
|
) |>
|
|
lapply(\(.fun){
|
|
do.call(
|
|
.fun,
|
|
c(
|
|
list(data = gtsummary::trial),
|
|
list(outcome.str = "stage")
|
|
)
|
|
)
|
|
}) |>
|
|
purrr::map(regression_table) |>
|
|
tbl_merge()
|
|
}
|
|
regression_table <- function(x, ...) {
|
|
UseMethod("regression_table")
|
|
}
|
|
|
|
#' @rdname regression_table
|
|
#' @export
|
|
regression_table.list <- function(x, ...) {
|
|
x |>
|
|
purrr::map(\(.m){
|
|
regression_table(x = .m, ...) |>
|
|
gtsummary::add_n()
|
|
}) |>
|
|
gtsummary::tbl_stack()
|
|
}
|
|
|
|
#' @rdname regression_table
|
|
#' @export
|
|
regression_table.default <- function(x, ..., args.list = NULL, fun = "gtsummary::tbl_regression") {
|
|
# Stripping custom class
|
|
class(x) <- class(x)[class(x) != "freesearcher_model"]
|
|
|
|
if (any(c(length(class(x)) != 1, class(x) != "lm"))) {
|
|
if (!"exponentiate" \%in\% names(args.list)) {
|
|
args.list <- c(args.list, list(exponentiate = TRUE))
|
|
}
|
|
}
|
|
|
|
out <- do.call(getfun(fun), c(list(x = x), args.list))
|
|
out |>
|
|
gtsummary::add_glance_source_note() # |>
|
|
# gtsummary::bold_p()
|
|
}
|
|
}
|