This is a wrapper function of MCMCsummary
that calculates summary statistics for each
parameter in a mcmc.list
object. Summary statistics are calculated for all parameters across
each chain along with convergance diagnosics like the Gelman-Rubin convergence diagnostic and (Rhat) and samples
auto-correlation foreach parameter. If the model object contains deviance and penalty parameters, then Deviance Information
Criterion (DIC) is calculated and appended to the summary.
summarize_mobility(mod, ac_lags = c(2, 5, 10))
mod | an mcmc.list object |
---|---|
ac_lags | vector of lags over which to calculate autocorrelation of samples within chains (default = c(2,5,10)) |
a dataframe with summary statistics
Other model:
check_mobility()
,
fit_gravity()
,
fit_jags()
,
fit_mobility()
,
fit_prob_travel()
# Gravity model M <- mobility_matrices$M D <- mobility_matrices$D N <- mobility_matrices$N mod <- fit_gravity(M, D, N, DIC=TRUE)#>#>#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 74 #> Unobserved stochastic nodes: 30 #> Total graph size: 1196 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>summarize_mobility(mod)#> Mean SD HPD2.5 HPD97.5 Rhat SSeff AC2 AC5 #> gamma 1.725217e+00 0.01279210 1.700978e+00 1.751360e+00 1.01 1399 0.20 0.00 #> omega_1 1.350809e+00 0.61885499 5.077172e-01 2.570240e+00 1.06 659 0.51 0.09 #> omega_2 3.221456e-02 0.01559769 4.293284e-03 6.206515e-02 1.00 1040 0.32 0.02 #> theta 1.005430e+00 0.67432014 6.984112e-02 2.330877e+00 1.01 707 0.44 0.07 #> DIC 3.532814e+04 2.47747644 3.532515e+04 3.533301e+04 1.00 938 0.36 0.03 #> deviance 3.531933e+04 2.47747644 3.531633e+04 3.532420e+04 1.00 938 0.36 0.03 #> pD 4.407431e+00 NA NA NA NA NA NA NA #> AC10 #> gamma 0.01 #> omega_1 0.01 #> omega_2 0.00 #> theta 0.01 #> DIC 0.02 #> deviance 0.02 #> pD NA# Probability of travel n_orig <- 10 n_missing <- 3 orig_id <- LETTERS[1:n_orig] N <- rpois(n_orig, 100) # population size of each origin p <- rbeta(n_orig, 1, 2) # probability of leaving origin travel <- setNames(rbinom(n_orig, N, p), orig_id) total <- setNames(N, orig_id) miss <- sample(1:n_orig, n_missing) # missing observations travel[miss] <- total[miss] <- NA # Estimate probability of travel for each locations (missing locations regress to mean) prob_trav <- summarize_mobility( fit_prob_travel(travel=travel, total=total) )#>#>#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 7 #> Unobserved stochastic nodes: 10 #> Total graph size: 29 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>library(ggplot2) ggplot(data=prob_trav) + geom_point(aes(x=Mean, y=orig_id), size=2) + ggstance::geom_linerangeh(aes(y=orig_id, xmin=HPD2.5, xmax=HPD97.5)) + xlab('Probability of travel outside origin') + ylab('Origin') + xlim(0,1) + theme_bw() + theme(axis.text.x=element_text(size=10), axis.text.y=element_text(size=10), axis.title.x=element_text(size=12, margin = margin(t = 15)), axis.title.y=element_text(size=12, margin = margin(r = 15)), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position='right')