Skip to content

Instantly share code, notes, and snippets.

Avatar

Nikos Bosse nikosbosse

View GitHub Profile
View gist:5b7e96ea2b1d159dfd835016ef26ef6f
# in the R script:
init_fun <- function(){list(R = array(rep(rgamma(n = data$t,
shape = (rt_prior$mean / rt_prior$sd)^2,
scale = (rt_prior$sd^2) / rt_prior$mean),
data$k),dim = c(data$k, data$t)),
phi = array(rexp(data$k, 1/2)))}
View plot_two_histograms.R
plot_two_histograms <- function(vector1, vector2,
breaks = 100,
upper_limit = NA,
...){
if(!is.na(upper_limit)){
vector1 <- vector1[vector1 < upper_limit]
vector2 <- vector2[vector2 < upper_limit]
}
## set breakpoints and define minimum
@nikosbosse
nikosbosse / applyfunction.R
Last active Jan 14, 2020
Two Histograms in One Plot
View applyfunction.R
## illustrate prior
prior <- rnorm(100000, 0.5, 0.5)
## extract posterior from Stan
posterior <- extract(my_stanfitobject)$my_parameter
## alternatively, create some second vector
vector2 <- rnorm(100000, 2, 0.8)
plot_two_histograms(prior, vector2, breaks = 100,
@nikosbosse
nikosbosse / 1_hello_world.c
Last active Jan 12, 2020
Introduction to C
View 1_hello_world.c
#include <stdio.h>
int main(void){
printf("Hello World");
return 0;
}
@nikosbosse
nikosbosse / while.c
Created Jan 12, 2020
Intro to C-programming: While-Loops
View while.c
#include <stdio.h>
int main(void){
int counter = 0;
int t = 1;
while (t){
counter++;
printf("counter: %d\n", counter);
if (counter == 5){
t = 0;