{"action":"created","issue":{"url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1261","repository_url":"https://api.github.com/repos/pymc-devs/pymc3","labels_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1261/labels{/name}","comments_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1261/comments","events_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1261/events","html_url":"https://github.com/pymc-devs/pymc3/issues/1261","id":167644868,"number":1261,"title":"can't reproduce Bayesian Survival Analysis example","user":{"login":"DanielWeitzenfeld","id":834290,"avatar_url":"https://avatars.githubusercontent.com/u/834290?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielWeitzenfeld","html_url":"https://github.com/DanielWeitzenfeld","followers_url":"https://api.github.com/users/DanielWeitzenfeld/followers","following_url":"https://api.github.com/users/DanielWeitzenfeld/following{/other_user}","gists_url":"https://api.github.com/users/DanielWeitzenfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielWeitzenfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielWeitzenfeld/subscriptions","organizations_url":"https://api.github.com/users/DanielWeitzenfeld/orgs","repos_url":"https://api.github.com/users/DanielWeitzenfeld/repos","events_url":"https://api.github.com/users/DanielWeitzenfeld/events{/privacy}","received_events_url":"https://api.github.com/users/DanielWeitzenfeld/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-07-26T15:57:08Z","updated_at":"2016-07-26T20:37:23Z","closed_at":"2016-07-26T20:37:22Z","body":"I'm trying to reproduce the [Bayesian Survival Analysis](http://pymc-devs.github.io/pymc3/notebooks/survival_analysis.html#) example, but I'm getting nonsense results.\r\n\r\n@AustinRochford included a value for `random_seed`, so I don't think it's just randomness.\r\n\r\nHere is the code extracted from the example:\r\n\r\n```python\r\nimport numpy as np\r\nimport pymc3 as pm\r\nfrom pymc3.distributions.timeseries import GaussianRandomWalk\r\nimport seaborn as sns\r\nfrom statsmodels import datasets\r\nfrom theano import tensor as T\r\nfrom matplotlib import pyplot as plt\r\n\r\ndf = datasets.get_rdataset('mastectomy', 'HSAUR', cache=True).data\r\ndf.event = df.event.astype(np.int64)\r\ndf.metastized = (df.metastized == 'yes').astype(np.int64)\r\nn_patients = df.shape[0]\r\npatients = np.arange(n_patients)\r\n\r\ninterval_length = 3\r\ninterval_bounds = np.arange(0, df.time.max() + interval_length + 1, interval_length)\r\nn_intervals = interval_bounds.size - 1\r\nintervals = np.arange(n_intervals)\r\n\r\n\r\nlast_period = np.floor((df.time - 0.01) / interval_length).astype(int)\r\n\r\ndeath = np.zeros((n_patients, n_intervals))\r\ndeath[patients, last_period] = df.event\r\n\r\nexposure = np.greater_equal.outer(df.time, interval_bounds[:-1]) * interval_length\r\nexposure[patients, last_period] = df.time - interval_bounds[last_period]\r\n\r\nSEED = 5078864 # from random.org\r\n\r\nwith pm.Model() as model:\r\n\r\n    lambda0 = pm.Gamma('lambda0', 0.01, 0.01, shape=n_intervals)\r\n\r\n    beta = pm.Normal('beta', 0, sd=1000)\r\n\r\n    lambda_ = pm.Deterministic('lambda_', T.outer(T.exp(beta * df.metastized), lambda0))\r\n    mu = pm.Deterministic('mu', exposure * lambda_)\r\n\r\n    obs = pm.Poisson('obs', mu, observed=death)\r\n    \r\nn_samples = 1000\r\n\r\nwith model:\r\n    trace_ = pm.sample(n_samples,random_seed=SEED)\r\n\r\ntrace = trace_[100:]\r\n\r\nnp.exp(trace['beta'].mean())\r\n```\r\nOutput:\r\n```\r\nApplied log-transform to lambda0 and added transformed lambda0_log to model.\r\nAssigned NUTS to lambda0_log\r\nAssigned NUTS to beta\r\n [-----------------100%-----------------] 1000 of 1000 complete in 3.6 sec\r\nOut[8]:\r\n1.0\r\n```\r\n\r\nIn the example, the last line (`np.exp(trace['beta'].mean())`) returns `2.1839971003209597`.  I'm getting `1.0` because the trace for beta is always `1.0`.\r\n\r\nI'm using `pymc3` version `3.0`\r\n"},"comment":{"url":"https://api.github.com/repos/pymc-devs/pymc3/issues/comments/235397341","html_url":"https://github.com/pymc-devs/pymc3/issues/1261#issuecomment-235397341","issue_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1261","id":235397341,"user":{"login":"DanielWeitzenfeld","id":834290,"avatar_url":"https://avatars.githubusercontent.com/u/834290?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielWeitzenfeld","html_url":"https://github.com/DanielWeitzenfeld","followers_url":"https://api.github.com/users/DanielWeitzenfeld/followers","following_url":"https://api.github.com/users/DanielWeitzenfeld/following{/other_user}","gists_url":"https://api.github.com/users/DanielWeitzenfeld/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielWeitzenfeld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielWeitzenfeld/subscriptions","organizations_url":"https://api.github.com/users/DanielWeitzenfeld/orgs","repos_url":"https://api.github.com/users/DanielWeitzenfeld/repos","events_url":"https://api.github.com/users/DanielWeitzenfeld/events{/privacy}","received_events_url":"https://api.github.com/users/DanielWeitzenfeld/received_events","type":"User","site_admin":false},"created_at":"2016-07-26T20:37:22Z","updated_at":"2016-07-26T20:37:22Z","body":"I reinstalled pymc3 one more time and it's working now.  Sorry for the false alarm.  I'll check if this resolves https://github.com/pymc-devs/pymc3/issues/1254 as well"}}
{"actor":{"display_login":"DanielWeitzenfeld"}}