-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d69d8d
commit 80d6e7b
Showing
18 changed files
with
50 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,6 @@ | |
#' @param fit An object of class \code{brmsfit}. | ||
#' @param var The variable to obtain. | ||
#' @return A \code{data.frame}. | ||
#' | ||
#' @author Darcy Webber \email{[email protected]} | ||
#' | ||
#' @importFrom reshape2 melt | ||
#' @importFrom readr parse_number | ||
#' @importFrom nlme fixef ranef | ||
|
@@ -124,23 +121,21 @@ get_coefs_raw <- function(fit, var = "area") { | |
#' @param hurdle If a hurdle model then use the hurdle. | ||
#' @param transform if the coefficients should be transformed using the link function. | ||
#' @return A \code{data.frame}. | ||
#' | ||
#' @importFrom reshape2 melt | ||
#' @importFrom readr parse_number | ||
#' @importFrom nlme fixef ranef | ||
#' @importFrom brms posterior_samples | ||
#' @import dplyr | ||
#' @export | ||
#' | ||
get_coefs <- function(fit, var = "area", | ||
get_coefs <- function(fit, | ||
var = "area", | ||
normalise = TRUE, | ||
hurdle = FALSE, | ||
transform = FALSE) { | ||
|
||
if (!is.brmsfit(fit)) stop("fit is not an object of class brmsfit.") | ||
|
||
type <- id_var_type(fit = fit, xfocus = var, hurdle = hurdle) | ||
|
||
is_poly <- FALSE | ||
|
||
if (any(grepl("\\(1 \\|", var))) { | ||
|
@@ -156,8 +151,7 @@ get_coefs <- function(fit, var = "area", | |
mutate(variable = gsub(".*\\[|\\]", "", variable)) %>% | ||
mutate(variable = gsub(",Intercept", "", variable)) | ||
if (!str_detect(var, ":")) { | ||
ps <- ps %>% | ||
filter(!str_detect(variable, ":")) | ||
ps <- ps %>% filter(!str_detect(variable, ":")) | ||
} | ||
} else { | ||
# Population-level effects | ||
|
@@ -182,11 +176,8 @@ get_coefs <- function(fit, var = "area", | |
ps <- ps %>% | ||
filter(!str_detect(variable, ":")) | ||
} | ||
# mutate(variable = paste0(var, gregexpr("[[:digit:]]+", variable))) | ||
# mutate(variable = paste0(var, parse_number(as.character(variable)))) | ||
# unique(ps$variable) | ||
# tail(ps) | ||
} | ||
# unique(ps$variable) | ||
|
||
# Check to see if this is a polynomial | ||
if (any(grepl("poly", ps$variable))) { | ||
|
@@ -203,8 +194,7 @@ get_coefs <- function(fit, var = "area", | |
filter(grepl("hu", variable)) %>% | ||
mutate(variable = gsub("hu_", "", variable)) | ||
} else { | ||
ps <- ps %>% | ||
filter(!grepl("hu", variable)) | ||
ps <- ps %>% filter(!grepl("hu", variable)) | ||
} | ||
} | ||
|
||
|
@@ -232,7 +222,12 @@ get_coefs <- function(fit, var = "area", | |
value = 0) | ||
coefs <- rbind(ps0, ps) | ||
} else { | ||
coefs <- ps | ||
data <- fit$data | ||
data[,var] <- paste0(var, data[,var]) | ||
ps0 <- data.frame(iteration = 1:max(ps$iteration), | ||
variable = unique(data[,var])[!unique(data[,var]) %in% unique(ps$variable)], | ||
value = 0) | ||
coefs <- rbind(ps0, ps) | ||
} | ||
|
||
# Arrange by vessel coefficient if vessel chosen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,7 @@ | |
#' the same for all and raw, but the legend will change from numbers of records to a proportion. | ||
#' @param ... Further arguments passed to nothing. | ||
#' @return a \code{ggplot} object. | ||
#' | ||
#' @author Darcy Webber \email{[email protected]} | ||
#' | ||
#' @seealso \code{\link{get_coefs}}, \code{\link{get_influ}}, \code{\link{plot_bubble}} | ||
#' | ||
#' @importFrom gtable is.gtable gtable_filter | ||
#' @importFrom stats poly | ||
#' @importFrom tidyselect all_of | ||
|
@@ -49,7 +45,6 @@ plot_bayesian_cdi <- function(fit, | |
sum_by = "row", ...) { | ||
|
||
if (!is.brmsfit(fit)) stop("fit is not an object of class brmsfit.") | ||
|
||
if (is.null(xlab)) xlab <- xfocus | ||
if (is.null(ylab)) ylab <- yfocus | ||
y_coefs <- "Conditional effect" | ||
|
@@ -58,10 +53,15 @@ plot_bayesian_cdi <- function(fit, | |
type <- id_var_type(fit = fit, xfocus = xfocus, hurdle = hurdle) | ||
|
||
# Posterior samples of coefficients | ||
# if (type %in% c("random_effect")) { | ||
if (type %in% c("fixed_effect", "random_effect")) { | ||
coefs <- get_coefs(fit = fit, var = xfocus, hurdle = hurdle) | ||
} else { | ||
coefs <- get_marginal(fit = fit, var = xfocus) # this would plot the marginal/conditional effect, but if it is a hurdle model it ignores the hurdle bit | ||
# this would plot the marginal/conditional effect, but if it is a hurdle model it ignores the hurdle bit | ||
coefs <- get_marginal(fit = fit, var = xfocus)# %>% | ||
# mutate(value = log(value)) | ||
# library(marginaleffects) | ||
# pred <- predictions(model = fit) | ||
# coefs <- get_coefs_raw(fit = fit, var = xfocus) | ||
} | ||
|
||
|
@@ -73,9 +73,7 @@ plot_bayesian_cdi <- function(fit, | |
|
||
# Model data | ||
if (is.numeric(coefs$variable)) { | ||
data <- fit$data %>% | ||
select(all_of(c(yfocus, xfocus))) | ||
|
||
data <- fit$data %>% select(all_of(c(yfocus, xfocus))) | ||
length.out <- 15 | ||
dmin <- min(data[,xfocus]) | ||
dmax <- max(data[,xfocus]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.