Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: defm
Type: Package
Title: Estimation and Simulation of Multi-Binary Response Models
Version: 0.2.2.0
Version: 0.2.2.9000
Authors@R: c(
person("George", "Vega Yon", role=c("aut", "cre"),
email="g.vegayon@gmail.com", comment = c(ORCID = "0000-0002-3171-0844")),
Expand All @@ -22,7 +22,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
LinkingTo: Rcpp, barry (>= 0.2.2)
Imports:
Rcpp,
Expand All @@ -34,3 +33,4 @@ Suggests:
texreg, tinytest, barry
Remotes:
USCbiostats/barryr
Config/roxygen2/version: 8.0.0
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# defm 0.2.2.9000 (development version)

* Building against `barry` (>= 0.2.2.9000), currently available from GitHub
(USCbiostats/barryr), fixes the `td_formula()` parser (USCbiostats/barry#26).
The CRAN version of `barry` still has these bugs:
- Covariate names containing `y<digit>` (e.g., `Day1`) were read as motif
terms, silently changing the model: `"{y0} > {y0} x Day1"` became
`Motif {a+}>{a+, b+} x Day1`.
- `"{...}x Covar"` (no space before `x`) silently dropped the covariate.
- Transitions such as `"{y0_1} > {y1}"`, with a current-time term on the
left-hand side, were silently turned into intercept motifs; they now
throw an error.

* The same `barry` version also fixes wrong draws in `sim_defm()` caused by a
support-vs-array index confusion (USCbiostats/barry#25).


# defm 0.2.2.0

* Requires `barry` (>= 0.2.2), which fixes a hash-collision bug that made
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ td_generic <- function(m, mat, covar = "") {
#' - Intercept effect: `{...} x Hispanic` interacts with the Hispanic covar.
#' - Transition effect: `{...} > {...} x Hispanic` Same.
#'
#' The `x` must be followed by a space. Only the terms inside the curly
#' brackets are part of the motif, so covariate names such as `Day1` are
#' fine.
#'
#' ## Intercept effects
#'
#' Intercept effects only involve a single set of curly brackets. Using the
Expand Down
59 changes: 59 additions & 0 deletions inst/tinytest/test_formula_parser.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Regression tests for the formula parser (USCbiostats/barry#26): covariate
# names are not motif terms, `}x Covar` keeps the covariate, and the LHS of a
# transition cannot include the current time.
set.seed(1)
n <- 40
id <- rep(1:10, each = 4)
Y <- matrix(
rbinom(n * 2, 1, .5), ncol = 2,
dimnames = list(NULL, c("a", "b"))
)
X <- cbind(Day1 = runif(n), Female = rbinom(n, 1, .5))

new_model <- function() new_defm(id, Y, X, order = 1)

# The fix lives in barry's headers (LinkingTo), i.e., it is compiled into
# defm. Instead of checking barry's version, we probe the parser defm was
# built with: the unfixed parser reads `y1` from `Day1` and throws
# "The term y1 shows more than once in the formula."
parser_fixed <- tryCatch({
td_formula(new_model(), "{y0} > {y1} x Day1")
TRUE
}, error = function(e) FALSE)

if (!parser_fixed)
exit_file("defm was built against a barry without the formula parser fix.")

# Covariate names containing y<digit>
m <- new_model()
td_formula(m, "{y0} > {y0} x Day1")
td_formula(m, "{y0} > {y1} x Day1")
td_formula(m, "{y0, 0y1} x Day1")
expect_equal(
names(m),
c(
"Motif {a+}>{a+} x Day1",
"Motif {a+}>{b+} x Day1",
"Motif {a+, b-} x Day1"
)
)

# The statistic is weighted by the covariate
init_defm(m)
S <- get_stats(m)
prev <- rbind(NA, Y[-n, ])
prev[c(TRUE, id[-1] != id[-n]), ] <- NA
expect_equal(
unname(S[, 1]),
ifelse(is.na(prev[, 1]), NA, (prev[, 1] == 1 & Y[, 1] == 1) * X[, "Day1"])
)

# No space before `x` keeps the covariate
m <- new_model()
td_formula(m, "{y0} > {y1}x Female")
expect_equal(names(m), "Motif {a+}>{b+} x Female")

# The LHS cannot include the current time
m <- new_model()
expect_error(td_formula(m, "{y0_1} > {y1}"), "LHS")
expect_error(td_formula(m, "{y0_5} > {y1}"), "out of range")
4 changes: 4 additions & 0 deletions man/defm_terms.Rd

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

4 changes: 4 additions & 0 deletions src/terms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ SEXP td_generic(
//' - Intercept effect: `{...} x Hispanic` interacts with the Hispanic covar.
//' - Transition effect: `{...} > {...} x Hispanic` Same.
//'
//' The `x` must be followed by a space. Only the terms inside the curly
//' brackets are part of the motif, so covariate names such as `Day1` are
//' fine.
//'
//' ## Intercept effects
//'
//' Intercept effects only involve a single set of curly brackets. Using the
Expand Down
Loading