Hello everybody, i have the following function, which i want to solve for b i=1,..,n, and n is the length of t and t is the last element of t, if you do cumsum() before. (t_n*exp(-b*t_n)*sum_{i=1}^{n} f_i) / (1-exp(-b*t_n)) - (sum_{i=1}^{n} (f_i*(t_i*exp(-b*t_i)-t_{i-1}*exp(-b*t_{i-1}))) / (exp(-b*t_{i-1})-exp(-b*t_i)) ) = 0 i implemented this function in the following way ll2<-function(b,f,t) { t<-cumsum(t) tn<-t[length(t)] i<-seq(along=f) s1<-tn*exp(-b*tn)*sum(f[i]) s2<-(1-exp(-b*tn)) i[length(i)+1]<-0 i<-sort(i) f[length(f)+1]<-1 t[length(t)+1]<-0 t<-sort(t) s3<-f[2]*(t[2]*exp(-b*t[2])-t[1]*exp(-b*t[1])) s4<-exp(-b*t[1])-exp(-b*t[2]) i<-i[3:length(i)] s5<-sum(f[i]*(t[i]*exp(-b*t[i])-t[i-1]*exp(-b*t[i-1]))) s6<-sum(exp(-b*t[i-1])-exp(-b*t[i])) (s1/s2)-((s3/s4)+(s5/s6)) } # i have the given data f=c(1,1,1) t=c(320,14390,9000) # now i wanted to use optimize() to get the minimum of ll2() with the given data xmin<-optimize(ll2,c(0,10000),tol=0.001,f=f,t=t) and i got always the error "invalid "mode" of argument optimize", but i don't now what is really wrong? Or is there any mistake in my implementation of the function? best regards Andreas