Worked examples

Worked examples #

In all cases below we will work with the demo data included with models-for-missing-data, which has the following directory structure:

.
└── assets
    └── _config/
        └── M4MD/
            ├── ELDO/
            │   ├── _park-level-attributes.yml
            │   ├── counts.yml
            │   └── hits-vs-trials.yml
            └── _network-level-attributes.yml

A minimal example for count data #

The following example comes from “assets/_config/M4MD/ELDO/counts.yml”.

The analysis config file #

# ==== DATA ===================================================================

response info:
    file: assets/_data/count-data.csv
    state variable:
        response column:
            - y_sim
        description:
            - Simulated count data
    sampling method: plot
    sample id column(s):
        - plot

site location info:
    file: assets/_data/sample-locs.csv
    coordinate columns:
        - x_coord
        - y_coord

covariate info:
    file: assets/_data/sample-covariates.csv
    # event date info: # TODO: describe. Only use when covariates are time-varying!
    #     date-time column: event_year
    #     date-time format: Y!

# ==== MODEL ==================================================================

# Likelihood. For counts, one or both of: poisson, negative-binomial.
likelihood:
    - poisson
    - negative-binomial

# Deterministic model for the mean. For counts, one of: exponential, linear,
# or monomolecular.
deterministic model:
    # - linear
    - exponential
    # - monomolecular

# Group-level effects structure. One of: b0, b0-b1.
group-level effects:
    - b0
    # - b0-b1

# Variance structure (these *have* to be colnames, not descriptions).
variances:
    stratum-level fixed:
      level: stratum
      type: fixed
      response column(s):
          - y_sim
    # site-level hierarchical:
    #  level: site
    #  type: hier
    #  response column(s):
    #      - y_sim

# Covariates.
additional covariates:
    - w1

# Initial values (one of: 'auto', 'default', or 'inherited')
initial values: default

The model call #

You can run this model interactively from RStudio using “model-api/analysis-pipeline.R”, or at the command line with:

./model-api/analysis-pipeline.R \
    assets/_config/M4MD/ELDO/counts.yml \
    --n-adapt 5000 --n-update 10000 --n-iter 8000 \
    --n-cores 2 \
    --excl-null

Note that we exclude the “null” (time-only) model with the flag --excl-null.

Selected outputs #

Convergence diagnostics #

Potential scale reduction factors:

            Point est. Upper C.I.
B1[1]             1.00       1.01
B1[2]             1.00       1.00
Beta              1.00       1.01
deviance          1.00       1.00
mu.B0[1]          1.00       1.00
mu.B0[2]          1.00       1.00
p.mean            1.00       1.00
p.sd              1.00       1.00
sigma.B0[1]       1.00       1.01
sigma.B0[2]       1.01       1.01

#

Model checking and evaluation #

Posterior predictive checksObserved vs. predicted plots

Inference #

Intercept and time slope termsFixed effects

A minimal example for binomial data #

The following example comes from “assets/_config/M4MD/ELDO/hits-vs-trials.yml”.

The analysis config file #

# ==== DATA ===================================================================

response info:
    file: assets/_data/binomial-data.csv
    state variable:
        hits column:
            - y_sim
        description:
            - Simulated binomial data
        trials column:
            - trials
    sampling method: transect
    sample id column(s):
        - transect

site location info:
    file: assets/_data/sample-locs.csv
    coordinate columns:
        - x_coord
        - y_coord

covariate info:
    file: assets/_data/sample-covariates.csv
    # event date info: # TODO: describe. Only use when covariates are time-varying!
    #     date-time column: event_year
    #     date-time format: Y!

# ==== MODEL ==================================================================

# Likelihood. For counts, one or both of: poisson, negative-binomial.
likelihood:
    - binomial
    - beta-binomial
    # - zero-inflated-binomial
    # - zero-inflated-beta-binomial

# Deterministic model for the mean. For counts, one of: exponential, linear,
# or monomolecular.
deterministic model:
    - inverse-logit

# Group-level effects structure. One of: b0, b0-b1.
group-level effects:
    - b0
    # - b0-b1

# Variance structure (these *have* to be colnames, not descriptions).
variances:
    stratum-level fixed:
      level: stratum
      type: fixed
      response column(s):
          - y_sim
    # site-level hierarchical:
    #  level: site
    #  type: hier
    #  response column(s):
    #      - y_sim

# Covariates.
additional covariates:
    - w1

# Initial values (one of: 'auto', 'default', or 'inherited')
initial values: default