Skip to content

Commit

Permalink
allow contemporaneous dependency for multivariate responses in differ…
Browse files Browse the repository at this point in the history
…ent components
  • Loading branch information
santikka committed Apr 22, 2024
1 parent 4401c1d commit 69ad700
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 20 additions & 5 deletions R/dynamiteformula.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,26 @@ parse_formula <- function(x, family) {
formula_parts
)
formulas <- lapply(paste0(responses, "~", formula_parts), as.formula)
predictors <- ulapply(formulas, function(y) {
find_nonlags(formula_rhs(y))
})
resp_pred <- responses %in% predictors
predictors <- lapply(
formulas,
function(y) {
find_nonlags(formula_rhs(y))
}
)
resp_pred <- vapply(
seq_along(responses),
function(i) {
responses[i] %in% predictors[[i]]
},
logical(1L)
)
# predictors <- ulapply(
# formulas,
# function(y) {
# find_nonlags(formula_rhs(y))
# }
# )
# resp_pred <- responses %in% predictors
p <- sum(resp_pred)
stopifnot_(
!any(resp_pred),
Expand Down Expand Up @@ -353,7 +369,6 @@ parse_name <- function(x) {
gsub("[^[:alnum:]_]+", "", x, perl = TRUE)
}


#' @rdname dynamiteformula
#' @param e1 \[`dynamiteformula`]\cr A model formula specification.
#' @param e2 \[`dynamiteformula`]\cr A model formula specification.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ test_that("contemporaneous self dependency within a channel fails", {
)
)
expect_error(
obs(c(y, x) ~ x | 1, family = "mvgaussian"),
obs(c(y, x) ~ y | 1, family = "mvgaussian"),
paste0(
"Contemporaneous self-dependency found in model formula:\n",
"x Variable `x` appears on both sides of the formula for \\(y, x\\)\\."
"x Variable `y` appears on both sides of the formula for \\(y, x\\)\\."
)
)
})
Expand Down

0 comments on commit 69ad700

Please sign in to comment.