Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
beckyfisher committed Sep 9, 2024
1 parent 64611ea commit 1d58906
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Depends:
License: GPL-2
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Biarch: true
Imports:
formula.tools,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(loo,loo_model_weights)
importFrom(modelbased,zero_crossings)
importFrom(purrr,map)
importFrom(purrr,map_dfr)
importFrom(rlang,.data)
Expand Down
4 changes: 2 additions & 2 deletions R/ecx.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ ecx.bayesnecfit <- function(object, ecx_val = 10, resolution = 1000,
x_vec <- newdata_list$x_vec
if (grepl("horme", object$model)) {
n <- seq_len(nrow(p_samples))
p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
p_samples, hormesis_def, fct = "rbind")
#p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
# p_samples, hormesis_def, fct = "rbind")
}
ecx_fct <- get(paste0("ecx_x_", type))
ecx_out <- apply(p_samples, 1, ecx_fct, ecx_val, x_vec)
Expand Down
7 changes: 5 additions & 2 deletions R/expand_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ expand_nec <- function(object, formula, x_range = NA, resolution = 1000,
}
if (mod_class == "ecx") {
reference <- quantile(pred_posterior[, 1], sig_val)
grab <- apply(pred_posterior - reference, 1, min_abs)
ne_posterior <- pred_data$x[grab]
# grab <- apply(pred_posterior - reference, 1, min_abs)
# ne_posterior <- pred_data$x[grab]
ne_posterior <- apply(pred_posterior, 1, nsec_fct,
reference = reference, x_vec = pred_data$x)

x_str <- grep("crf(", labels(terms(formula)), fixed = TRUE, value = TRUE)
x_call <- str2lang(eval(parse(text = x_str)))
if (inherits(x_call, "call")) {
Expand Down
27 changes: 18 additions & 9 deletions R/nsec.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ nsec.bayesnecfit <- function(object, sig_val = 0.01, resolution = 1000,
ecnsec <- quantile(ecnsecP, probs = prob_vals)
if (grepl("horme", object$model)) {
n <- seq_len(nrow(p_samples))
p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
p_samples, hormesis_def, fct = "rbind")
nec_posterior <- as_draws_df(object$fit)[["b_nec_Intercept"]]
#p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
# p_samples, hormesis_def, fct = "rbind")
#nec_posterior <- as_draws_df(object$fit)[["b_nec_Intercept"]]
if (hormesis_def == "max") {
reference <- quantile(apply(p_samples, 2, max), probs = sig_val)
}
Expand Down Expand Up @@ -218,10 +218,19 @@ nsec.bayesmanecfit <- function(object, sig_val = 0.01, resolution = 1000,
}

#' @noRd
#' @importFrom modelbased zero_crossings
nsec_fct <- function(y, reference, x_vec) {
x_vec[min_abs(y - reference)]
val <- min(zero_crossings(y - reference))
if(is.na(val)) {
return(max(x_vec))} else {
floor_x <- x_vec[floor(val)]
ceiling_x <- x_vec[ceiling(val)]
prop_x <- (val-floor(val))*(ceiling_x-floor_x)
return(floor_x + prop_x)
}
}


#' @inheritParams nsec
#'
#' @param object An object of class \code{\link{brmsfit}} returned by
Expand Down Expand Up @@ -308,9 +317,9 @@ nsec.brmsfit <- function(object, sig_val = 0.01, resolution = 1000,

if (horme) {
n <- seq_len(nrow(p_samples))
p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
p_samples, hormesis_def, fct = "rbind")
nec_posterior <- as_draws_df(object$fit)[["b_nec_Intercept"]]
#p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
# p_samples, hormesis_def, fct = "rbind")
#nec_posterior <- as_draws_df(object$fit)[["b_nec_Intercept"]]
if (hormesis_def == "max") {
reference <- quantile(apply(p_samples, 2, max), probs = sig_val)
}
Expand All @@ -334,8 +343,8 @@ nsec.brmsfit <- function(object, sig_val = 0.01, resolution = 1000,
ecnsec <- quantile(ecnsecP, probs = prob_vals)
if (horme) {
n <- seq_len(nrow(p_samples))
p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
p_samples, hormesis_def, fct = "rbind")
#p_samples <- do_wrapper(n, modify_posterior, object, x_vec,
# p_samples, hormesis_def, fct = "rbind")
nec_posterior <- as_draws_df(object$fit)[["b_nec_Intercept"]]
if (hormesis_def == "max") {
reference <- quantile(apply(p_samples, 2, max), probs = sig_val)
Expand Down
19 changes: 19 additions & 0 deletions man/bayesnec-package.Rd

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

5 changes: 4 additions & 1 deletion man/check_priors.Rd

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

0 comments on commit 1d58906

Please sign in to comment.