I am writing an R function that performs a Bayesian analysis to estimate a posterior density given an informed prior and data. I would like the function to send a warning if the user needs to reconsider the prior.
The following cases might require that the prior be re-evaluated:
- the data represents an extreme case that was not accounted for when stating the prior
- errors in data (e.g. if data is in units of g when the prior is in kg)
- the wrong prior was chosen from a set of available priors because of a bug in the code
In the first case, the priors are usuallystill diffuse enough that the data will generally overwhelm them unless the data values lie in an unsupported range (e.g. <0 for logN or Gamma). The other cases are bugs or errors.
- Are there any issues concerning the validity of using data to evaluate a prior?
- is any particular test best suited for this problem?
Here are two data sets that are poorly matched to a $logN(0,1)$ prior because they are from populations with either $N(0,5)$ (red) or $N(8,0.5)$ (blue).
The blue data could be a valid prior + data combination whereas the red data would require a prior distribution that is supported for negative values.
set.seed(1) x<- seq(0.01,15,by=0.1) plot(x, dlnorm(x), type = 'l', xlim = c(-15,15),xlab='',ylab='') points(rnorm(50,0,5),jitter(rep(0,50),factor =0.2), cex = 0.3, col = 'red') points(rnorm(50,8,0.5),jitter(rep(0,50),factor =0.4), cex = 0.3, col = 'blue')