Learn R Programming

rethinking (version 1.59)

resample: Resample map2stan fit

Description

Sample from a new chain or chains, using a previous map2stan fit object.

Usage

resample( object , iter=1e4 , warmup=1000 , chains=1 , cores=1 , 
    DIC=TRUE , WAIC=TRUE , rng_seed , data , ... )

Arguments

object

Object of class map2stan

iter

Number of sampling iterations, including warmup

warmup

Number of adaptation steps

chains

Number of independent chains

cores

Number of cores to distribute chains across

DIC

If TRUE, computes DIC after sampling

WAIC

If TRUE, computes WAIC after sampling

rng_seed

Optional seed to use for all chains. When missing, a random seed is chosen and used for all chains.

...

Other parameters to pass to stan

Value

An object of class map2stan, holding the new samples, as well as all of the original formulas and data for the model.

Details

This function is a convenience for drawing more samples from an initial map2stan fit.

When cores is set greater than 1, either mclapply (on a unix system) or parLapply (on a Windows system) is used to run the chains, distributing them across processor cores. The results are automatically recombined with sflist2stanfit.

See Also

map2stan, mclapply, sflist2stanfit

Examples

Run this code
# NOT RUN {
data(Trolley)
d <- Trolley
d2 <- list(
    y=d$response,
    xA=d$action,
    xI=d$intention,
    xC=d$contact,
    id=as.integer(d$id)
)
Nid <- length(unique(d2$id))

# ordered logit regression with varying intercepts
m.init <- map2stan(
    alist(
        y ~ dordlogit( phi , cutpoints ),
        phi <- aj + bA*xA + bI*xI + bC*xC,
        c(bA,bI,bC) ~ dnorm(0,1),
        aj[id] ~ dnorm(0,sigma_id),
        sigma_id ~ dcauchy(0,2.5),
        cutpoints ~ dcauchy(0,2.5)
    ),
    data=d2 ,
    start=list(
        bA=0,bI=0,bC=0,
        cutpoints=c(-2,-1.7,-1,-0.2,0.5,1.3),
        aj=rep(0,Nid),sigma_id=1
    ),
    types=list(cutpoints="ordered") , 
    iter=2
)

# Note: parallel chains won't work on Windows
m <- resample( m.init , chains=3 , cores=3 , warmup=1000 , iter=3000 )
# }

Run the code above in your browser using DataLab