plotOverlap: Calculate the Overlap between the Prior and the Posterior...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/plotOverlap.R

Description

The function overlapPriorPost implements the diagnostic of Garrett and Zeger (2000) to assess the overlap between the prior and the posterior.

The function plotOverlap displays the table summarizing the overlap between the prior and the posterior distributions of the parameters (result of the function overlapPriorPost.

Usage

1
2
3
overlapPriorPost(x, param, prior = "dnorm(z,0,sqrt(10))", from = -10, to = 10, n = 1000)

plotOverlap(x, df, cex = 1.5)

Arguments

x

An object of class mcmc.list.

param

A character string containing the name of a parameter in x

prior

a character string indicating the form of the prior for the parameter. Note that the parameter should be named z in this expression.

from,to,n

the values of param over which the prior and posterior should be compared (passed to the function density.

df

A data.frame (see details).

cex

the size of the text in the table

Details

For the function plotOverlap, tqhe object df must contain the following variables: (i) Parameter: the name of the parameter in the model i, (ii) tau: the value of the overlap parameter tau between the prior and the posterior,(iii) namo: a character string containing a plotmath expression to be used in the first column of the resulting table, (iv) prior: a character string indicating the form of the prior for the parameter; note that the parameter should be named z in this expression, (v) three columns named from,to,n passed to the function density, and used to calculate the values of the parameter over which the prior and posterior should be compared.

Value

The function overlapPriorPost returns a numeric value corresponding to the diagnostic.

Author(s)

Clement Calenge clement.calenge@ofb.gouv.fr

References

Calenge C., Menoni E., Milhau B., Foulche K, Chiffard J., Marchandeau S. (in prep.). The participatory monitoring of the capercaillie in the French Pyrenees.

Garrett, E. and Zeger, S. 2000. Latent class model diagnosis. Biometrics, 56, 1055-1067.

See Also

overlapPriorPost to calculate the coefficient tau.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## Not run: 
    
## Use the MCMC samples from the model coefModelCountDetectBinREY 
rs <- do.call(rbind, coefModelCountDetectBinREY)

## Detects the name of the parameters for which tau should be calculated
library(stringr)
nam <- c("interceptpd","pente1pd","mukappa","sigmaREY",
         "sigmaepsilon","sigmaeta","sigmakappa",
         "sigmanu")
nam <- unlist(lapply(nam, function(z) colnames(rs)[str_detect(colnames(rs),z)]))

## Remove the parameters not part of the model (only three regions
## for KILs, and only one region for ULs)
nam <- nam[!nam
            "mukappa[3,3]", "mukappa[4,3]","mukappa[5,3]")]

## For each parameter, calculates the value of tau:
lb <- sapply(nam, function(na) {
    if (str_detect(na, "mukappa")|na
        tau <- overlapPriorPost(coefModelCountDetectBinREY, na)
    if (str_detect(na, "sigma"))
        tau <- overlapPriorPost(coefModelCountDetectBinREY, na,
                                prior="dgamma(den$x[j],0.01, 0.01)", from=0, to=1000)
    return(tau)
})


## Builds the data.frame required by plotOverlap
df <- data.frame(Parameter=nam, tau=lb)
namo <- paste0("expression(", c("alpha[d]","beta[d]", gsub("kappa","",gsub(",", "", nam[3:11])),
                               "sigma[e]", "sigma[epsilon]",
                               "sigma[eta]^(1)", "sigma[eta]^(2)",
                               "sigma[eta]^(3)",
                               "sigma[kappa]","sigma[nu]"),")")
df$namo <- namo
df$prior <- "dgamma(z,0.01,0.01)"
df$prior[1:11] <- "dnorm(z,0,sqrt(10))"
df$from <- 0.01
df$to <- 20
df$to[12] <- 100
df$to[13] <- 600
df$to[17] <- 600
df$from[1:11] <- -4
df$to[1:11] <- 4


plotOverlap(coefModelCountDetectBinREY, df, cex=1)


## End(Not run)

ClementCalenge/caperpyogm documentation built on Sept. 14, 2021, 4:14 p.m.