Skip to content

Instantly share code, notes, and snippets.

View nikosbosse's full-sized avatar

Nikos Bosse nikosbosse

View GitHub Profile
@nikosbosse
nikosbosse / while.c
Created January 12, 2020 13:04
Intro to C-programming: While-Loops
#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;
@nikosbosse
nikosbosse / 1_hello_world.c
Last active January 12, 2020 13:32
Introduction to C
#include <stdio.h>
int main(void){
printf("Hello World");
return 0;
}
@nikosbosse
nikosbosse / applyfunction.R
Last active January 14, 2020 21:57
Two Histograms in One Plot
## 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 / plot_two_histograms.R
Created January 14, 2020 21:53
plot_two_histograms
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
# 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)))}