# Re: [R] ifelse command

From: Carlos J. Gil Bellosta <cgb_at_datanalytics.com>
Date: Sun 23 Jul 2006 - 05:10:20 EST

Dear Xin,

Although I have no idea what your function does, I believe it would be "formally" correct in the following way:

foo <- function (parameters,y,x1,x2)
{

```	p <-parameters
alpha1<-parameters
beta1<-parameters
delta1<-parameters
alpha2<-parameters

mu<-alpha1*((x1)^beta1)*exp(-delta1*(x1^alpha2))

if(y>0 & x1>0 & x2==1) return( lgamma(y+p)+p*(log(p)-log(mu
+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p) )
if(y>0 & x1>0 & x2==2) return( lgamma(y+p)+p*(log(p)-log(mu
+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p) )
if(y>0 & x1>0 & x2==3) return( lgamma(y+p)+p*(log(p)-log(mu
```
+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p) )

return( "what then?" )
}

Sincerely,

Carlos J. Gil Bellosta
http://www.datanalytics.com
http://www.data-mining-blog.com

El sáb, 22-07-2006 a las 13:25 +0100, Xin escribió:
> Dear:
>
> I try to revise the maximum likelihood function below using something constrains. But it seems something wrong with it. Becasue R would not allow me to edit the function like this. It is very appreciate if you can help.
>
> function (parameters,y,x1,x2)
>
> {
>
> p<-parameters
>
> alpha1<-parameters
>
> beta1<-parameters[3)]
>
> delta1<-parameters
>
> alpha2<-parameters
>
> mu<-alpha1*((x1)^beta1)*exp(-delta1*(x1^alpha2))
>
> if(y>0 & 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
>
> if(y>0 & x1>0 & x2==2,
>
> L<-lgamma(y+p)+p*(log(p)-log(mu+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p)
>
> )
>
> else
>
> if(y>0 & x1>0 & x2==3,
>
> L<-lgamma(y+p)+p*(log(p)-log(mu+p))+y*(log(mu)-log(mu+p))-lfactorial(y)-lgamma(p)
>
> )
>
> else
>
> L
>
> }
>
> Thanks a lot!
>
> Xin Shi
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help