Learn R Programming

sourceR (version 0.2.0)

flatten: Flattens the McMC posterior from saBayes output into a data frame.

Description

Flattens the McMC posterior from saBayes output into a data frame with one column per parameter.

Usage

flatten(object)

Arguments

object
an object that inherits from class source_attribution, such as a source_attribution object produced using saBayes.

Value

Returns a data frame with one column per parameter in the object posterior list. The parameters will be named as follows:
Parameter Name format
Source effects (a): a_timeName.locationName.sourceName
Type effects (q): q_typeName
Theta values (theta): theta_typeName
Cluster values (cluster): cluster_typeName
Relative prevalences (r): r_timeName.typeName.sourceName
Lambda i (li): li_timeName_locationName_typeName
Lambda j (lj): lj_timeName_locationName_sourceName
where timeName, locationName and typeName are the values passed to the time, location and type arguments of saBayes prefixed with "time", "location", and "type" respectively. The sourceName values correspond to the source names passed to the formula argument of saBayes.

See Also

saBayes, subset_posterior, summary

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)
               
##########################################################################
#### Flatten #############################################################
##########################################################################

flat_res <- flatten(res)
names(flat_res)

Run the code above in your browser using DataLab