# Calculate plugin pD from a JAGS model with univariate likelihood for studies with repeated measurements

`pDcalc.Rd`

Uses results from MBNMA JAGS models to calculate pD via the plugin method (Spiegelhalter et al. 2002) . Can only be used for models with known standard errors or covariance matrices (typically univariate).

## Usage

```
pDcalc(
obs1,
obs2,
fups = NULL,
narm,
NS,
theta.result,
resdev.result,
likelihood = "normal",
type = "time"
)
```

## Arguments

- obs1
A matrix (study x arm) or array (study x arm x time point) containing observed data for

`y`

(normal likelihood) or`r`

(binomial or Poisson likelihood) in each arm of each study. This will be the same array used as data for the JAGS model.- obs2
A matrix (study x arm) or array (study x arm x time point) containing observed data for

`se`

(normal likelihood),`N`

(binomial likelihood) or`E`

(Poisson likelihood) in each arm of each study. This will be the same array used as data for the JAGS model.- fups
A numeric vector of length equal to the number of studies, containing the number of follow-up mean responses reported in each study. Required for time-course MBNMA models (if

`type="time"`

)- narm
A numeric vector of length equal to the number of studies, containing the number of arms in each study.

- NS
A single number equal to the number of studies in the dataset.

- theta.result
A matrix (study x arm) or array (study x arm x time point) containing the posterior mean predicted means/probabilities/rate in each arm of each study. This will be estimated by the JAGS model.

- resdev.result
A matrix (study x arm) or array (study x arm x time point) containing the posterior mean residual deviance contributions in each arm of each study. This will be estimated by the JAGS model.

- likelihood
A character object of any of the following likelihoods:

`univariate`

`binomial`

(does not work with time-course MBNMA models)`multivar.normal`

(does not work with time-course MBNMA models)

- type
The type of MBNMA model fitted. Can be either

`"time"`

or`"dose"`

## Details

Method for calculating pD via the plugin method proposed by (Spiegelhalter et al. 2002) . Standard errors / covariance matrices must be assumed to be known. To obtain values for theta.result and resdev.result these parameters must be monitored when running the JAGS model.

For non-linear time-course MBNMA models residual deviance contributions may be skewed, which
can lead to non-sensical results when calculating pD via the plugin method.
Alternative approaches are to use pV (`pv`

) as an approximation (Plummer 2008)
or
pD calculated by Kullback–Leibler divergence (`pd.kl`

) or using an optimism adjustment (`popt`

) (Plummer 2008)
.

## Examples

```
# \donttest{
# Using the alogliptin dataset
network <- mb.network(alog_pcfb)
#> Reference treatment is `placebo`
#> Studies reporting change from baseline automatically identified from the data
# Run Emax model saving predicted means and residual deviance contributions
emax <- mb.run(network, fun=temax(),
parameters.to.save=c("theta", "resdev"), intercept=FALSE)
#> 'et50' parameters must take positive values.
#> Default half-normal prior restricts posterior to positive values.
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 233
#> Unobserved stochastic nodes: 38
#> Total graph size: 4166
#>
#> Initializing model
#>
# Get matrices of observed data
jagsdat <- getjagsdata(network$data.ab)
# Plugin estimation of pD is problematic with non-linear models as it often leads to
#negative values, hence use of pV, pd.kl and popt as other measures for the effective
#number of parameters
pDcalc(obs1=jagsdat$y, obs2=jagsdat$se,
fups=jagsdat$fups, narm=jagsdat$narm, NS=jagsdat$NS,
theta.result = emax$BUGSoutput$mean$theta,
resdev.result = emax$BUGSoutput$mean$resdev
)
#> [1] -9738.838
# }
```