[R] Why the contrain does not work for selecting a particular range of data?

From: Xin <jasonshi510_at_hotmail.com>
Date: Sun 23 Jul 2006 - 18:07:17 EST


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]]



R-help@stat.math.ethz.ch 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. Received on Sun Jul 23 18:12:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 24 Jul 2006 - 00:17:33 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.