-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.R
More file actions
51 lines (44 loc) · 1.21 KB
/
utils.R
File metadata and controls
51 lines (44 loc) · 1.21 KB
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
library(rwebppl)
library(tidyverse)
library(jsonlite)
library(ggthemes)
library(pander)
project_dir = "../"
data_dir = function(path) {
return(paste(project_dir, "data/", path, sep = ""))
}
cache_dir = function(path) {
return(paste(project_dir, "analysis/.cache/", path, sep = ""))
}
model_dir = function(path) {
return(paste(project_dir, "models/", path, sep = ""))
}
char = as.character
num = function(v) {
v = ifelse(is.na(v), NA, char(v))
v = ifelse(v=="infty", "Inf", v)
v = as.numeric(v)
return(v)
}
theme.new = theme_set(theme_few(12))
# for bootstrapping 95% confidence intervals
theta <- function(x,xdata) {mean(xdata[x])}
ci.low <- function(x) {
quantile(bootstrap::bootstrap(1:length(x),1000,theta,x)$thetastar,.025)}
ci.high <- function(x) {
quantile(bootstrap::bootstrap(1:length(x),1000,theta,x)$thetastar,.975)}
named_vec = function(df, label_vec, value_vec) {
if (!is.null(df)) {
label_vec <- df[[deparse(substitute(label_vec))]]
value_vec <- df[[deparse(substitute(value_vec))]]
}
names(value_vec) = label_vec
return(value_vec)
}
change_names = function(df, new_names) {
names(df) = new_names
return(df)
}
approx_eq = function(a, b, eps=0.0000001) {
return(abs(a-b) < eps)
}