Thanks for your help, what I meant was that each observation x had a corresponding count to them, and I wanted to use these counts as weights in the optim (so that the optim process would give more weight to the measurements that had more counts).
I had forgotten if the weights should accounted for in the ypred formula, or in the sum of squares as you mentioned. On Fri, Sep 23, 2011 at 3:10 PM, Rolf Turner <rolf.tur...@xtra.co.nz> wrote: > > > I'm not at all sure that I understand your question, but since (as far > as I am aware) no-one else has answered, I'll give it a go. > > The puzzle, to me, is what you mean by ``I would like to add weights > to optim.'' What do you mean ``add weights''? > > If you want to minimize a weighted sum of squares, it seems to me to > be trivial: > > logis.op <- function(p,x,y,w=1) { > > ypred <- 1.0 / (1.0 + exp((p[1] - x) / p[2])); > sum(w*(y-ypred)^2) > } > > (Note that your ``res <- ...'' and ``return(res)'' are unnecessary.) > > optim(c(0.0,1.0),logis.op,x=**d1_all$SOA,y=as.numeric(md1[,**i]), > w=<whatever weights you had in > mind>) > > HTH > > cheers, > > Rolf Turner > > > > On 23/09/11 13:47, Ahnate Lim wrote: > >> I realize this may be more of a math question. I have the following optim: >> >> optim(c(0.0,1.0),logis.op,x=**d1_all$SOA,y=as.numeric(md1[,**i])) >> >> which uses the following function: >> >> logis.op<- function(p,x,y) { >> >> ypred<- 1.0 / (1.0 + exp((p[1] - x) / p[2])); >> >> res<- sum((y-ypred)^2) >> >> return(res) >> >> } >> >> I would like to add weights to the optim. Do I have to alter the logis.op >> function by adding an additional weights parameter? And if so, how would I >> change the ypred formula? Would I just substitute x with x*w >> > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.