diff --git a/DESCRIPTION b/DESCRIPTION index 494c87973..08854ca1b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.2.6 +Version: 0.12.2.7 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NAMESPACE b/NAMESPACE index 4d59423a9..e0543f2b8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,8 +49,6 @@ S3method(check_convergence,"_glm") S3method(check_convergence,default) S3method(check_convergence,glmmTMB) S3method(check_convergence,merMod) -S3method(check_dag,dagitty) -S3method(check_dag,default) S3method(check_distribution,default) S3method(check_distribution,numeric) S3method(check_heteroscedasticity,default) diff --git a/R/check_dag.R b/R/check_dag.R index becc39750..66fae0c1c 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -31,6 +31,10 @@ #' @param latent A character vector with names of latent variables in the model. #' @param effect Character string, indicating which effect to check. Can be #' `"all"` (default), `"total"`, or `"direct"`. +#' @param coords A list with two elements, `x` and `y`, which both are named +#' vectors of numerics. The names correspond to the variable names in the DAG, +#' and the values for `x` and `y` indicate the x/y coordinates in the plot. +#' See 'Examples'. #' @param x An object of class `check_dag`, as returned by `check_dag()`. #' #' @section Specifying the DAG formulas: @@ -103,6 +107,21 @@ #' ) #' dag #' +#' # use specific layout for the DAG +#' dag <- check_dag( +#' score ~ exp + b + c, +#' exp ~ b, +#' outcome = "score", +#' exposure = "exp", +#' coords = list( +#' # x-coordinates for all nodes +#' x = c(score = 5, exp = 4, b = 3, c = 3), +#' # y-coordinates for all nodes +#' y = c(score = 3, exp = 3, b = 2, c = 4) +#' ) +#' ) +#' plot(dag) +#' #' # Objects returned by `check_dag()` can be used with "ggdag" or "dagitty" #' ggdag::ggdag_status(dag) #' @@ -123,29 +142,8 @@ check_dag <- function(..., exposure = NULL, adjusted = NULL, latent = NULL, - effect = c("all", "total", "direct")) { - UseMethod("check_dag") -} - - -#' @export -check_dag.dagitty <- function(..., - outcome = NULL, - exposure = NULL, - adjusted = NULL, - latent = NULL, - effect = c("all", "total", "direct")) { - insight::format_error("This function is not yet implemented.") -} - - -#' @export -check_dag.default <- function(..., - outcome = NULL, - exposure = NULL, - adjusted = NULL, - latent = NULL, - effect = c("all", "total", "direct")) { + effect = c("all", "total", "direct"), + coords = NULL) { insight::check_if_installed( c("ggdag", "dagitty"), reason = "to check correct adjustments for identifying causal effects." @@ -190,7 +188,12 @@ check_dag.default <- function(..., } # convert to dag - dag_args <- c(formulas, list(exposure = exposure, outcome = outcome, latent = latent)) + dag_args <- c(formulas, list( + exposure = exposure, + outcome = outcome, + latent = latent, + coords = coords + )) dag <- do.call(ggdag::dagify, dag_args) # add adjustments diff --git a/man/check_dag.Rd b/man/check_dag.Rd index 278dcfd10..0ba8729d1 100644 --- a/man/check_dag.Rd +++ b/man/check_dag.Rd @@ -11,7 +11,8 @@ check_dag( exposure = NULL, adjusted = NULL, latent = NULL, - effect = c("all", "total", "direct") + effect = c("all", "total", "direct"), + coords = NULL ) as.dag(x, ...) @@ -40,6 +41,11 @@ for in the model. If a model object is provided in \code{...}, any values in \item{effect}{Character string, indicating which effect to check. Can be \code{"all"} (default), \code{"total"}, or \code{"direct"}.} +\item{coords}{A list with two elements, \code{x} and \code{y}, which both are named +vectors of numerics. The names correspond to the variable names in the DAG, +and the values for \code{x} and \code{y} indicate the x/y coordinates in the plot. +See 'Examples'.} + \item{x}{An object of class \code{check_dag}, as returned by \code{check_dag()}.} } \value{ @@ -123,6 +129,21 @@ dag <- check_dag( ) dag +# use specific layout for the DAG +dag <- check_dag( + score ~ exp + b + c, + exp ~ b, + outcome = "score", + exposure = "exp", + coords = list( + # x-coordinates for all nodes + x = c(score = 5, exp = 4, b = 3, c = 3), + # y-coordinates for all nodes + y = c(score = 3, exp = 3, b = 2, c = 4) + ) +) +plot(dag) + # Objects returned by `check_dag()` can be used with "ggdag" or "dagitty" ggdag::ggdag_status(dag)