Skip to content
Open
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
2 changes: 1 addition & 1 deletion R/get_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ get_formula_str = function(ST, par_x, ytype = "ct", init = FALSE) {
if (ytype == "ct") {
formula_str = paste0(formula_str, "\n\n# Fitted value\ny_[i_] = \n")
} else if (ytype == "sigma") {
formula_str = paste0(formula_str, "# Fitted standard deviation\nsigma_[i_] = max(0, \n") # Add max(0, [formula]) to prevent modeling negative sigmas. JAGS uses precision = 1 / sigma^2 which yields positive precisions for negative sigmas.
formula_str = paste0(formula_str, "# Fitted standard deviation\nsigma_[i_] = max(0.001, \n") # Add max(0, [formula]) to prevent modeling negative sigmas. JAGS uses precision = 1 / sigma^2 which yields positive precisions for negative sigmas.
} else if (stringr::str_detect(ytype, "ar[0-9]+")) {
formula_str = paste0(formula_str, "# Autoregressive coefficient for all AR(", ar_order,")\n", ytype, "_[i_] = \n")
} else if (stringr::str_detect(ytype, "ma[0-9]+")) {
Expand Down
4 changes: 3 additions & 1 deletion R/get_jagscode.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ get_jagscode = function(prior, ST, formula_str, arma_order, family, sample) {
# Compute residuals for AR
if (has_ar) {
if (family$family == "binomial") {
mm = paste0(mm, "\n resid_abs_[i_] = ", family$linkfun_str, "(", ST$y[1], "[i_] / ", ST$trials[1], "[i_]) - y_[i_] # Residuals represented by sigma_ after ARMA")
mm = paste0(mm, "\n resid_abs_[i_] = ", family$linkfun_str, "(0.01 + 0.98 * ", ST$y[1], "[i_] / ", ST$trials[1], "[i_]) - y_[i_] # Residuals represented by sigma_ after ARMA")
} else if (family$family == "poisson") {
mm = paste0(mm, "\n resid_abs_[i_] = ", family$linkfun_str, "(0.01 + ", ST$y[1], "[i_]) - y_[i_] # Residuals represented by sigma_ after ARMA")
} else {
mm = paste0(mm, "\n resid_abs_[i_] = ", family$linkfun_str, "(", ST$y[1], "[i_]) - y_[i_] # Residuals represented by sigma_ after ARMA")
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/helper-runs.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ test_plot = function(fit, varying_cols) {
is_expected = any(stringr::str_detect(error_message, expected_error))
expect_true(is_expected)
} else {
testthat::expect_true(ggplot2::is.ggplot(gg))
testthat::expect_true(ggplot2::is_ggplot(gg))
}
}

# Test plot() calls to bayesplot
test_plot_pars = function(fit) {
gg = plot_pars(fit, type = "dens_overlay")
testthat::expect_true(ggplot2::is.ggplot(gg))
testthat::expect_true(ggplot2::is_ggplot(gg))
}


Expand All @@ -194,7 +194,7 @@ test_hypothesis = function(fit) {

# Varying
if (!is.null(fit$pars$varying)) {
mcmc_vars = colnames(mcmclist_samples(fit)[[1]])
mcmc_vars = colnames(mcp:::mcmclist_samples(fit)[[1]])
varying_starts = paste0("^", fit$pars$varying[1])
varying_col_ids = stringr::str_detect(mcmc_vars, varying_starts)
varying_cols = paste0("`", mcmc_vars[varying_col_ids], "`") # Add these for varying
Expand Down Expand Up @@ -298,7 +298,7 @@ test_pp_eval = function(fit) {
testthat::expect_true(error_message)
}
} else {
testthat::expect_true(ggplot2::is.ggplot(pp_default))
testthat::expect_true(ggplot2::is_ggplot(pp_default))
}
}

Expand Down