Description Usage Arguments Details Value Author(s) See Also Examples
Combine Several Single Metropolis Objects Into One CMM objects
1 2 |
... |
a list of objects of class |
c.GSMetrop
transforms several objects of class
GSMetrop
into an object of class CMM
(combined
multiple Metropolis).
an object of class "CMM". If only one object is passed, the function returns the input object without transformation.
Clement Calenge, clement.calenge@oncfs.gouv.fr
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.