[R] Optim Problem

Christopher Kelvin chris_kelvin2001 at yahoo.com
Tue Aug 28 03:12:54 CEST 2012


Hello,
I want to estimate the exponential parameter by using optim with the following input, where t contains 40% of the data and q contains 60% of the data within an interval. In implementing the code command for optim i want it to contain both the t and q data so i can obtain the correct estimate. Is there any suggestion as to how this can be done. I have tried h<-c(t,q) but it is not working because q lies within an interval.

rate<-15;n<-100;a<-40;b<-60;rr<-1000
ms11=ms22=0
bia11=bia22=0
t<-rexp(a,rate)
for(i in 1:rr){
C1<-runif(b,0,rate)
C2<-rexp(b,rate)
f2 <- function(C1, C2) {
  r <- pmax(C1 , C2 + C1)
  cbind(C1, r)
} 
m<-f2(C1,C2)
x[1:b]<-(m[,1])
u<-x[1:b]
x[1:b]<-(m[,2])
v<-x[1:b]
q<-cbind(u,v)

h<-c(t,q)

z<-function(data ){ 
rate<-p[2]
log1<--(n/log(p[2]))-sum(t/(p[2]))+sum(log(exp(-(u/(p[2])))-exp(-(v/(p[2])))))
return(-log1)
}
}
start <- c(1,1)
zz<-optim(start,fn=z,data=h,hessian=T)
m1<-zz$par[2]

thank you

chris b guure
researcher
institute for mathematical research 
upm  




More information about the R-help mailing list