Skip to content

Commit

Permalink
add coords argument
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Aug 4, 2024
1 parent 1682d4d commit 3063954
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 27 additions & 24 deletions R/check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
#'
Expand All @@ -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."
Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion man/check_dag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3063954

Please sign in to comment.