{"action":"created","comment":{"url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/comments/198340389","pull_request_review_id":132255018,"id":198340389,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5ODM0MDM4OQ==","diff_hunk":"@@ -391,3 +420,12 @@ loglik_obs(::Gamma, y, μ, wt, ϕ) = wt*logpdf(Gamma(inv(ϕ), μ*ϕ), y)\n loglik_obs(::InverseGaussian, y, μ, wt, ϕ) = wt*logpdf(InverseGaussian(μ, inv(ϕ)), y)\n loglik_obs(::Normal, y, μ, wt, ϕ) = wt*logpdf(Normal(μ, sqrt(ϕ)), y)\n loglik_obs(::Poisson, y, μ, wt, ϕ) = wt*logpdf(Poisson(μ), y)\n+# in principle, μ = θp/(1-p) ==> p = μ/(μ+θ), and thus we should have been able\n+# to do following\n+# loglik_obs(d::NegativeBinomial, y, μ, wt, ϕ) = wt*logpdf(NegativeBinomial(d.r, μ/(μ+d.r)), y)\n+# however, that does not give the correct answer compared to that of R's `glm.nb`","path":"src/glmtools.jl","position":78,"original_position":78,"commit_id":"741dbb5a875b1d334bee5fc85977be4e33775897","original_commit_id":"0f3dd9bd7e16d00d75c131c7af7d4163da4a6b24","user":{"login":"hung-q-ngo","id":10747930,"node_id":"MDQ6VXNlcjEwNzQ3OTMw","avatar_url":"https://avatars2.githubusercontent.com/u/10747930?v=4","gravatar_id":"","url":"https://api.github.com/users/hung-q-ngo","html_url":"https://github.com/hung-q-ngo","followers_url":"https://api.github.com/users/hung-q-ngo/followers","following_url":"https://api.github.com/users/hung-q-ngo/following{/other_user}","gists_url":"https://api.github.com/users/hung-q-ngo/gists{/gist_id}","starred_url":"https://api.github.com/users/hung-q-ngo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hung-q-ngo/subscriptions","organizations_url":"https://api.github.com/users/hung-q-ngo/orgs","repos_url":"https://api.github.com/users/hung-q-ngo/repos","events_url":"https://api.github.com/users/hung-q-ngo/events{/privacy}","received_events_url":"https://api.github.com/users/hung-q-ngo/received_events","type":"User","site_admin":false},"body":"@nalimilan : I appreciate the encouragement.\r\n\r\nW.r.t. the above `loglik_obs` issue, if we use the straightforward \r\n```\r\nloglik_obs(d::NegativeBinomial, y, μ, wt, ϕ) = wt*logpdf(NegativeBinomial(d.r, μ/(μ+d.r)), y)\r\n```\r\nthen the `loglikelihood` numbers are not correct anymore. In `runtest.jl`, the `gm18` model would return\r\n```\r\njulia> loglikelihood(gm18)\r\n-5208.360845881062\r\n```\r\ninstead of the expected ` -553.259` (the same LL returned by `glm.nb` from `MASS`). I haven't been able to figure out why.","created_at":"2018-06-27T01:05:16Z","updated_at":"2018-06-27T01:05:16Z","html_url":"https://github.com/JuliaStats/GLM.jl/pull/238#discussion_r198340389","pull_request_url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/comments/198340389"},"html":{"href":"https://github.com/JuliaStats/GLM.jl/pull/238#discussion_r198340389"},"pull_request":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238"}},"in_reply_to_id":198114963},"pull_request":{"url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238","id":193171744,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzMTcxNzQ0","html_url":"https://github.com/JuliaStats/GLM.jl/pull/238","diff_url":"https://github.com/JuliaStats/GLM.jl/pull/238.diff","patch_url":"https://github.com/JuliaStats/GLM.jl/pull/238.patch","issue_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/238","number":238,"state":"open","locked":false,"title":"Negative Binomial regression support","user":{"login":"hung-q-ngo","id":10747930,"node_id":"MDQ6VXNlcjEwNzQ3OTMw","avatar_url":"https://avatars2.githubusercontent.com/u/10747930?v=4","gravatar_id":"","url":"https://api.github.com/users/hung-q-ngo","html_url":"https://github.com/hung-q-ngo","followers_url":"https://api.github.com/users/hung-q-ngo/followers","following_url":"https://api.github.com/users/hung-q-ngo/following{/other_user}","gists_url":"https://api.github.com/users/hung-q-ngo/gists{/gist_id}","starred_url":"https://api.github.com/users/hung-q-ngo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hung-q-ngo/subscriptions","organizations_url":"https://api.github.com/users/hung-q-ngo/orgs","repos_url":"https://api.github.com/users/hung-q-ngo/repos","events_url":"https://api.github.com/users/hung-q-ngo/events{/privacy}","received_events_url":"https://api.github.com/users/hung-q-ngo/received_events","type":"User","site_admin":false},"body":"There were a couple of requests for negative binomial regression support ( [issue 209](https://github.com/JuliaStats/GLM.jl/issues/209) for instance). From comments by @dmbates and @bbolker , and from reading section 7.4 of \"_Modern Applied Statistics with S, 4th ed._\", I understand that training the model involves fixing \"theta\", use GLM machinery to estimate \"beta\", then use that to estimate \"theta\" and so forth.\r\n\r\nThis PR allows `GLM.jl` to support calls of the type\r\n```\r\nnbmodel = glm(@formula(Days ~ Eth+Sex+Age+Lrn), quine, NegativeBinomial(2.0), LogLink())\r\n```\r\nin exactly the same way we can write that in `R`, without using the `glm.nb` package:\r\n```\r\nmodel = glm(Days ~ Eth + Sex + Age + Lrn, family = negative.binomial(2), data=quine)\r\n```\r\nIn the above calls, the parameter `theta` is fixed/given. To also compute an MLE estimate for theta, we can call\r\n\r\n```\r\nmodel = negbin(@formula(Days ~ Eth+Sex+Age+Lrn), quine, LogLink())           \r\n```\r\n\r\nComments/feedback are greatly appreciated.\r\n\r\nFixes https://github.com/JuliaStats/GLM.jl/issues/209.","created_at":"2018-06-07T00:00:51Z","updated_at":"2018-06-27T01:05:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0bc6d1f2196a1e2278493c35c653cf2b305ce5a","assignee":null,"assignees":[],"requested_reviewers":[{"login":"andreasnoack","id":505001,"node_id":"MDQ6VXNlcjUwNTAwMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/505001?v=4","gravatar_id":"","url":"https://api.github.com/users/andreasnoack","html_url":"https://github.com/andreasnoack","followers_url":"https://api.github.com/users/andreasnoack/followers","following_url":"https://api.github.com/users/andreasnoack/following{/other_user}","gists_url":"https://api.github.com/users/andreasnoack/gists{/gist_id}","starred_url":"https://api.github.com/users/andreasnoack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreasnoack/subscriptions","organizations_url":"https://api.github.com/users/andreasnoack/orgs","repos_url":"https://api.github.com/users/andreasnoack/repos","events_url":"https://api.github.com/users/andreasnoack/events{/privacy}","received_events_url":"https://api.github.com/users/andreasnoack/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238/commits","review_comments_url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238/comments","review_comment_url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/238/comments","statuses_url":"https://api.github.com/repos/JuliaStats/GLM.jl/statuses/741dbb5a875b1d334bee5fc85977be4e33775897","head":{"label":"RelationalAI-oss:master","ref":"master","sha":"741dbb5a875b1d334bee5fc85977be4e33775897","user":{"login":"RelationalAI-oss","id":32937086,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTM3MDg2","avatar_url":"https://avatars2.githubusercontent.com/u/32937086?v=4","gravatar_id":"","url":"https://api.github.com/users/RelationalAI-oss","html_url":"https://github.com/RelationalAI-oss","followers_url":"https://api.github.com/users/RelationalAI-oss/followers","following_url":"https://api.github.com/users/RelationalAI-oss/following{/other_user}","gists_url":"https://api.github.com/users/RelationalAI-oss/gists{/gist_id}","starred_url":"https://api.github.com/users/RelationalAI-oss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RelationalAI-oss/subscriptions","organizations_url":"https://api.github.com/users/RelationalAI-oss/orgs","repos_url":"https://api.github.com/users/RelationalAI-oss/repos","events_url":"https://api.github.com/users/RelationalAI-oss/events{/privacy}","received_events_url":"https://api.github.com/users/RelationalAI-oss/received_events","type":"Organization","site_admin":false},"repo":{"id":128092793,"node_id":"MDEwOlJlcG9zaXRvcnkxMjgwOTI3OTM=","name":"GLM.jl","full_name":"RelationalAI-oss/GLM.jl","owner":{"login":"RelationalAI-oss","id":32937086,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTM3MDg2","avatar_url":"https://avatars2.githubusercontent.com/u/32937086?v=4","gravatar_id":"","url":"https://api.github.com/users/RelationalAI-oss","html_url":"https://github.com/RelationalAI-oss","followers_url":"https://api.github.com/users/RelationalAI-oss/followers","following_url":"https://api.github.com/users/RelationalAI-oss/following{/other_user}","gists_url":"https://api.github.com/users/RelationalAI-oss/gists{/gist_id}","starred_url":"https://api.github.com/users/RelationalAI-oss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RelationalAI-oss/subscriptions","organizations_url":"https://api.github.com/users/RelationalAI-oss/orgs","repos_url":"https://api.github.com/users/RelationalAI-oss/repos","events_url":"https://api.github.com/users/RelationalAI-oss/events{/privacy}","received_events_url":"https://api.github.com/users/RelationalAI-oss/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RelationalAI-oss/GLM.jl","description":"Generalized linear models in Julia","fork":true,"url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl","forks_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/forks","keys_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/teams","hooks_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/hooks","issue_events_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/issues/events{/number}","events_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/events","assignees_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/assignees{/user}","branches_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/branches{/branch}","tags_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/tags","blobs_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/languages","stargazers_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/stargazers","contributors_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/contributors","subscribers_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/subscribers","subscription_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/subscription","commits_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/contents/{+path}","compare_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/merges","archive_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/downloads","issues_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/issues{/number}","pulls_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/labels{/name}","releases_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/releases{/id}","deployments_url":"https://api.github.com/repos/RelationalAI-oss/GLM.jl/deployments","created_at":"2018-04-04T16:53:50Z","updated_at":"2018-06-27T00:56:06Z","pushed_at":"2018-06-27T00:56:04Z","git_url":"git://github.com/RelationalAI-oss/GLM.jl.git","ssh_url":"git@github.com:RelationalAI-oss/GLM.jl.git","clone_url":"https://github.com/RelationalAI-oss/GLM.jl.git","svn_url":"https://github.com/RelationalAI-oss/GLM.jl","homepage":null,"size":622,"stargazers_count":0,"watchers_count":0,"language":"Julia","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JuliaStats:master","ref":"master","sha":"886f4fc8c2aa19487852746d754dd2874c43dac8","user":{"login":"JuliaStats","id":2761531,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjE1MzE=","avatar_url":"https://avatars2.githubusercontent.com/u/2761531?v=4","gravatar_id":"","url":"https://api.github.com/users/JuliaStats","html_url":"https://github.com/JuliaStats","followers_url":"https://api.github.com/users/JuliaStats/followers","following_url":"https://api.github.com/users/JuliaStats/following{/other_user}","gists_url":"https://api.github.com/users/JuliaStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaStats/subscriptions","organizations_url":"https://api.github.com/users/JuliaStats/orgs","repos_url":"https://api.github.com/users/JuliaStats/repos","events_url":"https://api.github.com/users/JuliaStats/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaStats/received_events","type":"Organization","site_admin":false},"repo":{"id":4490597,"node_id":"MDEwOlJlcG9zaXRvcnk0NDkwNTk3","name":"GLM.jl","full_name":"JuliaStats/GLM.jl","owner":{"login":"JuliaStats","id":2761531,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3NjE1MzE=","avatar_url":"https://avatars2.githubusercontent.com/u/2761531?v=4","gravatar_id":"","url":"https://api.github.com/users/JuliaStats","html_url":"https://github.com/JuliaStats","followers_url":"https://api.github.com/users/JuliaStats/followers","following_url":"https://api.github.com/users/JuliaStats/following{/other_user}","gists_url":"https://api.github.com/users/JuliaStats/gists{/gist_id}","starred_url":"https://api.github.com/users/JuliaStats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JuliaStats/subscriptions","organizations_url":"https://api.github.com/users/JuliaStats/orgs","repos_url":"https://api.github.com/users/JuliaStats/repos","events_url":"https://api.github.com/users/JuliaStats/events{/privacy}","received_events_url":"https://api.github.com/users/JuliaStats/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JuliaStats/GLM.jl","description":"Generalized linear models in Julia","fork":false,"url":"https://api.github.com/repos/JuliaStats/GLM.jl","forks_url":"https://api.github.com/repos/JuliaStats/GLM.jl/forks","keys_url":"https://api.github.com/repos/JuliaStats/GLM.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JuliaStats/GLM.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JuliaStats/GLM.jl/teams","hooks_url":"https://api.github.com/repos/JuliaStats/GLM.jl/hooks","issue_events_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/events{/number}","events_url":"https://api.github.com/repos/JuliaStats/GLM.jl/events","assignees_url":"https://api.github.com/repos/JuliaStats/GLM.jl/assignees{/user}","branches_url":"https://api.github.com/repos/JuliaStats/GLM.jl/branches{/branch}","tags_url":"https://api.github.com/repos/JuliaStats/GLM.jl/tags","blobs_url":"https://api.github.com/repos/JuliaStats/GLM.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JuliaStats/GLM.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JuliaStats/GLM.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/JuliaStats/GLM.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JuliaStats/GLM.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/JuliaStats/GLM.jl/languages","stargazers_url":"https://api.github.com/repos/JuliaStats/GLM.jl/stargazers","contributors_url":"https://api.github.com/repos/JuliaStats/GLM.jl/contributors","subscribers_url":"https://api.github.com/repos/JuliaStats/GLM.jl/subscribers","subscription_url":"https://api.github.com/repos/JuliaStats/GLM.jl/subscription","commits_url":"https://api.github.com/repos/JuliaStats/GLM.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/JuliaStats/GLM.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/JuliaStats/GLM.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/JuliaStats/GLM.jl/contents/{+path}","compare_url":"https://api.github.com/repos/JuliaStats/GLM.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JuliaStats/GLM.jl/merges","archive_url":"https://api.github.com/repos/JuliaStats/GLM.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JuliaStats/GLM.jl/downloads","issues_url":"https://api.github.com/repos/JuliaStats/GLM.jl/issues{/number}","pulls_url":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/JuliaStats/GLM.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/JuliaStats/GLM.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JuliaStats/GLM.jl/labels{/name}","releases_url":"https://api.github.com/repos/JuliaStats/GLM.jl/releases{/id}","deployments_url":"https://api.github.com/repos/JuliaStats/GLM.jl/deployments","created_at":"2012-05-30T03:30:46Z","updated_at":"2018-06-18T18:42:09Z","pushed_at":"2018-06-27T00:56:05Z","git_url":"git://github.com/JuliaStats/GLM.jl.git","ssh_url":"git@github.com:JuliaStats/GLM.jl.git","clone_url":"https://github.com/JuliaStats/GLM.jl.git","svn_url":"https://github.com/JuliaStats/GLM.jl","homepage":null,"size":595,"stargazers_count":181,"watchers_count":181,"language":"Julia","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":61,"mirror_url":null,"archived":false,"open_issues_count":28,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":61,"open_issues":28,"watchers":181,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238"},"html":{"href":"https://github.com/JuliaStats/GLM.jl/pull/238"},"issue":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/238"},"comments":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/issues/238/comments"},"review_comments":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238/comments"},"review_comment":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/pulls/238/commits"},"statuses":{"href":"https://api.github.com/repos/JuliaStats/GLM.jl/statuses/741dbb5a875b1d334bee5fc85977be4e33775897"}},"author_association":"NONE"}}
{"actor":{"display_login":"hung-q-ngo"}}