2
$\begingroup$

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)
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – gung - Reinstate Monica Feb 17 '14 at 4:28
  • $\begingroup$ 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) $\endgroup$ – user40395 Feb 17 '14 at 4:34
  • $\begingroup$ I'm not sure I follow your code. What do you want it to accomplish? $\endgroup$ – gung - Reinstate Monica Feb 17 '14 at 4:58
  • $\begingroup$ 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 $\endgroup$ – user40395 Feb 17 '14 at 5:01
  • $\begingroup$ Note that questions about 'how do I do _____ in R?', or 'what's wrong w/ my r code?' belong on Stack Overflow, not here. Note further that our approach to HW questions is to provide hints only (see the [self-study] tag's wiki). 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. $\endgroup$ – gung - Reinstate Monica Feb 17 '14 at 5:09
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ You're welcome, @C.Thurman. You can ask for further hints if this doesn't get you over the hump. $\endgroup$ – gung - Reinstate Monica Feb 17 '14 at 5:22
  • $\begingroup$ hey @gung not sure if you are online, but I'm still slightly confused. If you have any further hints that would be great $\endgroup$ – user40395 Feb 18 '14 at 3:51
  • $\begingroup$ What have you come to understand & what are you still stuck on, @C.Thurman? $\endgroup$ – gung - Reinstate Monica Feb 18 '14 at 3:52
  • $\begingroup$ 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 $\endgroup$ – user40395 Feb 18 '14 at 3:58
  • $\begingroup$ 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? $\endgroup$ – gung - Reinstate Monica Feb 18 '14 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy