Xin
2006-Jul-22 14:59 UTC
[R] Why the contrain does not work for selecting a particular range of data?
Dear: Continuing the issue of 'ifelse'! I selecting the data whose 'x2'=1 for maximizing likelihood. I used two way to do this but the results are different. 1.Way one I use the data for x2=1 and run the program. It works for me. Tthe program is described as below: function (parameters,y1,x11) { p<-parameters[1] alpha1<-parameters[2] beta1<-parameters[3] delta1<-parameters[4] lamda1<-parameters[5] mu<-alpha1*((x11)^beta1)*exp(-delta1*(x11^lamda1)) ifelse(y1>0|x11>0, L<-lgamma(y1+p)+p*(log(p)-log(mu+p))+y1*(log(mu)-log(mu+p))-lfactorial(y1)-lgamma(p) ,Inf) L } This is working for me. 2 Way two: I select the data whose x2=1 in the whole range of data. It works but it is not right comparing the value of MLE. the program is: function (parameters,y,x1,x2) { p<-parameters[1] alpha1<-parameters[2] beta1<-parameters[3] delta1<-parameters[4] alpha2<-parameters[5] mu<-alpha1*((x1)^beta1)*exp(-delta1*(x1^alpha2)) if(x1>0 & x2==1) { L<-lgamma(y+p)+p*(log(p)-log(mu+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p) } else L } The reason why I edit the program by the second way is I want to use one program for getting results of the different range of data. Anyone can help? Please! Thanks! Xin Shi [[alternative HTML version deleted]]
Xin
2006-Jul-23 08:07 UTC
[R] Why the contrain does not work for selecting a particular range of data?
Dear: Continuing the issue of 'ifelse'! I selecting the data whose 'x2'=1 for maximizing likelihood. I used two way to do this but the results are different. 1.Way one I use the data for x2=1 and run the program. It works for me. Tthe program is described as below: function (parameters,y1,x11) { p<-parameters[1] alpha1<-parameters[2] beta1<-parameters[3] delta1<-parameters[4] lamda1<-parameters[5] mu<-alpha1*((x11)^beta1)*exp(-delta1*(x11^lamda1)) ifelse(y1>0|x11>0, L<-lgamma(y1+p)+p*(log(p)-log(mu+p))+y1*(log(mu)-log(mu+p))-lfactorial(y1)-lgamma(p) ,Inf) L } This is working for me. 2 Way two: I select the data whose x2=1 in the whole range of data. It works but it is not right comparing the value of MLE. the program is: function (parameters,y,x1,x2) { p<-parameters[1] alpha1<-parameters[2] beta1<-parameters[3] delta1<-parameters[4] alpha2<-parameters[5] mu<-alpha1*((x1)^beta1)*exp(-delta1*(x1^alpha2)) if(x1>0 & x2==1) { L<-lgamma(y+p)+p*(log(p)-log(mu+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p) } L } The reason why I edit the program by the second way is I want to use one program for getting results of the different range of data. Anyone can help? Please! Thanks! Xin Shi My Estimation function for way two is : function (parameters, y, x1,x2) { nx1 <- length(x1); nx2 <- length(x2); ny <- length(y); x1 <- matrix(x1,nrow=nx1,ncol=1); x2 <- matrix(x2,nrow=nx2,ncol=1); y <- matrix(y,nrow=ny,ncol=1); ##Likelihood ##---------- Lvec <- matrix(0,nrow=nx1,ncol=1) for (i in 1:ny) { Lvec[i] <- nb_L3(parameters, y[i],x1[i],x2[i]) LL <- -sum(Lvec) } LL } [[alternative HTML version deleted]]