{"action":"created","issue":{"url":"https://api.github.com/repos/stan-dev/stan/issues/1757","labels_url":"https://api.github.com/repos/stan-dev/stan/issues/1757/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1757/comments","events_url":"https://api.github.com/repos/stan-dev/stan/issues/1757/events","html_url":"https://github.com/stan-dev/stan/issues/1757","id":127995747,"number":1757,"title":"Stan doesn't respect starting values for multiple chains","user":{"login":"RobertMyles","id":7211207,"avatar_url":"https://avatars.githubusercontent.com/u/7211207?v=3","gravatar_id":"","url":"https://api.github.com/users/RobertMyles","html_url":"https://github.com/RobertMyles","followers_url":"https://api.github.com/users/RobertMyles/followers","following_url":"https://api.github.com/users/RobertMyles/following{/other_user}","gists_url":"https://api.github.com/users/RobertMyles/gists{/gist_id}","starred_url":"https://api.github.com/users/RobertMyles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobertMyles/subscriptions","organizations_url":"https://api.github.com/users/RobertMyles/orgs","repos_url":"https://api.github.com/users/RobertMyles/repos","events_url":"https://api.github.com/users/RobertMyles/events{/privacy}","received_events_url":"https://api.github.com/users/RobertMyles/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-21T18:59:43Z","updated_at":"2016-01-22T00:32:48Z","closed_at":null,"body":"Hi stan folks,\r\n\r\nFirst of all, thanks for stan, it's fantastic, and has saved me lots of time, as I was trying to run some ideal-point IRT models with JAGS and it was really slow. However, I'm having some trouble making stan use the initial values that I specify for my model (and initial values are important for these models). The model runs fine, it's a simple model, but never uses the initial values I provide. \r\n\r\nI have tried all the ways suggested in the R help for stan, and two ways are reproduced below in the toy example I provide. With one chain, there is no problem.  \r\n\r\nHere's my example and thanks for any help:\r\n(I know it's a short run so error messages pop up about the treesize etc., but it's the initial values problem that I'm interested in)\r\n\r\n\r\n```library(rstan)\r\nJ <- 35\r\nK <- 50\r\nThetaInit <- rnorm(J, 0, 1)\r\nThetaInit[1] <- 1.5\r\nThetaInit[2] <- -1.5\r\nBetaInit <- rnorm(K, 0, 3)\r\nAlphaInit <- rnorm(K, 0, 3)\r\ny <- matrix(rbinom(J*K, size=1, prob=0.5), J, K)\r\n\r\n#My real data has plenty of NA, so just to keep the example similar to the real thing:\r\n\r\ny[20, 12] <- NA\r\ny[5, 11] <- NA\r\ny[6, 2] <- NA\r\n\r\nN <- length(y)\r\nj <- rep(1:J, times=K)\r\nk <- rep(1:K, each=J)\r\n\r\n#delete missing values\r\n\r\nmissing <- which(is.na(y))\r\nN <- N - length(missing)\r\nj <- j[-missing]\r\nk <- k[-missing]\r\ny <- y[-missing]\r\n\r\n #Model\r\n\r\nstan.code <- \"\r\ndata {\r\n  int<lower=1> J;\r\n  int<lower=1> K;\r\n  int<lower=1> N;\r\n  int<lower=1, upper=J> j[N];\r\n  int<lower=1, upper=K> k[N];\r\n  int<lower=0, upper=1> y[N];\r\n}\r\nparameters {\r\n  real alpha[K];\r\n  real beta[K];\r\n  real theta[J];\r\n}\r\nmodel {\r\n  alpha ~ normal(0,3); \r\n  beta ~ normal(0,3); \r\n  theta ~ normal(0,1); \r\n  theta[1] ~  normal(1, .001);\r\n  theta[2] ~ normal(-1, .001); \r\nfor (n in 1:N)\r\n  y[n] ~ bernoulli(Phi(theta[j[n]] * beta[k[n]] - alpha[k[n]]));\r\n}\"\r\n\r\n # Inits\r\n # function form 2 with an argument named \"chain_id\"\r\n # This is copied from ?stan\r\n\r\ninitf2 <- function(chain_id = 1) {\r\n  # cat(\"chain_id =\", chain_id, \"\\n\")\r\n  list(beta=list(BetaInit), theta=list(ThetaInit), alpha=list(AlphaInit))\r\n} \r\n\r\n # generate a list of lists to specify initial values\r\n # Copied from ?stan\r\n\r\nn_chains <- 4\r\ninit_ll <- lapply(1:n_chains, function(id) initf2(chain_id = id))\r\n\r\nstan.data <- list(J=J, K=K, N=N, j=j, k=k, y=y)\r\n\r\nstan.fit <- stan(model_code=stan.code, data=stan.data,\r\n iter=100, warmup=25, chains=4, thin=1,\r\n init=init_ll, verbose=TRUE, cores=4, seed=1234)\r\n\r\nget_inits(stan.fit)\r\nInitList <- get_inits(stan.fit)\r\nTheta1 <- InitList[[1]][3]\r\nTheta2 <- InitList[[2]][3]\r\nTheta3 <- InitList[[3]][3]\r\nTheta4 <- InitList[[4]][3]\r\n\r\nTheta1[[1]][1] # all should be exactly 1.5\r\n[1] -0.8131447\r\nTheta2[[1]][1]\r\n[1] 1.644208\r\nTheta3[[1]][1]\r\n[1] 1.42286\r\nTheta4[[1]][1]\r\n[1] 0.3714791\r\n```"},"comment":{"url":"https://api.github.com/repos/stan-dev/stan/issues/comments/173761118","html_url":"https://github.com/stan-dev/stan/issues/1757#issuecomment-173761118","issue_url":"https://api.github.com/repos/stan-dev/stan/issues/1757","id":173761118,"user":{"login":"betanalpha","id":1527190,"avatar_url":"https://avatars.githubusercontent.com/u/1527190?v=3","gravatar_id":"","url":"https://api.github.com/users/betanalpha","html_url":"https://github.com/betanalpha","followers_url":"https://api.github.com/users/betanalpha/followers","following_url":"https://api.github.com/users/betanalpha/following{/other_user}","gists_url":"https://api.github.com/users/betanalpha/gists{/gist_id}","starred_url":"https://api.github.com/users/betanalpha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betanalpha/subscriptions","organizations_url":"https://api.github.com/users/betanalpha/orgs","repos_url":"https://api.github.com/users/betanalpha/repos","events_url":"https://api.github.com/users/betanalpha/events{/privacy}","received_events_url":"https://api.github.com/users/betanalpha/received_events","type":"User","site_admin":false},"created_at":"2016-01-22T00:32:48Z","updated_at":"2016-01-22T00:32:48Z","body":"Ooh, sorry, I didn’t recognize that it was the RStan specific\n“get_inits” function.  Those values look like they’re initialized\nand the init values are never being set.\n\nOn Jan 22, 2016, at 12:21 AM, Jonah Gabry <notifications@github.com> wrote:\n\n> If rstan::get_inits doesn't actually return initial values then I guess we should probably name the function something else or get rid of it.\n> \n> —\n> Reply to this email directly or view it on GitHub.\n> \n\n"}}