2

I have a Bayesian statistics homework question that I'm not sure of:

Running this in R, I got completely flat lines at 0 and 1 so I was thinking this meant that the success probability does not change with this particular prior. Can anyone shed some more light on this problem?

mu0    = 0 
sig2_0 = 100 
n      = 10000 
b0     = rnorm(n, mean=mu0, sd=sqrt(sig2_0)) 
x      = seq(from=0, to=10, length.out=100) 
res    = matrix(0, length(x), 3) 
for(i in 1:length(x)){ 
  z       = b0 
  z1      = exp(z) / (1+exp(z)) 
  res[i,] = quantile(z1, c(0.025, 0.5, 0.975)) 
} 

plot( x, res[,2], type='l', ylim=range(res), ylab='Success probability', xlab='Covariate') 
lines(x, res[,1], lty=3) 
lines(x, res[,3], lty=3)
  • I'm not sure I follow your comment about getting flat lines at 0 & 1 when you ran it in R. Can you add the figure to your question, or include your code? – gung - Reinstate Monica Feb 17 '14 at 04:28
  • sure @gung This is the code we were given to work with in class (I edited it to fit this particular problem...I hope it's right) `mu0=0 sig2_0=100 n=10000 b0=rnorm(n,mean=mu0,sd=sqrt(sig2_0)) x=seq(from=0,to=10,length.out=100) res=matrix(0,length(x),3) for (i in 1:length(x)){ z=b0 z1=exp(z)/(1+exp(z)) res[i,]=quantile(z1,c(0.025,0.5,0.975)) } plot(x,res[,2],type='l',ylim=range(res),ylab='Success probability',xlab='Covariate') lines(x,res[,1],lty=3) lines(x,res[,3],lty=3)` –  Feb 17 '14 at 04:34
  • I'm not sure I follow your code. What do you want it to accomplish? – gung - Reinstate Monica Feb 17 '14 at 04:58
  • This particular code was meant to "show how the success probability varies as a function of our covariate and, at the same time, show the 95% interval for this relationship." Honestly I'm not 100% sure this is all we were given to work with from the notes I took in class. I'm not even sure if you need R to solve this problem @gung –  Feb 17 '14 at 05:01
  • Note that questions about 'how do I do `_____` in R?', or 'what's wrong w/ my r code?' belong on [Stack Overflow](http://stackoverflow.com/), not here. Note further that our approach to HW questions is to provide hints *only* (see the `[self-study]` tag's [wiki](http://stats.stackexchange.com/tags/self-study/info)). Since I think there is a legitimate statistical question here, I provided hints below. There are also some issues w/ your code, however. 1st, your code doesn't include any covariates. 2nd you generate your pseudorandom data in line 4; each pass through the loop uses the same data. – gung - Reinstate Monica Feb 17 '14 at 05:09
  • Sorry I'm new to this, but this wasn't a question on whether my R code was right or not. I wasn't sure how to solve the problem, and I thought possibly this R code that my professor showed me in class might be the way to do it (obviously it isn't). I was merely wondering what the best way to go about starting to answer this question was, and I was only asking for hints not a flat out answer. I apologize for any confusion @gung –  Feb 17 '14 at 05:14
  • There's no need to apologize, that was just FYI. (You may want to take our [tour](http://stats.stackexchange.com/about) to learn a little bit more about CV.) I think the code, in its present form, will not help you. The hints below should get you started, though. – gung - Reinstate Monica Feb 17 '14 at 05:17

1 Answers1

1

For some initial hints, consider a logistic regression in a non-Bayesian context. If the true $B_0$ in some situation were $0$, what would the probability of success be when all $X$ variables were $0$? Note that $B_0$ is on the logit scale, so you have to convert this into a probability.

Now, if your prior for $B_0$ were centered on $0$, that implies that in some sense (n.b., there are different positions on what Bayesian priors are supposed to mean) you believe the true value of $B_0=0$ (or at least did, before seeing your data).

The width of a prior represents your certainty about your prior belief, with wider priors implying greater uncertainty. The posterior can be understood (very loosely) as a weighted average of your prior and what your data tell you, with the weights being proportional to the width of your prior. So the result / mean of your posterior for $B_0$ will be partway between $0$ and what the data suggest, being closer to $0$ the narrower your prior and closer to what the data suggest the wider your prior.

gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
  • You're welcome, @C.Thurman. You can ask for further hints if this doesn't get you over the hump. – gung - Reinstate Monica Feb 17 '14 at 05:22
  • hey @gung not sure if you are online, but I'm still slightly confused. If you have any further hints that would be great –  Feb 18 '14 at 03:51
  • What have you come to understand & what are you still stuck on, @C.Thurman? – gung - Reinstate Monica Feb 18 '14 at 03:52
  • Honestly I'm so lost, I think I understand that since my width of my prior is large it shows greater uncertainty (vague). I'm still not seeing the relation to the success probability @gung –  Feb 18 '14 at 03:58
  • Start w/ the 1st paragraph of my answer above. In a non-Bayesian setting, the true value of $B_0$ is $0$. Note that this is on the log odds scale. Can you convert this into a probability? – gung - Reinstate Monica Feb 18 '14 at 04:00
  • Wouldn't it just be 1? –  Feb 18 '14 at 04:06
  • No, it isn't 1. Try reading my answer here: [interpretation of simple predictions to odds ratios in logistic regression](http://stats.stackexchange.com/questions/34636//34638#34638). – gung - Reinstate Monica Feb 18 '14 at 04:09
  • I looked at it, and if I was supposed to use the equation you provided in the chat, I got 1/2. This was assuming the other coeffients were 0 as well. Again I'm not sure, math and I are not the best of friends @gung –  Feb 18 '14 at 04:18
  • So if the answer is 1/2, then what is the probability of success when all covariates =0? Moreover, if your prior is centered on 0, what do you believe the probability of success is when all covariates =0? & so, "What does this prior imply in relation to the success probability π?" – gung - Reinstate Monica Feb 18 '14 at 04:27
  • SO does this imply that the success probability of this prior is 50% (so it falls directly between 0 and 100)? –  Feb 18 '14 at 04:32
  • It does seem like 1/2=50%, which falls between 0% & 100%. – gung - Reinstate Monica Feb 18 '14 at 04:35
  • hmmm okay @gung –  Feb 18 '14 at 04:37
  • sorry to bother you again, but looking again at the data...if the prior is zero wouldn't that just mean that the data would not transform and the success probability would also be centered on zero? @gung –  Feb 20 '14 at 03:29
  • $B_0=0$ is on the log odds scale. Try converting it into a probability & see if it ends up equaling 0. – gung - Reinstate Monica Feb 20 '14 at 03:46
  • okay nwm .5 was correct the first time @gung –  Feb 20 '14 at 03:49