Skip to content

Commit cc1ddd2

Browse files
committed
Rel 0.0.1 Initial Julia v1 updates
1 parent 728600b commit cc1ddd2

10 files changed

Lines changed: 1189 additions & 285 deletions

File tree

Example/demo_wells.jl

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
1+
using StatisticalRethinking
12
using JSON
2-
using Colors
3-
using Gadfly
4-
using DataFrames
5-
6-
using Mamba
7-
using Stan
8-
3+
using StanSample
94
using PSIS
5+
using Statistics
106

11-
include("cvit.jl")
7+
ProjDir = @__DIR__
128

9+
include(joinpath(ProjDir, "cvit.jl"))
1310

1411
# Data
15-
data = JSON.parsefile("wells.data.json")
12+
data = JSON.parsefile(joinpath(ProjDir, "wells.data.json"))
1613
y = Float64.(data["switched"])
1714
x = Float64[data["arsenic"] data["dist"]]
1815
n, m = size(x)
1916

2017
# Model
21-
model_str = readstring(open("arsenic_logistic.stan"))
22-
stanmodel = Stanmodel(name="arsenic_logistic", adapt=500, update=500, model=model_str)
23-
24-
if isfile("sim.jls")
25-
sim = read("sim.jls", Chains)
26-
else
27-
standata = [Dict("p" => m, "N" => n, "y" => y, "x" => x)]
28-
# Fit the model in Stan
29-
sim = stan(stanmodel, standata, '.', CmdStanDir=CMDSTAN_HOME, summary=false)
30-
write("sim.jls", sim)
31-
end
18+
model_str = read(open(joinpath(ProjDir, "arsenic_logistic.stan")), String)
19+
tmpdir = joinpath(ProjDir, "tmp")
20+
sm = SampleModel("arsenic_logistic", model_str; tmpdir)
3221

33-
names_sim = filter(x->startswith(x,"log_lik"), sim.names)
22+
data = (p = m, N = n, y = Int.(y), x = x)
23+
# Fit the model in Stan
24+
rc = stan_sample(sm; data)
25+
nt = read_samples(sm)
3426

3527
# Compute LOO and standard error
36-
log_lik = sim[:, names_sim, :]
28+
log_lik = nt.log_lik'
3729
loo, loos, pk = psisloo(log_lik)
3830
elpd_loo = sum(loos)
3931
se_elpd_loo = std(loos) * sqrt(n)

0 commit comments

Comments
 (0)