[R] All possible models with nls()

mael henriksson.anna at live.se
Thu Aug 23 17:19:38 CEST 2012


Hi all,

I am trying to make a script that prints all possible models from a model
I've created using nls(). It is a logisitc model which in total includes 13
variables. So its >8000 models I need to create, which I don't want to do
manually. I've tried modify scripts made for linear models with no results.

I've tried these scripts on a two variable model (c,a1 and a2 is what I want
to estimate here. Where c is a constant and a1 and a2 is a weight for x1 and
x2):

x1<-sample(0:1,50,replace=T)#explanatory var
x2<-sample(0:1,50,replace=T)#explanatory var
y<-sample(0:1,50,replace=T)#response
# first script I've tried
mod <- list()
for (i in 1:3) {
 	  mod[[i]] <- nls(y~exp(c+(a1*x1)+(a2*x2)
)/
(1+exp(c+(a1*x1)+(a2*x2)))
	,start=list(a1=-0.2,a2=-0.2,c=0.2))
 	  print(summary(mod[[i]]))
 	  }

#second script I've tried
regressors<-c("x1","x2")
regMat<-expand.grid(c(T,F),c(T,F))
regMat

allModelsList <- apply(regMat,1,
function(x)as.formula(nls(y~exp(c+(a1*x1)+(a2*x2)
)/
(1+exp(c+(a1*x1)+(a2*x2)))
	,start=list(a1=-0.2,a2=-0.2,c=0.2))))

allModelsList
allModelsResults <- lapply(allModelsList,
                           function(x) nls(x,
start=list(a1=-0.2,a2=-0.2,c=0.2)))
allModelsResults

They both give me the same models repeatedly, which is not what I wanted.
Any suggestions on how to do this? Please help.
Thanks!
Anna




--
View this message in context: http://r.789695.n4.nabble.com/All-possible-models-with-nls-tp4641105.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list