It really helped with a nerdy little procrastination project, trying to work out the likelihood and risk of me failing my exams based on past papers I've done.

You explained the topic with a clarity and depth that I haven't found elsewhere so far

Keep up the good work! ]]>

The last time I was in Statistics class was about 5 years ago now and I am pretty rusty on the concepts. I might have to double back and see if I can't brush up on them, but I have officially become more verbose in Python (took me long enough right?) so my hope is that with a better understanding of statistics I might be able to better follow along in your code examples in your later blog posts.

This is awesome stuff though man, I will keep reading!

]]>However I copied it, all run correctly, but I do not obtain the graphs.

See my code here:

library(ggplot2)

m = 0.5

n = 100

N_samp = 500

Y_samp = 500

### Function: Prior Plot Values

prior <- function(m,n){

a = n * m

b = n * (1 - m)

dom <- seq(0,1,0.005)

val <- dbeta(dom,a,b)

return(data.frame('x'=dom, 'y'=val))

}

### Function: Likelihood Plot Values

likelihood <- function(N,Y){

a <- Y + 1

b <- N - Y + 1

dom <- seq(0,1,0.005)

val <- dbeta(dom,a,b)

return(data.frame('x'=dom, 'y'=val))

}

### Function: Posterior Plot Values

posterior <- function(m,n,N,Y){

a <- Y + (n*m) -1

b <- N - Y + (n*(1-m)) - 1

dom <- seq(0,1,0.005)

val <- dbeta(dom,a,b)

return(data.frame('x'=dom, 'y'=val))

}

### Function: Mean of Posterior Beta

mean_of_posterior <- function(m,n,N,Y){

a <- Y + (n*m) -1

b <- N - Y + (n*(1-m)) - 1

E_posterior <- a / (a + b)

return(E_posterior)

}

### Function: Mode of Posterior Beta

mode_of_posterior <- function(m,n,N,Y){

a <- Y + (n*m) -1

b <- N - Y + (n*(1-m)) - 1

mode_posterior <- (a-1)/(a+b-2)

return(mode_posterior)

}

### Function: Std Dev of Posterior Beta

sd_of_posterior <- function(m,n,N,Y){

a <- Y + (n*m) -1

b <- N - Y + (n*(1-m)) - 1

sigma_posterior <- sqrt((a*b)/(((a+b)^2)*(a+b+1)))

return(sigma_posterior)

}

pr <- prior(m,n)

lk <- likelihood(N_samp,Y_samp)

po <- posterior(m,n,N_samp,Y_samp)

model_plot <- data.frame('Dist'=c(rep('Prior',nrow(pr)),

rep('Likelihood',nrow(lk)),

rep('Posterior',nrow(po))),

rbind(pr,lk,po))

with(model_plot, Dist <- factor(Dist, levels = c('Prior', 'Likelihood',

'Posterior'), ordered = TRUE))

mean_po <- mean_of_posterior(m,n,N_samp,Y_samp)

mode_po <- mode_of_posterior(m,n,N_samp,Y_samp)

sd_po <- sd_of_posterior(m,n,N_samp,Y_samp)

Thanks for the very detailed illustration you have described in this page. I have tried to use your code and replicate the charts (I'm loading ggplot2), but without success.

I have tested that ggplot2 is otherwise working well. It is. To avoid confusion, I have also copied all the different piece of your code into a single R script document and sourcing it.

Your feedback / help would help tremendously.

]]>In your reply Dec 11, 2012: "...I'm really interested in the spatial and spatial-temporal modeling techniques, especially in the bayesian framework, like these...". The link corresponding to "these" does not seem to work? Secondly, did you try the spBayes package as you had stated? Thanks and Regards...

]]>