Skip to contents

From the output of the function fit_trend() (or read_bugs()), this function extracts estimated parameters into a data.frame.

The resulting data.frame has no particular use in popbayes but it can be useful for users.

Usage

bugs_to_df(data)

Arguments

data

a named list of BUGS outputs. The output of fit_trend() or read_bugs()

Value

A data.frame.

Examples

## Load Garamba raw dataset ----
file_path <- system.file("extdata", "garamba_survey.csv", 
                         package = "popbayes")
                         
garamba <- read.csv(file = file_path)

## Create temporary folder ----
temp_path <- tempdir()

## Format dataset ----
garamba_formatted <- popbayes::format_data(
  data              = garamba, 
  path              = temp_path,
  field_method      = "field_method",
  pref_field_method = "pref_field_method",
  conversion_A2G    = "conversion_A2G",
  rmax              = "rmax")
#>  Detecting 10 count series.
                                        
## Select one serie ----
a_buselaphus <- popbayes::filter_series(garamba_formatted, 
                                        location = "Garamba",
                                        species  = "Alcelaphus buselaphus")
#>  Found 1 series with "Alcelaphus buselaphus" and "Garamba".
# \donttest{
## Fit population trends (requires JAGS) ----
a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path)
#> module glm loaded
#> Compiling data graph
#>    Resolving undeclared variables
#>    Allocating nodes
#>    Initializing
#>    Reading data back into data table
#> Compiling model graph
#>    Resolving undeclared variables
#>    Allocating nodes
#> Graph information:
#>    Observed stochastic nodes: 15
#>    Unobserved stochastic nodes: 15
#>    Total graph size: 227
#> 
#> Initializing model
#> 

## Import BUGS outputs for one count series ----
bugs <- popbayes::read_bugs(series = "garamba__alcelaphus_buselaphus", 
                            path   = temp_path)

