[R] Error in integrate(integrand, 0, Inf) : non-finite function value
David Winsemius
dwinsemius at comcast.net
Sun Oct 21 08:17:26 CEST 2012
On Oct 20, 2012, at 8:01 PM, stats12 wrote:
> Hi,
>
> Thank you for your comment. I worked on the code again and was able to make
> it work.
Does that mean you know what value is "correct" for certain cases? Is there an overall strategy that is guiding this effort? I wrote earlier:
> DW> Your uncommented code seems to have problems with organization, but since you never really described
> DW> your overall strategy or [what the] goal was, it's hard to know.
I strongly suspect that is still the case. You are mixing applicative looping strategies with functional methods and it "looks wrong" to my eyes, but I have nothing to compare it to as far as goals.
> The only problem I am having right now is that nlm depends on the
> initial value.
> When the initial value is 1, I get the following estimates
> 0.1230414 19.6271029
>
> when it is 2, I get the following
> 29.46874 20.01679
>
>
>
> d<-matrix(c(1,1,0,0,0,0,0,0,2,1,0,0,1,1,0,1,2,2,1,0),nrow=10,ncol=2)
> h<-matrix(runif(20,0,1),10)
> delta<-matrix(c(2,1,0,1,0,1,0,0,2,1,0,0,1,1,1,1,0,2,1,0),nrow=10,ncol=2)
>
> out<-vector("numeric",length(1:2))
> integ<-vector("numeric",length(1:10))
>
> for (k in 1:2){
> ll<-function(p){
> cmh<-delta[,k]*(h[,k]*log(0.5))+p*log(gamma(1+1/p))
> for(s in 1:10){
> integrand<-function(x)
> x^d[s,k]*exp(-x*gamma(1+1/p))^p*p*x^(p-1)*exp(-x*h[s,k])
> integ<-integrate(integrand,0,Inf)$value
> return(integ)
> }
>
> lik<-sum(cmh+log(integ))
> -lik
> }
> initial<-c(1)
> t<-nlm(ll,initial)
> out[k]<-t$estimate
> }
>
> est<-as.vector(out)
---
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list