I was told to use Bayesian inference instead of working only analytically with polling data. However, I have a problem; I have a small dataset with guesses about prior distributions for the parties, and I have data from polls. How can I obtain marginals from Gibbs simulations?
prior <- a <- c(.30, .15, .15, .10, .10, .08, .12)
polls <- data.frame(rbind(
a <- c(.24, .23, .20, .11, .08, .08, .06, 3959, .02),
b <- c(.22, .22, .22, .11, .07, .08, .08, 1024, .03),
c <- c(.23, .25, .19, .11, .07, .08, .06, 2099, .02),
d <- c(.19, .27, .18, .10, .04, .08, .06, 1024, .03),
e <- c(.22, .30, .18, .09, .07, .08, .06, 1799, .02)
))
names(polls) <- c("Cons", "Lib", "Lab", "Ind", "Others", "Null", "Swingy",
"Sample.size", "Err")
You can build upon a Dirichlet distribution alpha priors. I didn't test it with your data, so, my answer ill be addressing only the conception.
# K = number of parties
# T = number of periods a:e, I guess
model {
for(t in 1:T){
y[t, 1:k] ~ dmulti(alpha[t, 1:k], N[t])
# Dirichlet priors on the paramenters
alpha[t, 1:k] ~ ddirch(theta[1:k])
N[t] <- sum(y[t,1:k])
# Sample size for dmulti based on observed data
# Inference probabilities
delta[t]<-step(alpha[t,2]-alpha[t,3])
}
for(i in 1:k){ #gamma prior for the alpha vector
theta[i] ~ dgamma(0,0.01) }
}