-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples.R
94 lines (76 loc) · 2.88 KB
/
examples.R
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
# ----------------------------------------------------------------------------
# Initial setup
# Load libraries
library(shiny)
library(rstan)
# Stan settings
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# Load the functions
funcs <- new.env()
source('functions.R', local=funcs)
# ----------------------------------------------------------------------------
# Find normal distribution parameters with targets:
# P[x < -2.0] ~ 0.01
# P[x > 2.0] ~ 0.01
targets = list(
bound_L = -2, # LOWER quantile boundary
bound_U = 2, # UPPER quantile boundary
dens_L = 0.01, # Target density below LOWER quantile boundary
dens_U = 0.01) # Target density above UPPER quantile boundary
results = funcs$tuneParams(distribution='normal', targets)
results$params
results$quantiles
results$histogram
# ----------------------------------------------------------------------------
# Find lognormal distribution parameters with targets:
# P[x < 0.1] ~ 0.01
# P[x > 4.0] ~ 0.01
targets = list(
bound_L = 0.1, # LOWER quantile boundary
bound_U = 4, # UPPER quantile boundary
dens_L = 0.01, # Target density below LOWER quantile boundary
dens_U = 0.01) # Target density above UPPER quantile boundary
results = funcs$tuneParams(distribution='lognormal', targets)
results$params
results$quantiles
results$histogram
# ----------------------------------------------------------------------------
# Find beta distribution parameters with targets:
# P[x < 0.5] ~ 0.01
# P[x > 0.99] ~ 0.01
targets = list(
bound_L = 0.5, # LOWER quantile boundary
bound_U = 0.99, # UPPER quantile boundary
dens_L = 0.01, # Target density below LOWER quantile boundary
dens_U = 0.01) # Target density above UPPER quantile boundary
results = funcs$tuneParams(distribution='beta', targets)
results$params
results$quantiles
results$histogram
# ----------------------------------------------------------------------------
# Find gamma distribution parameters with targets:
# P[x < 1.0] ~ 0.01
# P[x > 10] ~ 0.01
targets = list(
bound_L = 1, # LOWER quantile boundary
bound_U = 10, # UPPER quantile boundary
dens_L = 0.01, # Target density below LOWER quantile boundary
dens_U = 0.01) # Target density above UPPER quantile boundary
results = funcs$tuneParams(distribution='gamma', targets)
results$params
results$quantiles
results$histogram
# ----------------------------------------------------------------------------
# Find inv_gamma distribution parameters with targets:
# P[x < 1.0] ~ 0.01
# P[x > 10] ~ 0.01
targets = list(
bound_L = 1, # LOWER quantile boundary
bound_U = 10, # UPPER quantile boundary
dens_L = 0.01, # Target density below LOWER quantile boundary
dens_U = 0.01) # Target density above UPPER quantile boundary
results = funcs$tuneParams(distribution='inv_gamma', targets)
results$params
results$quantiles
results$histogram