Skip to content

Commit

Permalink
fixed jointModel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abigailkeller committed Dec 23, 2024
1 parent 9f25e9f commit 782db9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions R/muCritical.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ muCritical <- function(modelfit, cov.val = NULL, ci = 0.9) {
}

if(all(is.null(cov.val))){
# extract posteriors for alpha and p10 parameters
##alpha
posterior_alpha <- unlist(rstan::extract(modelfit, pars = "alpha"))
# extract posteriors for beta and p10 parameters
##beta
posterior_beta <- unlist(rstan::extract(modelfit, pars = "alpha"))
#p10
posterior_p10 <- unlist(rstan::extract(modelfit, pars = "p10"))
} else {
Expand All @@ -115,7 +115,7 @@ muCritical <- function(modelfit, cov.val = NULL, ci = 0.9) {
posterior_p10 <- unlist(rstan::extract(modelfit, pars = "p10"))
}

if('q' %in% modelfit@model_pars){
if(modelfit@par_dims$q > 0){
# extract q values
posterior_q <- rstan::extract(modelfit, pars = "q")$q

Expand All @@ -129,10 +129,10 @@ muCritical <- function(modelfit, cov.val = NULL, ci = 0.9) {
colnames(out) <- c('gear_1', gear_names)

# calculate mu_critical -- gear type 1
critical_mu_1 <- rep(NA, length(posterior_alpha))
critical_mu_1 <- rep(NA, length(posterior_beta))
for(i in seq_along(critical_mu_1)){
critical_mu_1[i] <- (
posterior_p10[i]*exp(posterior_alpha[i])/(1-posterior_p10[i])
posterior_p10[i]*exp(posterior_beta[i])/(1-posterior_p10[i])
)
}
out[,1] <- c(stats::median(critical_mu_1),
Expand All @@ -152,10 +152,10 @@ muCritical <- function(modelfit, cov.val = NULL, ci = 0.9) {

} else {
# calculate mu_critical
critical_mu <- rep(NA, length(posterior_alpha))
critical_mu <- rep(NA, length(posterior_beta))
for(i in seq_along(critical_mu)){
critical_mu[i] <- (
posterior_p10[i]*exp(posterior_alpha[i])/(1-posterior_p10[i])
posterior_p10[i]*exp(posterior_beta[i])/(1-posterior_p10[i])
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-jointModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ test_that("jointModel parameter recovery tests work",{
# test that output values are on the same scale as the data
mu_estimates <- rep(NA,nsite)
for(i in 1:nsite){
mu_estimates[i] <- summary1[paste0('mu[',i,']'),'mean']
mu_estimates[i] <- summary1[paste0('mu[',i,',1]'),'mean']
}

# get mean of input count data at each site
Expand Down

0 comments on commit 782db9f

Please sign in to comment.