## Extract estimated parameters ----
popbayes::bugs_to_df(bugs)
#>                            series parameter          mean           sd
#> 1  garamba__alcelaphus_buselaphus      N[1]  1.772100e+04 1.729775e+03
#> 2  garamba__alcelaphus_buselaphus      N[2]  3.850141e+03 4.973625e+02
#> 3  garamba__alcelaphus_buselaphus      N[3]  3.309152e+03 3.905891e+02
#> 4  garamba__alcelaphus_buselaphus      N[4]  2.998527e+03 4.323555e+02
#> 5  garamba__alcelaphus_buselaphus      N[5]  2.678312e+03 3.307934e+02
#> 6  garamba__alcelaphus_buselaphus      N[6]  3.233291e+03 5.526038e+02
#> 7  garamba__alcelaphus_buselaphus      N[7]  3.765074e+03 6.764909e+02
#> 8  garamba__alcelaphus_buselaphus      N[8]  3.472602e+03 3.705043e+02
#> 9  garamba__alcelaphus_buselaphus      N[9]  2.888552e+03 2.072682e+02
#> 10 garamba__alcelaphus_buselaphus     N[10]  2.748165e+03 2.034497e+02
#> 11 garamba__alcelaphus_buselaphus     N[11]  2.752900e+03 2.580135e+02
#> 12 garamba__alcelaphus_buselaphus     N[12]  2.625408e+03 2.982512e+02
#> 13 garamba__alcelaphus_buselaphus     N[13]  1.311394e+03 7.328570e+01
#> 14 garamba__alcelaphus_buselaphus     N[14]  1.571261e+03 9.053393e+01
#> 15 garamba__alcelaphus_buselaphus     N[15]  2.394501e+03 1.539111e+02
#> 16 garamba__alcelaphus_buselaphus  deviance  2.362347e+02 5.165043e+00
#> 17 garamba__alcelaphus_buselaphus     meanr -4.875138e-02 2.885809e-03
#> 18 garamba__alcelaphus_buselaphus      r[1] -2.186147e-01 2.270729e-02
#> 19 garamba__alcelaphus_buselaphus      r[2] -1.500121e-01 6.877398e-02
#> 20 garamba__alcelaphus_buselaphus      r[3] -5.099129e-02 6.069916e-02
#> 21 garamba__alcelaphus_buselaphus      r[4] -2.204245e-02 3.392850e-02
#> 22 garamba__alcelaphus_buselaphus      r[5]  9.074184e-02 6.432717e-02
#> 23 garamba__alcelaphus_buselaphus      r[6]  7.540158e-02 5.851457e-02
#> 24 garamba__alcelaphus_buselaphus      r[7] -2.350364e-02 5.097567e-02
#> 25 garamba__alcelaphus_buselaphus      r[8] -9.050151e-02 5.096770e-02
#> 26 garamba__alcelaphus_buselaphus      r[9] -2.499481e-02 4.316500e-02
#> 27 garamba__alcelaphus_buselaphus     r[10]  5.962291e-05 6.665749e-02
#> 28 garamba__alcelaphus_buselaphus     r[11] -4.950209e-02 6.553757e-02
#> 29 garamba__alcelaphus_buselaphus     r[12] -8.615151e-02 1.541633e-02
#> 30 garamba__alcelaphus_buselaphus     r[13]  9.034500e-02 3.563934e-02
#> 31 garamba__alcelaphus_buselaphus     r[14]  1.402948e-01 2.779964e-02
#> 32 garamba__alcelaphus_buselaphus       sdr  1.122059e-01 9.657620e-03
#> 33 garamba__alcelaphus_buselaphus    vrrmax  4.621535e-01 3.977778e-02
#>             2.5%           25%           50%           75%         97.5%
#> 1   1.431631e+04  1.655658e+04  1.772194e+04  1.888266e+04  2.110299e+04
#> 2   2.888981e+03  3.509654e+03  3.847487e+03  4.180559e+03  4.834674e+03
#> 3   2.550177e+03  3.042992e+03  3.309741e+03  3.573129e+03  4.072483e+03
#> 4   2.195827e+03  2.698451e+03  2.982672e+03  3.280820e+03  3.887447e+03
#> 5   2.033679e+03  2.450529e+03  2.677881e+03  2.904399e+03  3.324855e+03
#> 6   2.234661e+03  2.841034e+03  3.203521e+03  3.583267e+03  4.414243e+03
#> 7   2.583617e+03  3.282852e+03  3.721283e+03  4.190219e+03  5.220882e+03
#> 8   2.774144e+03  3.215877e+03  3.464590e+03  3.721169e+03  4.215468e+03
#> 9   2.487402e+03  2.746939e+03  2.887398e+03  3.027517e+03  3.300742e+03
#> 10  2.354293e+03  2.609529e+03  2.746285e+03  2.885595e+03  3.145791e+03
#> 11  2.259670e+03  2.576350e+03  2.747009e+03  2.927198e+03  3.267404e+03
#> 12  2.058893e+03  2.419733e+03  2.619069e+03  2.822791e+03  3.229276e+03
#> 13  1.169513e+03  1.261833e+03  1.310949e+03  1.361339e+03  1.455309e+03
#> 14  1.395993e+03  1.510320e+03  1.570637e+03  1.631658e+03  1.752060e+03
#> 15  2.094380e+03  2.290871e+03  2.393927e+03  2.498309e+03  2.696495e+03
#> 16  2.273803e+02  2.326268e+02  2.357662e+02  2.393482e+02  2.476382e+02
#> 17 -5.417675e-02 -5.071391e-02 -4.881654e-02 -4.688358e-02 -4.284532e-02
#> 18 -2.643631e-01 -2.335204e-01 -2.181308e-01 -2.035562e-01 -1.739981e-01
#> 19 -2.840044e-01 -1.966724e-01 -1.502095e-01 -1.037954e-01 -1.386374e-02
#> 20 -1.686733e-01 -9.192219e-02 -5.164791e-02 -1.002543e-02  6.891448e-02
#> 21 -8.773795e-02 -4.476381e-02 -2.245801e-02  3.076995e-04  4.682962e-02
#> 22 -3.326142e-02  4.651487e-02  9.047525e-02  1.342468e-01  2.222861e-01
#> 23 -3.663444e-02  3.581146e-02  7.492059e-02  1.140134e-01  1.938999e-01
#> 24 -1.225695e-01 -5.760341e-02 -2.414298e-02  9.806327e-03  7.841485e-02
#> 25 -1.880805e-01 -1.252855e-01 -9.160568e-02 -5.617282e-02  1.119226e-02
#> 26 -1.097735e-01 -5.432977e-02 -2.501886e-02  4.182605e-03  6.042202e-02
#> 27 -1.309067e-01 -4.508699e-02  3.956121e-04  4.575904e-02  1.280129e-01
#> 28 -1.791352e-01 -9.338575e-02 -4.914100e-02 -5.119069e-03  7.850645e-02
#> 29 -1.155664e-01 -9.653620e-02 -8.644329e-02 -7.610274e-02 -5.473144e-02
#> 30  2.001179e-02  6.653616e-02  9.037790e-02  1.141177e-01  1.597086e-01
#> 31  8.434997e-02  1.217361e-01  1.405392e-01  1.589559e-01  1.941114e-01
#> 32  9.409520e-02  1.056223e-01  1.117709e-01  1.185014e-01  1.322428e-01
#> 33  3.875591e-01  4.350368e-01  4.603616e-01  4.880831e-01  5.446815e-01
#>        Rhat n.eff
#> 1  1.001631  2200
#> 2  1.001109 10000
#> 3  1.001016 27000
#> 4  1.000970 27000
#> 5  1.000962 27000
#> 6  1.001053 16000
#> 7  1.002393  1000
#> 8  1.000988 27000
#> 9  1.001137  8500
#> 10 1.001087 12000
#> 11 1.001677  2100
#> 12 1.002717   860
#> 13 1.000967 27000
#> 14 1.001001 27000
#> 15 1.001032 21000
#> 16 1.002141  1300
#> 17 1.001651  2200
#> 18 1.001647  2200
#> 19 1.001066 14000
#> 20 1.000975 27000
#> 21 1.000972 27000
#> 22 1.001151  7900
#> 23 1.002909   770
#> 24 1.003283   650
#> 25 1.000976 27000
#> 26 1.001392  3500
#> 27 1.001601  2300
#> 28 1.002164  1200
#> 29 1.002384  1100
#> 30 1.001011 27000
#> 31 1.001065 14000
#> 32 1.000967 27000
#> 33 1.000967 27000
# }