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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tools/lib
tools/*.html
\#\*R:scripts\*\#
demon.org
tools/coverage-test-failures.zip
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.4.1
Date: 2026-06-23 12:55:28 UTC
SHA: 2f488b3aa26db9b410db06b9992defa0d3dabdcb
Date: 2026-06-23 14:20:55 UTC
SHA: a6dd636783dd7e4c660715e64382cf5834562c60
3 changes: 2 additions & 1 deletion R/brmSS.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#' and T_5(mu, 3) priors for changepoint parameters.
#' This is done because the values are strictly positive and the lognormal distribution
#' is easily interpreted. The changepoint priors are T distributions for symmetry, 5 DF
#' having been chosen for heavy but not unmanageable tails.
#' having been chosen for heavy but not unmanageable tails. Constant priors can be specified
#' by providing the value as a string (ie, "3" for a constant 3 value for that variable).
#' If this argument is not provided then priors are not
#' returned and a different set of priors will need to be made for the model using
#' \code{brms::set_prior}. This works similarly to the \code{params} argument
Expand Down
6 changes: 5 additions & 1 deletion R/brmSSHelpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
default_prior <- .explicitDefaultPrior(formula, df, family)
default_interaction_prior <- default_prior[grepl(":", default_prior$coef), ]
tenth_of_priors <- lapply(priors, function(x) {
return(mean(x) / 10)
return(mean(as.numeric(x)) / 10)
})
for (nlp in unique(default_interaction_prior$nlpar)) {
sd <- ifelse(nlp %in% names(tenth_of_priors), tenth_of_priors[[nlp]], 3)
Expand Down Expand Up @@ -191,6 +191,10 @@
.stanStringHelper <- function(priors, pars, USEGROUP) {
if (!is.null(pars)) {
priorStanStrings <- lapply(pars, function(par) {
if (methods::is(priors[[par]][1], "character")) {
par_string <- paste0("constant(", priors[[par]], ")") # constant prior
return(par_string)
}
if (!grepl("changePoint|I$", par)) {
par_string <- paste0("lognormal(log(", priors[[par]], "), 0.25)") # growth parameters are LN
} else {
Expand Down
4 changes: 2 additions & 2 deletions R/conjugate.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ conjugate <- function(s1 = NULL, s2 = NULL,
sample <- samplesList[[i]]
prior <- priors[[i]]
#* `Check sample class`
if (is.matrix(sample) | is.data.frame(sample)) {
if (is.matrix(sample) || is.data.frame(sample)) {
vec_suffix <- "mv"
sample <- .mvSampleFormatting(sample)
} else if (is.vector(sample)) {
Expand Down Expand Up @@ -531,7 +531,7 @@ conjugate <- function(s1 = NULL, s2 = NULL,
sample <- samplesList[[i]]
prior <- priors[[i]]
#* `Check sample class`
if (is.matrix(sample) | is.data.frame(sample)) {
if (is.matrix(sample) || is.data.frame(sample)) {
vec <- FALSE
} else if (is.vector(sample)) {
vec <- TRUE
Expand Down
2 changes: 2 additions & 0 deletions R/growthSS.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
#' If this is not provided then starting values are picked with \code{stats::selfStart}.
#' When type = "brms" these should be provided and are treated as the means of
#' lognormal priors for all growth model parameters and T_5(mu, 3) priors for changepoint parameters.
#' Constant priors can be specified by providing the value as a string
#' (ie, "3" for a constant 3 value for that variable).
#' This is done because the values are strictly positive and the lognormal distribution
#' is easily interpreted. The changepoint priors are T distributions for symmetry, 5 DF
#' having been chosen for heavy but not unmanageable tails.
Expand Down
16 changes: 8 additions & 8 deletions R/growthSim.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@
#'

growthSim <- function(
model = c(
"logistic", "logistic4", "logistic5", "gompertz", "double logistic", "double gompertz",
"monomolecular", "exponential", "linear", "power law", "frechet", "weibull", "gumbel",
"logarithmic", "bragg", "lorentz", "beta"
),
n = 20, t = 25, params = list(), D = 0,
returnParams = FALSE) {
model = c(
"logistic", "logistic4", "logistic5", "gompertz", "double logistic", "double gompertz",
"monomolecular", "exponential", "linear", "power law", "frechet", "weibull", "gumbel",
"logarithmic", "bragg", "lorentz", "beta"
),
n = 20, t = 25, params = list(), D = 0,
returnParams = FALSE) {
if (grepl("count:", model)) {
COUNT <- TRUE
model <- trimws(gsub("count:", "", model))
Expand Down Expand Up @@ -388,7 +388,7 @@ growthSim <- function(
names(iterNoise) <- sub(paste0(iterModelFindParams, u, "|Point."), "", names(iterNoise))

iter_data <- do.call(rbind, lapply(1:n, function(i) {
if (is.null(nextChangepoints) | u == length(component_models)) {
if (is.null(nextChangepoints) || u == length(component_models)) {
iterChangepointsRand <- rep(t, length(iterParams[[1]]))
} else {
iterChangepointsRand <- lapply(nextChangepoints, function(fc) {
Expand Down
4 changes: 2 additions & 2 deletions R/mv_ag.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mv_ag <- function(df, group, mvCols = "frequencies", n_per_group = 1, outRows =
}
rownames(mv) <- seq_len(nrow(mv))
nms <- sample(rownames(mv), nrow(mv), replace = FALSE)
if (nrow(mv) > 1 & iter_n > 1) {
if (nrow(mv) > 1 && iter_n > 1) {
index <- cut(seq_len(nrow(mv)), iter_n)
nms_split <- split(nms, index)
} else {
Expand Down Expand Up @@ -199,7 +199,7 @@ mv_ag <- function(df, group, mvCols = "frequencies", n_per_group = 1, outRows =
return(id_d)
}))
#* separate IDS into groups
if (length(IDS) > 1 & iter_n > 1) {
if (length(IDS) > 1 && iter_n > 1) {
index <- cut(seq_along(IDS), iter_n)
ids_split <- split(IDS, index)
} else {
Expand Down
15 changes: 6 additions & 9 deletions R/readpcv3.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@
#' @export

read.pcv.3 <- function(
file = NULL,
snapshotFile = NULL,
designFile = NULL,
metaCol = "meta",
metaForm = "vis_view_angle_zoom_horizontal_gain_exposure_v_new_n_rep",
joinSnapshot = "id",
conversions = NULL,
mode = "long",
...) {
file = NULL, snapshotFile = NULL, designFile = NULL,
metaCol = "meta",
metaForm = "vis_view_angle_zoom_horizontal_gain_exposure_v_new_n_rep",
joinSnapshot = "id", conversions = NULL,
mode = "long", ...) {

phenos <- read.pcv(filepath = file, mode = mode, ...)

#* `parse metadata`
Expand Down
12 changes: 10 additions & 2 deletions R/stat_brms_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ statBrmsMod <- ggplot2::ggproto("StatBrm", Stat,
}
old <- old[, !(names(old) %in% names(new)), drop = FALSE]
non_constant <- vapply(old, vctrs::vec_unique_count, integer(1)) > 1L
non_constant_columns <<- c(non_constant_columns, names(old)[non_constant])
assign(
"non_constant_columns",
c(non_constant_columns, names(old)[non_constant]),
parent.frame()
)
vc <- vctrs:::vec_cbind(
new,
old[rep(1, nrow(new)), , drop = FALSE]
Expand Down Expand Up @@ -214,7 +218,11 @@ statBrmsStaticMod <- ggplot2::ggproto("StatStaticBrm", Stat,
}
old <- old[, !(names(old) %in% names(new)), drop = FALSE]
non_constant <- vapply(old, vctrs::vec_unique_count, integer(1)) > 1L
non_constant_columns <<- c(non_constant_columns, names(old)[non_constant])
assign(
"non_constant_columns",
c(non_constant_columns, names(old)[non_constant]),
parent.frame()
)
vc <- vctrs:::vec_cbind(
new,
old[rep(1, nrow(new)), , drop = FALSE]
Expand Down
6 changes: 5 additions & 1 deletion R/stat_nlme_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ statNlmeMod <- ggplot2::ggproto("StatNlme", Stat,
}
old <- old[, !(names(old) %in% names(new)), drop = FALSE]
non_constant <- vapply(old, vctrs::vec_unique_count, integer(1)) > 1L
non_constant_columns <<- c(non_constant_columns, names(old)[non_constant])
assign(
"non_constant_columns",
c(non_constant_columns, names(old)[non_constant]),
parent.frame()
)
vc <- vctrs:::vec_cbind(
new,
old[rep(1, nrow(new)), , drop = FALSE]
Expand Down
6 changes: 5 additions & 1 deletion R/stat_nls_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ statNlsMod <- ggplot2::ggproto("StatNls", Stat,
}
old <- old[, !(names(old) %in% names(new)), drop = FALSE]
non_constant <- vapply(old, vctrs::vec_unique_count, integer(1)) > 1L
non_constant_columns <<- c(non_constant_columns, names(old)[non_constant])
assign(
"non_constant_columns",
c(non_constant_columns, names(old)[non_constant]),
parent.frame()
)
vc <- vctrs:::vec_cbind(
new,
old[rep(1, nrow(new)), , drop = FALSE]
Expand Down
2 changes: 2 additions & 0 deletions man/growthSS.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test-brmsModels.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ test_that("Logistic brms model pipeline", {
n = 20, t = 25,
params = list("A" = c(200, 160), "B" = c(13, 11), "C" = c(3, 3.5))
)
ss <- growthSS(
model = "logistic", form = y ~ time | id / group, sigma = "gam",
list("A" = 130, "B" = 10, "C" = "3"), # "3" as a string for a constant prior
df = simdf, type = "brms"
)
ss <- growthSS(
model = "logistic", form = y ~ time | id / group, sigma = "gam",
list("A" = 130, "B" = 10, "C" = 3),
Expand Down
Loading