plot.PMCMC: Plots 'PMCMC' objects

Description Usage Arguments Value See Also Examples

View source: R/plotPMCMC.R

Description

Plot method for PMCMC objects.

Usage

1
2
3
4
5
6
7
8
9
## S3 method for class 'PMCMC'
plot(
  x,
  type = c("post", "trace"),
  joint = FALSE,
  transfunc = NA,
  ask = TRUE,
  ...
)

Arguments

x

A PMCMC object.

type

Takes the value "post" if you want to plot posterior distributions. Takes the value "trace" if you want to plot the trace plots.

joint

A logical describing whether joint or marginal distributions are wanted.

transfunc

Is a function object where the arguments to the function must match all or a subset of the parameters in the model. This function needs to return a data.frame object with columns containing the transformed parameters.

ask

Should the user ask before moving onto next trace plot.

...

Not used here.

Value

A plot of the (approximate) posterior distributions obtained from fitting a particle Markov chain Monte Carlo algorithm, or provides corresponding trace plots.

See Also

PMCMC, print.PMCMC, predict.PMCMC, summary.PMCMC window.PMCMC

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## set up data to pass to PMCMC
flu_dat <- data.frame(
    t = 1:14,
    Robs = c(3, 8, 26, 76, 225, 298, 258, 233, 189, 128, 68, 29, 14, 4)
)

## set up observation process
obs <- data.frame(
    dataNames = "Robs",
    dist = "pois",
    p1 = "R + 1e-5",
    p2 = NA,
    stringsAsFactors = FALSE
)

## set up model (no need to specify tspan
## argument as it is set in PMCMC())
transitions <- c(
    "S -> beta * S * I / (S + I + R + R1) -> I", 
    "I -> gamma * I -> R",
    "R -> gamma1 * R -> R1"
)
compartments <- c("S", "I", "R", "R1")
pars <- c("beta", "gamma", "gamma1")
model <- mparseRcpp(
    transitions = transitions, 
    compartments = compartments,
    pars = pars,
    obsProcess = obs
)

## set priors
priors <- data.frame(
    parnames = c("beta", "gamma", "gamma1"), 
    dist = rep("unif", 3), 
    stringsAsFactors = FALSE)
priors$p1 <- c(0, 0, 0)
priors$p2 <- c(5, 5, 5)

## define initial states
iniStates <- c(S = 762, I = 1, R = 0, R1 = 0)

set.seed(50)

## run PMCMC algorithm
post <- PMCMC(
    x = flu_dat, 
    priors = priors,
    func = model, 
    u = iniStates,
    npart = 25,
    niter = 5000, 
    nprintsum = 1000
)

## plot MCMC traces
plot(post, "trace")

## continue for some more iterations
post <- PMCMC(post, niter = 5000, nprintsum = 1000)

## plot traces and posteriors
plot(post, "trace")
plot(post)

## remove burn-in
post <- window(post, start = 5000)

## summarise posteriors
summary(post)

SimBIID documentation built on Feb. 4, 2021, 9:07 a.m.