Skip to content

Instantly share code, notes, and snippets.

@bakfoo
Last active November 11, 2020 22:28
Show Gist options
  • Save bakfoo/2447eb7d551ff256706a to your computer and use it in GitHub Desktop.
Save bakfoo/2447eb7d551ff256706a to your computer and use it in GitHub Desktop.
Rstan ADVI Test using rats examples.
y <- read.table('https://raw.github.com/wiki/stan-dev/rstan/rats.txt', header = TRUE)
x <- c(8, 15, 22, 29, 36)
xbar <- mean(x)
N <- nrow(y)
T <- ncol(y)
data <- list(y=y, x=x, xbar=xbar, N=N, T=T)
rats_model <- stan_model(file = "https://raw.githubusercontent.com/stan-dev/example-models/master/bugs_examples/vol1/rats/rats.stan")
#NUTS
rats_fit <- sampling(rats_model, data=data, iter=1000, warmup=500, chains=4, seed=123)
# ADVI
rats_fit_vb <- vb(rats_model, data=data, output_samples=2000, seed=123)
# ADVI+fullrank
racets_fit_vbfr <- vb(rats_model, data=data, output_samples=2000, seed=123, algorithm = "fullrank")
# by Julian King (https://groups.google.com/d/msg/stan-users/FaBvi8w7pc4/pogd3zmVAQAJ)
rats_0 <- vb(rats_model, data = data, eta=5, adapt_engaged=FALSE, iter = 1000000, tol_rel_obj=0.00001)
print(rats_fit)
print(rats_fit_vb)
print(rats_fit_vbfr)
print(rats_0)
@bfeif
Copy link

bfeif commented Jan 12, 2017

thanks!

@rudeboybert
Copy link

thanks from me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment