Learn R Programming

sourceR (version 0.2.0)

summary.source_attribution: Summary function for saBayes output.

Description

This function generates a median and Chen Shao highest posterior density (HPD) region for each parameter in a source attribution model (source_attribution object). This algorithm requires unimodiality of the marginal posterior distribution for each parameter. If the marginal posterior distribution is not unimodel, the HPD region calculated may be invalid.

Usage

"summary"(object, alpha = 0.05, burn_in = 0, thin = 1, interval_type = "chen-shao", ...)

Arguments

object
an object that inherits from class source_attribution, such as a source_attribution object produced using saBayes.
alpha
a 100(1-alpha)% interval has a probability content of 1-alpha.
burn_in
the number iterations to remove from the beginning of the MCMC chain prior to calculating the HPD intervals. A value of 0 results in no burn in being removed.
thin
the amount to thin the MCMC chain by prior to calculating the HPD intervals. A vlaue of 1 results in no thinning.
interval_type
The type of HPD to calculate. This defaults to Chen Shao, but can be set to SPIn
...
Does nothing at the moment.

Value

Returns a list with possible names a, q, alpha, r, d, li, lj and lj_proportion. The list contains the same nesting structure as posterior.
Parameter Format and nesting
Returns Source effects (a)
A nested list with a matrix for each time and location. Always returned.
eg posterior$a[[t]][[l]][,j] gives the median,
lower and upper values of the Chen Shao HPD region for
a j for time t, location l.
Type effects (q)
A matrix. eg posterior$q[,i] gives the the median, Returned if
lower and upper values of the Chen Shao HPD region for
names(posterior)
q i for time t. contains q.
r A nested list containing an array for each time.
Returned if
eg posterior$r[[t]][i,j,] gives the median, lower names(posterior)
and upper values of the Chen Shao HPD region for r
contains r.
(type i, source j) at time t.
Dispersion parameter (d) A vector.
Returned if
names(posterior)
contains d. Rate of human infection
A nested list with a matrix for each time and location. Returned if
from type i (Lambda i: li) eg posterior$li[[t]][[l]][,i] gives the median,
names(posterior)
lower and upper values of the Chen Shao HPD region for contains li.
li i for time t, location l.
Rate of human infection
A nested list with a matrix for each time and location. Returned if
from source j (Lambda j: lj) eg posterior$lj[[t]][[l]][,j] gives the median,
names(posterior)
lower and upper values of the Chen Shao HPD region for contains lj.
lj j for time t, location l.
Proportion of human
A nested list with a matrix for each time and location. Returned if
infection from source eg posterior$lj_proportion[[t]][[l]][,j] gives
names(posterior) j (lj_proportion)
the median, lower and upper values of the Chen Shao HPD contains lj.
region for lj_proportion j for time t,
location l.

References

Chen, M.-H. and Shao, Q.-M. (1998). Monte Carlo estimation of Bayesian credible and HPD intervals, Journal of Computational and Graphical Statistics, 7. Liu Y, Gelman A, Zheng T (2015). "Simulation-efficient shortest probability intervals." Statistics and Computing.

See Also

saBayes, flatten, subset_posterior

Examples

Run this code

##########################################################################
## Access simulated data set #############################################
##########################################################################
data(sim_SA)

##########################################################################
## Set priors ############################################################
##########################################################################

priors <- list(a = 1, r = 1, theta = c(0.01, 0.00001))

##########################################################################
## Run model #############################################################
##########################################################################

res <- saBayes(formula = Human~Source1+Source2+Source3+Source4+Source5, 
               time=~Time, location=~Location, type=~Type,
               data=sim_SA$data, priors = priors,
               alpha_conc = 1, prev = sim_SA$prev,
               likelihood_dist = "pois", n_iter = 20)
               
##########################################################################
#### Summary #############################################################
##########################################################################

s <- summary(res, alpha = 0.05, burn_in = 1, thin = 1)
# print the median and HPD for the type effects
s$q            
# print the median and HPD for the lambda's for each source
# for time 2, location A
s$lj_proportion$time2$locationA 
## or
s$lj_proportion[[2]][[1]]

Run the code above in your browser using DataLab