c.GSMetrop: Combine Several Single Metropolis Objects Into One CMM...

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

Description

Combine Several Single Metropolis Objects Into One CMM objects

Usage

1
2
## S3 method for class 'GSMetrop'
c(...)

Arguments

...

a list of objects of class GSMetrop

Details

c.GSMetrop transforms several objects of class GSMetrop into an object of class CMM (combined multiple Metropolis).

Value

an object of class "CMM". If only one object is passed, the function returns the input object without transformation.

Author(s)

Clement Calenge, clement.calenge@oncfs.gouv.fr

See Also

GeneralSingleMetropolis

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
71
#############################################
##
## First start with the same examples as in
## the help page of GeneralSingleMetropolis
##
## Generates a dataset:
x <- rnorm(100)
y <- 1+ 2*x + rnorm(100, sd = 0.1)

## Linear regression: estimate a, b, sigma in
## y = a + b*x + epsilon
## epsilon ~ dnorm(0, sigma)

## Log-posterior
logp <- function(par, lidat, ctrl)
{
   ## Current values of the parameters
   a <- par$a
   b <- par$b
   sigma <- exp(par$lsigma)

   ## log-Prior:
   lprior <- dnorm(a, mean=0, sd=100, log=TRUE)
   lprior <- lprior + dnorm(b, mean=0, sd=100, log=TRUE)
   ## uniform prior on sigma

   ## log-likelihood
   llike <- sum(dnorm(lidat$y, mean=lidat$x*b+a, sd=sigma, log=TRUE))

   ## log-posterior
   return(llike+lprior)
}

## Elements required for the fit
parinit <- list(a=0, b=1, lsigma=1) ## initial values
listUpdating <- list(a="sis", b="sis", lsigma="sis") ## all elements are updated with sis
lidat <- list(x=x, y=y)
lipum <- list(a=0.1, b=0.1, lsigma=1) ## test standard deviation of the proposals

## Not run: 
#############################################
##
## Then demonstrate the class CMM
##
## Three runs
gsm1 <- GeneralSingleMetropolis(parinit, lidat, logp, lipum,
                                nrepet=5000, saveResults=FALSE, nburnin=500)
gsm2 <- GeneralSingleMetropolis(parinit, lidat, logp, lipum,
                                nrepet=5000, saveResults=FALSE, nburnin=500)
gsm3 <- GeneralSingleMetropolis(parinit, lidat, logp, lipum,
                                nrepet=5000, saveResults=FALSE, nburnin=500)

## Combine these three runs
ae <- c(gsm1, gsm2, gsm3)

## Show various information about these models
ae
summary(ae)
plot(ae)

## Extraction features:
ae[1:2]
ae[2]

## work with the package coda:
library(coda)
raftery.diag(tocoda(gsm1))

gelman.diag(tocoda(ae))

## End(Not run)

ClementCalenge/metroponcfs documentation built on May 6, 2019, 12:05 p.m.