Sampler Exampler

x <- rnorm(10) #what's the mean of x? # i'm a sampler!! # try beta = 1 beta = 1 # get the probability of each observation given my model (i.e. "the data are normally distributed") and a parameter estimate ("beta = 1") p <- dnorm(x, mean = beta) # assuming the observations are independent, the probability of all of the data for a particular beta value is the probability of each observation multipled together PofD_B1 = prod(p) # try beta = 0 beta <- 0 p <- dnorm(x, mean = beta) PofD_B0 = prod(p) # beta = 0 looks better than beta = 1. I'll move to beta = 0 and keep looking around there. # try lots of betas! # this is a dumb sampler since it's just chugging through betas and not chosing them based on probability, but it demonstrates how this would reuslt in a likelihood distribution. betas <- seq(-2,2,.1) PofD_B <- 1:length(betas) for (i in 1:length(betas)) { beta <- betas[i] p <- dnorm(x, mean = beta) PofD_B[i] = prod(p) } results <- cbind(betas,PofD_B) plot(PofD_B~betas, type="l")

2 comments

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>