{"action":"created","comment":{"url":"https://api.github.com/repos/stan-dev/example-models/pulls/comments/52834361","id":52834361,"diff_hunk":"@@ -0,0 +1,115 @@\n+// -------------------------------------------------\n+// States (S):\n+// 1 alive at A\n+// 2 alive at B\n+// 3 dead\n+// Observations (O):  \n+// 1 seen at A \n+// 2 seen at B\n+// 3 not seen\n+// -------------------------------------------------\n+\n+functions {\n+  int first_capture(int[] y_i) {\n+    for (k in 1:size(y_i))\n+      if (y_i[k] != 3)\n+        return k;\n+    return 0;\n+  }\n+}\n+\n+data {\n+  int<lower=0> nind;\n+  int<lower=0> n_occasions;\n+  int<lower=1,upper=3> y[nind, n_occasions];\n+}\n+\n+transformed data {\n+  int<lower=0,upper=n_occasions> first[nind];\n+\n+  for (i in 1:nind)\n+    first[i] <- first_capture(y[i]);\n+}\n+\n+parameters {\n+  real<lower=0,upper=1> mean_phi[2]; // Mean state-spec. survival\n+  real<lower=0,upper=1> mean_psi[2]; // Mean transitions\n+  real<lower=0,upper=1> mean_p[2];   // Mean state-spec. recapture\n+}\n+\n+transformed parameters {\n+  vector<lower=0,upper=1>[n_occasions-1] phiA;  // Survival prob. at site A\n+  vector<lower=0,upper=1>[n_occasions-1] phiB;  // Survival prob. at site B\n+  vector<lower=0,upper=1>[n_occasions-1] psiAB; // Movement prob. from site A to site B\n+  vector<lower=0,upper=1>[n_occasions-1] psiBA; // Movement prob. from site B to site A\n+  vector<lower=0,upper=1>[n_occasions-1] pA;    // Recapture prob. at site A\n+  vector<lower=0,upper=1>[n_occasions-1] pB;    // Recapture prob. at site B\n+  simplex[3] ps[3, n_occasions-1];\n+  simplex[3] po[3, n_occasions-1];\n+\n+  // Constraints\n+  for (t in 1:(n_occasions - 1)) {\n+    phiA[t] <- mean_phi[1];\n+    phiB[t] <- mean_phi[2];\n+    psiAB[t] <- mean_psi[1];\n+    psiBA[t] <- mean_psi[2];\n+    pA[t] <- mean_p[1];\n+    pB[t] <- mean_p[2];\n+  }\n+\n+  // Define state-transition and observation matrices\n+  // Define probabilities of state S(t+1) given S(t)\n+  for (t in 1:(n_occasions - 1)) {\n+    ps[1, t, 1] <- phiA[t] * (1.0 - psiAB[t]);\n+    ps[1, t, 2] <- phiA[t] * psiAB[t];\n+    ps[1, t, 3] <- 1.0 - phiA[t];\n+    ps[2, t, 1] <- phiB[t] * psiBA[t];\n+    ps[2, t, 2] <- phiB[t] * (1 - psiBA[t]);\n+    ps[2, t, 3] <- 1.0 - phiB[t];\n+    ps[3, t, 1] <- 0.0;\n+    ps[3, t, 2] <- 0.0;\n+    ps[3, t, 3] <- 1.0;\n+    \n+    // Define probabilities of O(t) given S(t)\n+    po[1, t, 1] <- pA[t];\n+    po[1, t, 2] <- 0.0;\n+    po[1, t, 3] <- 1.0 - pA[t];\n+    po[2, t, 1] <- 0.0;\n+    po[2, t, 2] <- pB[t];\n+    po[2, t, 3] <- 1.0 - pB[t];\n+    po[3, t, 1] <- 0.0;\n+    po[3, t, 2] <- 0.0;\n+    po[3, t, 3] <- 1.0;\n+  } //t\n+}\n+\n+model {\n+  real acc[3];\n+  vector[3] gamma[n_occasions];\n+\n+  // Priors\n+  mean_phi ~ uniform(0, 1);\n+  mean_psi ~ uniform(0, 1);\n+  mean_p ~ uniform(0, 1);\n+\n+  // Likelihood\n+  // Forward algorithm derived from Stan Modeling Language\n+  // User's Guide and Reference Manual\n+  for (i in 1:nind) {","path":"BPA/Ch.09/ms_alternative1.stan","position":106,"original_position":98,"commit_id":"796347da6c0853a7f0da919d6fe3eb69a58a17c1","original_commit_id":"2175e71d53721ebd482dbf1c96126ac12233290b","user":{"login":"ito4303","id":13703977,"avatar_url":"https://avatars.githubusercontent.com/u/13703977?v=3","gravatar_id":"","url":"https://api.github.com/users/ito4303","html_url":"https://github.com/ito4303","followers_url":"https://api.github.com/users/ito4303/followers","following_url":"https://api.github.com/users/ito4303/following{/other_user}","gists_url":"https://api.github.com/users/ito4303/gists{/gist_id}","starred_url":"https://api.github.com/users/ito4303/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ito4303/subscriptions","organizations_url":"https://api.github.com/users/ito4303/orgs","repos_url":"https://api.github.com/users/ito4303/repos","events_url":"https://api.github.com/users/ito4303/events{/privacy}","received_events_url":"https://api.github.com/users/ito4303/received_events","type":"User","site_admin":false},"body":"I could not do so because an increment_log_prob function is inside the loop and it must be in the model block.","created_at":"2016-02-13T22:08:21Z","updated_at":"2016-02-13T22:08:21Z","html_url":"https://github.com/stan-dev/example-models/pull/43#discussion_r52834361","pull_request_url":"https://api.github.com/repos/stan-dev/example-models/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/comments/52834361"},"html":{"href":"https://github.com/stan-dev/example-models/pull/43#discussion_r52834361"},"pull_request":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/stan-dev/example-models/pulls/43","id":59221566,"html_url":"https://github.com/stan-dev/example-models/pull/43","diff_url":"https://github.com/stan-dev/example-models/pull/43.diff","patch_url":"https://github.com/stan-dev/example-models/pull/43.patch","issue_url":"https://api.github.com/repos/stan-dev/example-models/issues/43","number":43,"state":"open","locked":false,"title":"BPA: Add Chapter 9","user":{"login":"ito4303","id":13703977,"avatar_url":"https://avatars.githubusercontent.com/u/13703977?v=3","gravatar_id":"","url":"https://api.github.com/users/ito4303","html_url":"https://github.com/ito4303","followers_url":"https://api.github.com/users/ito4303/followers","following_url":"https://api.github.com/users/ito4303/following{/other_user}","gists_url":"https://api.github.com/users/ito4303/gists{/gist_id}","starred_url":"https://api.github.com/users/ito4303/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ito4303/subscriptions","organizations_url":"https://api.github.com/users/ito4303/orgs","repos_url":"https://api.github.com/users/ito4303/repos","events_url":"https://api.github.com/users/ito4303/events{/privacy}","received_events_url":"https://api.github.com/users/ito4303/received_events","type":"User","site_admin":false},"body":"I added models translated from Chapter 9 of BPA.","created_at":"2016-02-12T19:47:47Z","updated_at":"2016-02-13T22:08:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b3482553ae2caa1fba057c8030b81ab8b558aa9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stan-dev/example-models/pulls/43/commits","review_comments_url":"https://api.github.com/repos/stan-dev/example-models/pulls/43/comments","review_comment_url":"https://api.github.com/repos/stan-dev/example-models/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stan-dev/example-models/issues/43/comments","statuses_url":"https://api.github.com/repos/stan-dev/example-models/statuses/796347da6c0853a7f0da919d6fe3eb69a58a17c1","head":{"label":"ito4303:BPA","ref":"BPA","sha":"796347da6c0853a7f0da919d6fe3eb69a58a17c1","user":{"login":"ito4303","id":13703977,"avatar_url":"https://avatars.githubusercontent.com/u/13703977?v=3","gravatar_id":"","url":"https://api.github.com/users/ito4303","html_url":"https://github.com/ito4303","followers_url":"https://api.github.com/users/ito4303/followers","following_url":"https://api.github.com/users/ito4303/following{/other_user}","gists_url":"https://api.github.com/users/ito4303/gists{/gist_id}","starred_url":"https://api.github.com/users/ito4303/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ito4303/subscriptions","organizations_url":"https://api.github.com/users/ito4303/orgs","repos_url":"https://api.github.com/users/ito4303/repos","events_url":"https://api.github.com/users/ito4303/events{/privacy}","received_events_url":"https://api.github.com/users/ito4303/received_events","type":"User","site_admin":false},"repo":{"id":47541215,"name":"example-models","full_name":"ito4303/example-models","owner":{"login":"ito4303","id":13703977,"avatar_url":"https://avatars.githubusercontent.com/u/13703977?v=3","gravatar_id":"","url":"https://api.github.com/users/ito4303","html_url":"https://github.com/ito4303","followers_url":"https://api.github.com/users/ito4303/followers","following_url":"https://api.github.com/users/ito4303/following{/other_user}","gists_url":"https://api.github.com/users/ito4303/gists{/gist_id}","starred_url":"https://api.github.com/users/ito4303/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ito4303/subscriptions","organizations_url":"https://api.github.com/users/ito4303/orgs","repos_url":"https://api.github.com/users/ito4303/repos","events_url":"https://api.github.com/users/ito4303/events{/privacy}","received_events_url":"https://api.github.com/users/ito4303/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ito4303/example-models","description":"","fork":true,"url":"https://api.github.com/repos/ito4303/example-models","forks_url":"https://api.github.com/repos/ito4303/example-models/forks","keys_url":"https://api.github.com/repos/ito4303/example-models/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ito4303/example-models/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ito4303/example-models/teams","hooks_url":"https://api.github.com/repos/ito4303/example-models/hooks","issue_events_url":"https://api.github.com/repos/ito4303/example-models/issues/events{/number}","events_url":"https://api.github.com/repos/ito4303/example-models/events","assignees_url":"https://api.github.com/repos/ito4303/example-models/assignees{/user}","branches_url":"https://api.github.com/repos/ito4303/example-models/branches{/branch}","tags_url":"https://api.github.com/repos/ito4303/example-models/tags","blobs_url":"https://api.github.com/repos/ito4303/example-models/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ito4303/example-models/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ito4303/example-models/git/refs{/sha}","trees_url":"https://api.github.com/repos/ito4303/example-models/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ito4303/example-models/statuses/{sha}","languages_url":"https://api.github.com/repos/ito4303/example-models/languages","stargazers_url":"https://api.github.com/repos/ito4303/example-models/stargazers","contributors_url":"https://api.github.com/repos/ito4303/example-models/contributors","subscribers_url":"https://api.github.com/repos/ito4303/example-models/subscribers","subscription_url":"https://api.github.com/repos/ito4303/example-models/subscription","commits_url":"https://api.github.com/repos/ito4303/example-models/commits{/sha}","git_commits_url":"https://api.github.com/repos/ito4303/example-models/git/commits{/sha}","comments_url":"https://api.github.com/repos/ito4303/example-models/comments{/number}","issue_comment_url":"https://api.github.com/repos/ito4303/example-models/issues/comments{/number}","contents_url":"https://api.github.com/repos/ito4303/example-models/contents/{+path}","compare_url":"https://api.github.com/repos/ito4303/example-models/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ito4303/example-models/merges","archive_url":"https://api.github.com/repos/ito4303/example-models/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ito4303/example-models/downloads","issues_url":"https://api.github.com/repos/ito4303/example-models/issues{/number}","pulls_url":"https://api.github.com/repos/ito4303/example-models/pulls{/number}","milestones_url":"https://api.github.com/repos/ito4303/example-models/milestones{/number}","notifications_url":"https://api.github.com/repos/ito4303/example-models/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ito4303/example-models/labels{/name}","releases_url":"https://api.github.com/repos/ito4303/example-models/releases{/id}","deployments_url":"https://api.github.com/repos/ito4303/example-models/deployments","created_at":"2015-12-07T09:06:25Z","updated_at":"2016-01-22T11:09:41Z","pushed_at":"2016-02-13T21:57:52Z","git_url":"git://github.com/ito4303/example-models.git","ssh_url":"git@github.com:ito4303/example-models.git","clone_url":"https://github.com/ito4303/example-models.git","svn_url":"https://github.com/ito4303/example-models","homepage":null,"size":55156,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"stan-dev:master","ref":"master","sha":"6f0546b7aae4eed96798c324964f6de03e533b6d","user":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":22768481,"name":"example-models","full_name":"stan-dev/example-models","owner":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stan-dev/example-models","description":"Example models for Stan","fork":false,"url":"https://api.github.com/repos/stan-dev/example-models","forks_url":"https://api.github.com/repos/stan-dev/example-models/forks","keys_url":"https://api.github.com/repos/stan-dev/example-models/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stan-dev/example-models/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stan-dev/example-models/teams","hooks_url":"https://api.github.com/repos/stan-dev/example-models/hooks","issue_events_url":"https://api.github.com/repos/stan-dev/example-models/issues/events{/number}","events_url":"https://api.github.com/repos/stan-dev/example-models/events","assignees_url":"https://api.github.com/repos/stan-dev/example-models/assignees{/user}","branches_url":"https://api.github.com/repos/stan-dev/example-models/branches{/branch}","tags_url":"https://api.github.com/repos/stan-dev/example-models/tags","blobs_url":"https://api.github.com/repos/stan-dev/example-models/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stan-dev/example-models/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stan-dev/example-models/git/refs{/sha}","trees_url":"https://api.github.com/repos/stan-dev/example-models/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stan-dev/example-models/statuses/{sha}","languages_url":"https://api.github.com/repos/stan-dev/example-models/languages","stargazers_url":"https://api.github.com/repos/stan-dev/example-models/stargazers","contributors_url":"https://api.github.com/repos/stan-dev/example-models/contributors","subscribers_url":"https://api.github.com/repos/stan-dev/example-models/subscribers","subscription_url":"https://api.github.com/repos/stan-dev/example-models/subscription","commits_url":"https://api.github.com/repos/stan-dev/example-models/commits{/sha}","git_commits_url":"https://api.github.com/repos/stan-dev/example-models/git/commits{/sha}","comments_url":"https://api.github.com/repos/stan-dev/example-models/comments{/number}","issue_comment_url":"https://api.github.com/repos/stan-dev/example-models/issues/comments{/number}","contents_url":"https://api.github.com/repos/stan-dev/example-models/contents/{+path}","compare_url":"https://api.github.com/repos/stan-dev/example-models/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stan-dev/example-models/merges","archive_url":"https://api.github.com/repos/stan-dev/example-models/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stan-dev/example-models/downloads","issues_url":"https://api.github.com/repos/stan-dev/example-models/issues{/number}","pulls_url":"https://api.github.com/repos/stan-dev/example-models/pulls{/number}","milestones_url":"https://api.github.com/repos/stan-dev/example-models/milestones{/number}","notifications_url":"https://api.github.com/repos/stan-dev/example-models/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stan-dev/example-models/labels{/name}","releases_url":"https://api.github.com/repos/stan-dev/example-models/releases{/id}","deployments_url":"https://api.github.com/repos/stan-dev/example-models/deployments","created_at":"2014-08-08T19:03:11Z","updated_at":"2016-02-04T21:49:24Z","pushed_at":"2016-02-13T21:57:52Z","git_url":"git://github.com/stan-dev/example-models.git","ssh_url":"git@github.com:stan-dev/example-models.git","clone_url":"https://github.com/stan-dev/example-models.git","svn_url":"https://github.com/stan-dev/example-models","homepage":"http://mc-stan.org/","size":56814,"stargazers_count":141,"watchers_count":141,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":93,"mirror_url":null,"open_issues_count":13,"forks":93,"open_issues":13,"watchers":141,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/43"},"html":{"href":"https://github.com/stan-dev/example-models/pull/43"},"issue":{"href":"https://api.github.com/repos/stan-dev/example-models/issues/43"},"comments":{"href":"https://api.github.com/repos/stan-dev/example-models/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stan-dev/example-models/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/stan-dev/example-models/statuses/796347da6c0853a7f0da919d6fe3eb69a58a17c1"}}}}