This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove any old tmp files | |
old_tmp_files <- list.files(pattern = '^tmp', include.dirs = TRUE, full.names = TRUE) | |
invisible(unlink(old_tmp_files, recursive = TRUE)) | |
# create a dark widget frame via work around | |
dark_widgetframe <- | |
function(widget, background = '#666666FF', width = '100%', height = 420) { | |
file = tempfile(pattern = "tmp", tmpdir = '.', fileext = ".html") | |
selfcontained = FALSE | |
libdir = NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recreate the code from https://arxiv.org/pdf/1808.06399.pdf using greta (https://greta-dev.github.io/greta/) | |
library("DirichletReg") | |
Bld <- BloodSamples | |
Bld <- na.omit(Bld) | |
Bld$Smp <- DR_data(Bld[, 1:4]) | |
# using greta | |
# !! requires the development version to run! | |
# devtools::install_github("greta-dev/greta@dev") | |
# convert data to matrix then greta data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set up --------------------------- | |
library(furrr) | |
# use multiple clusters | |
ssh_username <- 'drn' | |
remote_ssh_configs <- c('a', 'b', 'e') # names for remote server (found in ~/.ssh/config e.g. Host a) | |
local_comp <- Sys.info()[["nodename"]] # get local computer name | |
# build cluster ---------------------------------------------------------------- | |
system(command = "ps -axc | grep ssh | awk '{print $1}' | sort -u | xargs kill") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recreate the code from https://arxiv.org/pdf/1808.06399.pdf using greta (https://greta-dev.github.io/greta/) | |
library("DirichletReg") | |
Bld <- BloodSamples | |
Bld <- na.omit(Bld) | |
Bld$Smp <- DR_data(Bld[, 1:4]) | |
# simplex function. applies simplex to each row of a matrix. | |
# HUGE speed gains using matrix mat vs for loop! | |
simplex_mat <- function(x){ | |
exp_x <- exp(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stan code from https://arxiv.org/pdf/1808.06399.pdf | |
library("DirichletReg") | |
Bld <- BloodSamples | |
Bld <- na.omit(Bld) | |
Bld$Smp <- DR_data(Bld[, 1:4]) | |
stan_code <- ' | |
data { | |
int<lower=1> N; // total number of observations | |
int<lower=2> ncolY; // number of categories |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rstan) | |
## HOW THE SIMULATION LOOP BELOW WORKS -- ignore the shocks for now -------------- | |
# quick example | |
I = 3 # individuals | |
M = 5 # "months" | |
S = 7 # sims | |
mat <- matrix(NA, I*M, S) # M rows (months) will be filled in at a time for each individual i across all S columns (simulations); records for individual i will populate rows ((i - 1)*M + 1):(i*M) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspired by https://stats.stackexchange.com/questions/174121/can-a-model-for-non-negative-data-with-clumping-at-zeros-tweedie-glm-zero-infl | |
# additions by Danton Noriega | |
library(statmod) | |
library(tweedie) | |
library(mgcv) | |
# generate fake mu (poisson count rates) | |
set.seed(1789) | |
x <- seq(1,100, by = .1) | |
mutrue <- exp(-1+x/25) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a running list of really useful data.table tricks | |
# TOP 1,2 ... last row by some group id | |
## source: https://stackoverflow.com/questions/16325641/is-it-possible-to-extract-the-first-2-rows-for-each-date#comment23381259_16325932 | |
## comment by @eddi | |
id <- c('date', 'userid') | |
dt[dt[, .I[1:2], by = id]$V1] # first 2 rows by id | |
dt[dt[, .I[.N], by = id]$V1] # last row by id (.N = length of group, .I = row index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
year | date | holiday | |
---|---|---|---|
2000 | 2000-01-01 | New Year's Day | |
2000 | 2000-02-05 | Chinese New Year | |
2000 | 2000-02-14 | Valentine's Day | |
2000 | 2000-04-23 | Easter Sunday | |
2000 | 2000-05-14 | Mother's Day | |
2000 | 2000-06-18 | Father's Day | |
2000 | 2000-07-04 | Independence Day | |
2000 | 2000-10-31 | Halloween | |
2000 | 2000-11-23 | Thanksgiving Day |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
class ExpandSelectionToEofCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
v = self.view | |
s = v.sel() | |
eof = v.size() | |
first_point = v.line(s[0]).a | |
region_to_eof = sublime.Region(first_point, eof) |