Skip to content

Instantly share code, notes, and snippets.

@kagaya
Last active June 4, 2018 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagaya/21360be217d22d3f7ede3496f88f5ba6 to your computer and use it in GitHub Desktop.
Save kagaya/21360be217d22d3f7ede3496f88f5ba6 to your computer and use it in GitHub Desktop.
copy of kick_model_1_1_choice.R
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