[R] Pasting a list of parameters into a function
bsm2
bsm2 at rice.edu
Thu Jan 24 17:01:37 CET 2013
I'm still having trouble, I think that I may have poorly explained the
problem I'm running into.
The code I'm working with looks like this:
mle.nb<-function(l,a,b,s){
t1pred=(data$T*l)/(1+a*data$T)^b
-sum(dnbinom(x=data$T.1, mu=t1pred, size=s,log=TRUE))
}
fit.mle.nb=mle2(mle.nb, start=list(l=2, a=1, b=1, s=1), method =
"Nelder-Mead",control = list(maxit = 50000))
I'm trying to iterate model fits while holding one variable (l,a,b or s)
constant. In order to do this, each time I need to re-run the mle2 fit with
one variable held constant, for example:
l=1
mle.nb<-function(a,b,s){
t1pred=(data$T*l)/(1+a*data$T)^b
-sum(dnbinom(x=data$T.1, mu=t1pred, size=s,log=TRUE))
}
fit.mle.nb=mle2(mle.nb, start=list(a=1, b=1, s=1), method =
"Nelder-Mead",control = list(maxit = 50000))
I would like to be able to rewrite this code as something like:
q<-("l,a,b,s") #or something like this, I'm not sure if this should be
formatted as a data frame or something else
mle.nb<-function(q){
t1pred=(data$T*l)/(1+a*data$T)^b
-sum(dnbinom(x=data$T.1, mu=t1pred, size=s,log=TRUE))
}
fit.mle.nb=mle2(mle.nb, start=list(a=1, b=1, s=1), method =
"Nelder-Mead",control = list(maxit = 50000))
####
I tried the previously suggested solutions and couldn't get them to work. I
apologize if I'm being dense!
--
View this message in context: http://r.789695.n4.nabble.com/Pasting-a-list-of-parameters-into-a-function-tp4656445p4656521.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list