@@ -1133,21 +1133,6 @@ mcmc_chains = function(object,
1133
1133
# for rstanarm/brms objects - set to NULL by default
1134
1134
sp_names <- NULL
1135
1135
1136
- # if from R2jags::jags.parallel
1137
- if (methods :: is(object , ' rjags.parallel' ))
1138
- {
1139
- x <- object $ BUGSoutput
1140
- mclist <- vector(' list' , x $ n.chains )
1141
- mclis <- vector(' list' , x $ n.chains )
1142
- ord <- dimnames(x $ sims.array )[[3 ]]
1143
- for (i in 1 : x $ n.chains )
1144
- {
1145
- tmp1 <- x $ sims.array [, i , ord ]
1146
- mclis [[i ]] <- coda :: mcmc(tmp1 , thin = x $ n.thin )
1147
- }
1148
- object <- coda :: as.mcmc.list(mclis )
1149
- }
1150
-
1151
1136
# if mcmc object (from nimble) - convert to mcmc.list
1152
1137
if (methods :: is(object , ' mcmc' ))
1153
1138
{
@@ -1160,13 +1145,6 @@ mcmc_chains = function(object,
1160
1145
object <- coda :: mcmc.list(lapply(object , function (x ) coda :: mcmc(x )))
1161
1146
}
1162
1147
1163
- # if from rstanarm::stan_glm
1164
- if (methods :: is(object , ' stanreg' ))
1165
- {
1166
- object <- object $ stanfit
1167
- sp_names <- object @ sim $ fnames_oi
1168
- }
1169
-
1170
1148
if (coda :: is.mcmc.list(object ) != TRUE &
1171
1149
! methods :: is(object , ' matrix' ) &
1172
1150
! methods :: is(object , ' mcmc' ) &
@@ -1180,25 +1158,6 @@ mcmc_chains = function(object,
1180
1158
stop(' Invalid object type. Input must be stanfit object (rstan), CmdStanMCMC object (cmdstanr), stanreg object (rstanarm), brmsfit object (brms), mcmc.list object (coda/rjags), mcmc object (coda/nimble), list object (nimble), rjags object (R2jags), jagsUI object (jagsUI), or matrix with MCMC chains.' )
1181
1159
}
1182
1160
1183
- # if from brms::brm
1184
- if (methods :: is(object , ' brmsfit' ))
1185
- {
1186
- # extract stanfit portion of object
1187
- object <- object $ fit
1188
- # Stan names
1189
- sp_names_p <- names(object @ sim $ samples [[1 ]])
1190
- # remove b_ and r_
1191
- st_nm <- substr(sp_names_p , start = 1 , stop = 2 )
1192
- sp_names <- rep(NA , length(sp_names_p ))
1193
- b_idx <- which(st_nm == ' b_' )
1194
- r_idx <- which(st_nm == ' r_' )
1195
- ot_idx <- which(st_nm != ' b_' & st_nm != ' r_' )
1196
- # fill names vec with b_ and r_ removed
1197
- sp_names [b_idx ] <- gsub(' b_' , ' ' , sp_names_p [b_idx ])
1198
- sp_names [r_idx ] <- gsub(' r_' , ' ' , sp_names_p [r_idx ])
1199
- sp_names [ot_idx ] <- sp_names_p [ot_idx ]
1200
- }
1201
-
1202
1161
# NAME SORTING BLOCK
1203
1162
if (methods :: is(object , ' stanfit' ))
1204
1163
{
@@ -4271,66 +4230,13 @@ check_rhat <- function(fit, quiet=FALSE, fit_summary) {
4271
4230
# ' @param quiet Logical (verbose or not?)
4272
4231
# ' @details Utility function written by Michael Betancourt (https://betanalpha.github.io/)
4273
4232
# ' @noRd
4274
- check_all_diagnostics <- function (fit , quiet = FALSE , max_treedepth = 10 ) {
4233
+ check_all_diagnostics <- function (fit , max_treedepth = 10 ) {
4275
4234
sampler_params <- rstan :: get_sampler_params(fit , inc_warmup = FALSE )
4276
4235
fit_summary <- rstan :: summary(fit , probs = c(0.5 ))$ summary
4277
- if (! quiet ) {
4278
- check_n_eff(fit , fit_summary = fit_summary )
4279
- check_rhat(fit , fit_summary = fit_summary )
4280
- check_div(fit , sampler_params = sampler_params )
4281
- check_treedepth(fit , max_depth = max_treedepth ,
4282
- sampler_params = sampler_params )
4283
- check_energy(fit , sampler_params = sampler_params )
4284
- } else {
4285
- warning_code <- 0
4286
-
4287
- if (! check_n_eff(fit , quiet = TRUE , fit_summary = fit_summary ))
4288
- warning_code <- bitwOr(warning_code , bitwShiftL(1 , 0 ))
4289
- if (! check_rhat(fit , quiet = TRUE , fit_summary = fit_summary ))
4290
- warning_code <- bitwOr(warning_code , bitwShiftL(1 , 1 ))
4291
- if (! check_div(fit , quiet = TRUE , sampler_params = sampler_params ))
4292
- warning_code <- bitwOr(warning_code , bitwShiftL(1 , 2 ))
4293
- if (! check_treedepth(fit , quiet = TRUE , sampler_params = sampler_params ))
4294
- warning_code <- bitwOr(warning_code , bitwShiftL(1 , 3 ))
4295
- if (! check_energy(fit , quiet = TRUE , sampler_params = sampler_params ))
4296
- warning_code <- bitwOr(warning_code , bitwShiftL(1 , 4 ))
4297
-
4298
- return (warning_code )
4299
- }
4300
- }
4301
-
4302
- # ' Parse warnings
4303
- # ' @param warning_code Type of warning code to generate
4304
- # ' @details Utility function written by Michael Betancourt (https://betanalpha.github.io/)
4305
- # ' @noRd
4306
- parse_warning_code <- function (warning_code ) {
4307
- if (bitwAnd(warning_code , bitwShiftL(1 , 0 )))
4308
- cat(" n_eff / iteration warning" )
4309
- if (bitwAnd(warning_code , bitwShiftL(1 , 1 )))
4310
- cat(" rhat warning" )
4311
- if (bitwAnd(warning_code , bitwShiftL(1 , 2 )))
4312
- cat(" divergence warning" )
4313
- if (bitwAnd(warning_code , bitwShiftL(1 , 3 )))
4314
- cat(" treedepth warning" )
4315
- if (bitwAnd(warning_code , bitwShiftL(1 , 4 )))
4316
- cat(" energy warning" )
4317
- }
4318
-
4319
- # ' Return parameter arrays separated into divergent and non-divergent transitions
4320
- # ' @param fit A stanfit object
4321
- # ' @details Utility function written by Michael Betancourt (https://betanalpha.github.io/)
4322
- # ' @noRd
4323
- partition_div <- function (fit ) {
4324
- nom_params <- rstan :: extract(fit , permuted = FALSE )
4325
- n_chains <- dim(nom_params )[2 ]
4326
- params <- as.data.frame(do.call(rbind , lapply(1 : n_chains , function (n ) nom_params [,n ,])))
4327
-
4328
- sampler_params <- rstan :: get_sampler_params(fit , inc_warmup = FALSE )
4329
- divergent <- do.call(rbind , sampler_params )[,' divergent__' ]
4330
- params $ divergent <- divergent
4331
-
4332
- div_params <- params [params $ divergent == 1 ,]
4333
- nondiv_params <- params [params $ divergent == 0 ,]
4334
-
4335
- return (list (div_params , nondiv_params ))
4236
+ check_n_eff(fit , fit_summary = fit_summary )
4237
+ check_rhat(fit , fit_summary = fit_summary )
4238
+ check_div(fit , sampler_params = sampler_params )
4239
+ check_treedepth(fit , max_depth = max_treedepth ,
4240
+ sampler_params = sampler_params )
4241
+ check_energy(fit , sampler_params = sampler_params )
4336
4242
}
0 commit comments