-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
218 lines (218 loc) · 8.11 KB
/
.Rhistory
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
library(usethis)
use_blank_slate(scope = "project")
library(usethis)
use_github()
use_tidy_github()
create_tidy_package(name = "standist")
create_tidy_package(path = "", name = "standist")
?create_tidy_package
create_tidy_package(path = "standist", name = "Jeffrey M. Girard")
library(usethis)
use_gpl3_license()
use_gpl3_license("Jeffrey M. Girard")
use_roxygen_md()
use_readme_rmd()
use_news_md()
use_tidy_github()
use_package("assertthat")
use_r()
use_package("ggplot2", type = "Imports")
?visualize
??visualize
?viz
?vis
d_rayleigh <- function(x, sigma) {
assert_that(is.numeric(x))
assert_that(is.number(sigma))
assert_that(sigma > 0)
y <- (x / sigma^2) *
base::exp(-(x^2) / (2 * sigma^2))
y[x < 0] <- 0
y
}
# Visualize one or more specified distributions
visualize <- function(..., xlim = c(-10, 10)) {
# Check the xlim argument
assert_that(is.numeric(xlim),
msg = "'xlim' must be numeric")
assert_that(length(xlim) == 2,
msg = "'xlim' must contain two numbers: a minimum and a maximum")
assert_that(xlim[[2]] > xlim[[1]],
msg = "The second number in 'xlim' must be larger than the first")
# Initialize ggplot object
p <- ggplot2::ggplot(data.frame(x = xlim), ggplot2::aes(x)) +
ggplot2::labs(color = "Distribution") +
ggplot2::theme(legend.position = "top")
# Capture all priors in a list
priors <- list(...)
# Loop through each prior in the list
for (i in seq_along(priors)) {
# Get current prior
prior_i <- priors[[i]]
# Check that current prior is a nonempty string
assert_that(is.string(prior_i),
msg = "Priors must be strings")
assert_that(nzchar(prior_i),
msg = "Priors cannot be empty strings")
# Convert current prior string into its function and argument components
str_i <- str_remove_all(prior_i, "[\\s\\)]")
str_i <- str_split(str_i, "[\\(\\,]", simplify = TRUE)
fun_i_raw <- str_i[[1]]
fun_i_str <- paste0("d_", fun_i_raw)
args_i <- as.list(as.double(str_i[-1]))
# Check that a function exists for the current prior
assert_that(exists(fun_i_str, mode = "function") == TRUE,
msg = "Could not find function for specified prior")
# Convert the current prior from a string into a function
fun_i <- base::eval(base::parse(text = fun_i_str))
# Check that the number of arguments in current prior matches the number
# of formals for its function
formals_i <- base::formals(fun_i)
assert_that(length(args_i) == length(formals_i) - 1,
msg = "The prior had too many or too few parameters")
# Add a plot of the function to the ggplot object
p <- p + stat_function(
aes(color = !!{{prior_i}}),
size = 1.5,
fun = fun_i,
args = args_i
)
}
# Return the complete ggplot object
p
}
visualize("rayleigh(1)", "rayleigh(2)")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
devtools::load_all(".")
pkgbuild::compile_dll()
devtools::document()
devtools::load_all(".")
source('D:/GitHub/standist/R/standist.R')
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
use_package("stringr")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
devtools::load_all(".")
visualize("rayleigh(1)", "rayleigh(2)")
visualize("rayleigh(1)", "rayleigh(2)", "rayleigh(10)")
visualize("rayleigh(1)", "rayleigh(2)", "rayleigh(10)", xlim = c(0, 20))
visualize("rayleigh(1)", "rayleigh(2)", "rayleigh(5)", xlim = c(0, 20))
visualize("rayleigh(1)", "rayleigh(2)", "rayleigh(4)", xlim = c(0, 20))
devtools::load_all(".")
d_normal(1:10, 0, 1)
devtools::load_all(".")
?d_normal
devtools::load_all(".")
?d_normal
devtools::load_all(".")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,2)")
devtools::load_all(".")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,2)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,2)", "exp_mod_normal(0, 1, 10)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,20)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,200)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,50)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,25)")
visualize("exp_mod_normal(0, 1, 1)", "exp_mod_normal(0,1,30)")
VGAM::erfc
VGAM::erf()
VGAM::erf
?VGAM::erf
VGAM::erf(1:10)
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
visualize("skew_normal(0,1,0)")
visualize("skew_normal(0,1,0)", "skew_normal(1,1,0)")
visualize("skew_normal(0,1,0)", "skew_normal(-1,1,0)")
visualize("skew_normal(0,1,0)", "skew_normal(0,2,0)")
visualize("skew_normal(0,1,0)", "skew_normal(0,1,1)")
visualize("skew_normal(0,1,0)", "skew_normal(0,1,-1)")
visualize("skew_normal(0,1,0)", "skew_normal(0,1,-10)")
visualize("skew_normal(0,1,0)", "skew_normal(0,1,10)")
visualize("skew_normal(0,1,0)", "skew_normal(0,2,10)")
visualize("skew_normal(0,1,0)", "skew_normal(0,2,100)")
devtools::load_all(".")
visualize("student_t(1,0,1)", "student_t(2,0,1)")
visualize("student_t(1,0,1)", "student_t(10,0,1)")
visualize("student_t(1,0,1)", "student_t(30,0,1)")
devtools::load_all(".")
visualize("gumbel(0, 1)", "gumbel(1,1)")
devtools::load_all(".")
visualize("gumbel(0, 1)", "gumbel(1,1)")
visualize("gumbel(0, 1)", "gumbel(0,2)")
devtools::load_all(".")
visualize("lognormal(0, 1)", "lognormal(0,2)")
visualize("chi_square(1)", "chi_square(2)")
visualize("chi_square(1)", "chi_square(3)")
devtools::load_all(".")
visualize("chi_square(1)", "inv_chi_square(1)")
visualize("chi_square(3)", "inv_chi_square(3)")
visualize("chi_square(3)", "inv_chi_square(30)")
visualize("chi_square(3)", "inv_chi_square(20)")
visualize("chi_square(3)", "inv_chi_square(10)")
visualize("chi_square(3)", "inv_chi_square(5)")
visualize("chi_square(3)", "inv_chi_square(10)")
visualize("inv_chi_square(2)", "scaled_inv_chi_square(2, 1)")
visualize("inv_chi_square(2)", "scaled_inv_chi_square(2, 2)")
visualize("inv_chi_square(2)", "scaled_inv_chi_square(1, 2)")
visualize("inv_chi_square(2)", "scaled_inv_chi_square(1, 3)")
visualize("exponential(1)", "exponential(2)")
visualize("exponential(1)", "exponential(3)")
visualize("exponential(1)", "exponential(10)")
visualize("gamma(1, 1)", "gamma(2, 1)")
visualize("gamma(1, 1)", "gamma(3, 1)")
visualize("gamma(1, 1)", "gamma(1, 2)")
visualize("gamma(1, 1)", "gamma(1, 3)")
visualize("gamma(1, 1)", "gamma(1, 4)")
devtools::load_all(".")
visualize("weibull(1, 1)", "weibull(2, 1)")
visualize("weibull(1, 1)", "weibull(3, 1)")
visualize("weibull(1, 1)", "weibull(4, 1)")
visualize("weibull(1, 1)", "weibull(5, 1)")
visualize("weibull(1, 1)", "weibull(1, 2)")
visualize("weibull(1, 1)", "weibull(1, 3)")
visualize("weibull(1, 1)", "weibull(3, 3)")
devtools::load_all(".")
visualize("pareto(2, 1)", "pareto(3, 1)")
visualize("pareto(2, 1)", "pareto(2, 2)")
visualize("pareto(2, 1)", "pareto(2, 3)")
visualize("pareto(2, 1)", "pareto(2, 4)")
visualize("pareto_type_2(0, 1, 1)", "pareto(1, 1, 1)")
visualize("pareto_type_2(0, 1, 1)", "pareto_type_2(1, 1, 1)")
visualize("pareto_type_2(0, 1, 1)", "pareto_type_2(1, 2, 1)")
visualize("pareto_type_2(1, 1, 1)", "pareto_type_2(1, 2, 1)")
visualize("pareto_type_2(1, 1, 1)", "pareto_type_2(1, 1, 2)")
visualize("pareto_type_2(0, 2, 3)", xlim = c(0, 4))
devtools::load_all(".")
visualize("beta(1, 1)", "beta(2,1)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(3,1)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(4,1)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(5,1)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(1,2)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(1,3)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(3,3)", xlim = c(-1, 2))
visualize("beta(1, 1)", "beta(0.5,0.5)", xlim = c(-1, 2))
visualize("beta_proportion(0.5, 1)", "beta_proportion(0.1,1)", xlim = c(-1, 2))
visualize("beta_proportion(0.5, 1)", "beta_proportion(0.5,2)", xlim = c(-1, 2))
visualize("beta_proportion(0.5, 1)", "beta_proportion(0.5,2)", xlim = c(-1, 3))
visualize("beta_proportion(0.5, 1)", "beta_proportion(0.5,3)", xlim = c(-1, 2))
devtools::load_all(".")
devtools::load_all(".")
visualize("bernoulli(0.4)", xlim = c(0, 1))
devtools::load_all(".")
visualize("bernoulli(0.4)", xlim = c(0, 1))
visualize("bernoulli(0.4)", xlim = c(-1, 2))
d_bernoulli(-10:10, 0.3)
plot(d_bernoulli(-10:10, 0.3))
plot(-10:10, d_bernoulli(-10:10, 0.3))