Last active
June 4, 2018 02:39
-
-
Save kagaya/21360be217d22d3f7ede3496f88f5ba6 to your computer and use it in GitHub Desktop.
copy of kick_model_1_1_choice.R
This file contains 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', | |
'id', 'leg_lack' )) | |
d <- d[complete.cases(d), ] | |
## renumber animal id from 1 | |
id <- as.factor(d$id) | |
levels(id) <- as.character(1:length(levels(id))) | |
d$id <- as.integer(id) | |
d$choice <- as.factor(d$choice) | |
levels(d$choice) <- c(2,1,3) # label M,L,No, as 1,2,3 | |
d$choice <- as.integer(as.character(d$choice)) | |
d$leg_lack <- as.factor(d$leg_lack) | |
levels(d$leg_lack) <- c(2,3,1) # label no_leg_lack, A, C, as 1, 2, 3 | |
d$leg_lack <- as.integer(as.character(d$leg_lack)) | |
data <- list(N=nrow(d), | |
K=max(d$choice), | |
L=max(d$id), | |
Y=d$choice, | |
C_width=d$shell_width, | |
Leg_lack=d$leg_lack, | |
ID=d$id) | |
fit <- stan(file='model_1_1_choice.stan', # kick this stan file | |
data=data, seed=1234, | |
chains=4, iter=6000, warmup=1000, thin=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment