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
test_num | id | shell_width | gender | start_date | end_date | choice | making_process | whole_px | hole_px | cm_per_px | leg_lack | cutting | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 13 | 8.04 | M | 2015/12/16 | 2015/12/19 | L | no_digging | NA | NA | NA | no | f | |
2 | 12 | 6.78 | F | 2015/12/19 | 2015/12/20 | M | NA | 92820 | 51210 | 0.024360536 | no | f | |
3 | 6 | 6.43 | M | 2015/12/20 | 2015/12/21 | L | breaking | 365628 | 225539 | 0.024154589 | no | t | |
4 | 9 | 3.54 | F | 2015/12/21 | 2015/12/22 | M | NA | 98304 | 29696 | 0.024183797 | no | f | |
5 | 14 | 6.83 | F | 2015/12/22 | 2015/12/23 | L | breaking | 143793 | 96282 | 0.024242424 | no | t | |
6 | 15 | 6.35 | M | 2015/12/23 | 2015/12/24 | L | breaking | 137267 | 101706 | 0.024271845 | no | t | |
7 | 16 | 10.76 | M | 2015/12/24 | 2015/12/31 | no_choice | NA | NA | NA | no | f | ||
8 | 17 | 7.35 | F | 2015/12/31 | 2016/1/4 | no_choice | NA | NA | NA | no | f | ||
9 | 18 | 9.8 | M | 2016/1/4 | 2016/1/16 | no_choice | NA | NA | NA | no | f |
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
functions { | |
real f(real mu, real s, real x){ | |
return(normal_lpdf(x | mu, s)); | |
} | |
real log_lik_Simpson(real mu, real s, real a, real b, int M) { | |
vector[M+1] lp; | |
real h; | |
h = (b-a)/M; | |
lp[1] = f(mu, s, a); |
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
functions { | |
real f(real mu, real s, real x){ | |
// separately performing numerical integration to make this computing fast | |
return(normal_lpdf(x | mu, s)); | |
} | |
real log_lik_Simpson(real mu, real s, real a, real b, int M) { | |
// numerical integration using the Simpson's rule | |
vector[M+1] lp; | |
real h; |
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(rstan) | |
library(tidyverse) | |
rstan_options(auto_write = TRUE) | |
options(mc.cores = parallel::detectCores()) | |
## preprocessing | |
d <- read_csv(file='Dromiidae.csv') # https://gist.github.com/kagaya/0d309397300b7e8294fe53c44b6fc525 | |
d <- d %>% | |
select(c('shell_width', 'choice', |
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(ggrepel) | |
library(rstan) | |
expose_stan_functions("my_stan_functions.stan") # https://gist.github.com/kagaya/c726f16d82b80026bb1924b408a72b5c | |
source("utility.R") # https://gist.github.com/kagaya/60c4190ac306840daee54115b3c315c3 | |
plot_choice_random_intercept <- function(d, fit){ | |
# mu[n,2] = bias_l[ID[n]] + cwl*C_width[n] + ll*Leg_lack[n]; | |
# mu[n,3] = bias_no0 + cwno*C_width[n] + lno*Leg_lack[n]; | |
ms <- rstan::extract(fit) |
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
waic <- function(log_likelihood) { | |
# from https://gist.github.com/MatsuuraKentaro/3f6ae5863e700f5039c19e36a9bdf646 | |
training_error <- - mean(log(colMeans(exp(log_likelihood)))) | |
functional_variance_div_N <- mean(colMeans(log_likelihood^2) - colMeans(log_likelihood)^2) | |
waic <- training_error + functional_variance_div_N | |
return(waic) | |
} |
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(grid) | |
library(gtable) | |
plot_segment_across_facets <- function(p, from=1, to=2, | |
from_point_id=1, | |
to_point_id=1, | |
plotout = F, | |
gp=gpar(lty=1, alpha=0.5)){ |
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
--- | |
title: "an example of model comparison by WAIC (draft)" | |
author: "Katsushi Kagaya" | |
date: "`r Sys.time()`" | |
output: | |
html_document: default | |
--- | |
# motivation and aims |
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
functions { | |
vector my_student_t_rng(int N, real nu, real mu, real sigma){ | |
vector[N] Y; | |
for (n in 1:N){ | |
Y[n] = student_t_rng(nu, mu, sigma); | |
} | |
return(Y); | |
} | |
vector my_ZIP_rng(int N, real q, real lambda){ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.