This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
/
stan_summary.jl
97 lines (86 loc) · 2.19 KB
/
stan_summary.jl
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
# Method stan_summary
Display cmdstan summary
### Method
```julia
stan_summary(
model::StanModel,
file::String;
CmdStanDir=CMDSTAN_HOME
)
```
### Required arguments
```julia
* `model::Stanmodel : Stanmodel
* `file::String` : Name of file with samples
```
### Optional arguments
```julia
* CmdStanDir=CMDSTAN_HOME : cmdstan directory for stansummary program
```
### Related help
```julia
?Stan.stan : Execute a StanModel
```
"""
function stan_summary(model::Stanmodel, file::String;
CmdStanDir=CMDSTAN_HOME)
try
pstring = joinpath("$(CmdStanDir)", "bin", "stansummary")
csvfile = "$(model.name)_summary.csv"
isfile(csvfile) && rm(csvfile)
cmd = setenv(`$(pstring) -c $(csvfile) $(file)`, ENV; dir=model.tmpdir)
resfile = open(cmd; read=true)
println("Setting $(model.printsummary)")
model.printsummary && print(read(resfile, String))
catch e
println(e)
end
end
"""
# Method stan_summary
Display cmdstan summary
### Method
```julia
stan_summary(
model::Stanmodel
filecmd::Cmd;
CmdStanDir=CMDSTAN_HOME
)
```
### Required arguments
```julia
* `model::Stanmodel` : Stanmodel
* `filecmd::Cmd` : Run command containing names of sample files
```
### Optional arguments
```julia
* CmdStanDir=CMDSTAN_HOME : cmdstan directory for stansummary program
```
### Related help
```julia
?Stan.stan : Create a StanModel
```
"""
function stan_summary(model::Stanmodel, filecmd::Cmd;
CmdStanDir=CMDSTAN_HOME)
try
pstring = joinpath("$(CmdStanDir)", "bin", "stansummary")
csvfile = "$(model.name)_summary.csv"
isfile(csvfile) && rm(csvfile)
cmd = setenv(`$(pstring) -c $(csvfile) $(filecmd)`, ENV; dir=model.tmpdir)
if model.printsummary
resfile = open(cmd; read=true)
print(read(resfile, String))
else
run(pipeline(cmd, stdout="out.txt"))
end
catch e
println(e)
println("Stan.jl caught above exception in Stan's 'stansummary' program.")
println("This is a usually caused by the setting:")
println(" Sample(save_warmup=true, thin=n)")
println("in the call to stanmodel() with n > 1.")
println()
end
end