# Bayesian model averaging in R

I have a logistic model that I've built with the nls function in R. I want to use Bayesian model averaging for variable selection, but I can't find a package for that in R. Are there any suitable packages? If not, is it possible to make a not too complicated script for it?

Data example:

y<-sample(c(1,0),100,replace=T)

var1<-sample(c(1,0),100,replace=T)

var2<-sample(c(1,0),100,replace=T)

var3<-sample(c(1,0),100,replace=T)


The model:

Sw<- function(y1, N1,N2,N3) {

SA <- nls(y1~exp(c+(a1*N1)+(a2*N2)+(a3*N3))/(1+exp(c+(a1*N1)+(a2*N2)+(a3*N3)))
,start=list(a1=-0.2,a2=-0.2,a3=-0.2,c=0.2))
SA
}

model <- Sw(y, var1,var2,var3)


How would I do Bayesian model averaging on this? I have 190 observations, where about 70 are 1s and 120 are 0s. I have 13 variables in total.

-
cran.r-project.org/web/packages/BMA/index.html should help, i think. – richiemorrisroe Aug 22 '12 at 12:16
I don't know about whether there is any package that handles BMA, but if you have a script with MCMC for you Bayesian problem, that you can obtain marginal likelihoods (and consequentely to do BMA) by so called power posteriors: "Friel N, Pettitt AN. Marginal likelihood estimation via power posteriors. Journal of Royal Statistical Society: Series B (Statistical Methodology) 70, 589-607 (2008)" Also, the implementation of the method in this paper is not difficult by BUGS program. – Tomas Aug 22 '12 at 12:39
Model averaging of any flavor only makes sense if you have > 1 model - oh, so you have several runs of your function using different variables for N1, N2, and N3? – atiretoo Aug 22 '12 at 22:54
nls() isn't doing Bayesian estimation. If you're not needing a Bayesian perspective, you might check out package AICcmodavg. It doesn't work with nls objects, but perhaps could give you some ideas on how to do it by hand. Do you need Bayesian model averaging, or just plain ol' model averaging? – atiretoo Aug 22 '12 at 22:59
What is the purpose of your analysis? prediction of future data or inference about the structure in the data you have? If this is for prediction, penalisation/shrinkage is probably better. – probabilityislogic Aug 22 '12 at 23:32