[R] doubt with integrate ()

From: Rogério Rosa da Silva <rogeriorosas_at_gmail.com>
Date: Sat 03 Jun 2006 - 04:52:14 EST


Dear members,

I'm getting an error with the "integrate" function. Searching in the r-help archives, I think this may have something to do with the function (it is not returning a vector but a number), but I don't see exactly what.

The function to integrate was defined with a for loop first:

    for (i in 1:(nbcol-1))
{tdon1<-tdon[,i]

    tdon11<-subset(tdon1,tdon1!="NA")
    fctk1<-function(x)
{density(tdon11, bandwidth=h[i], kernel="gaussian")$y}

    for (j in (i+1):nbcol)
{tdon2<-tdon[,j]

    tdon21<-subset(tdon2,tdon2!="NA")
    fctk2<-function(x)
{density(tdon21,bandwidth=h[j],kernel="gaussian")$y}

    diffctk<-function(x)
{abs(fctk1(x)-fctk2(x))}

    }}

    integrate(diffctk,-Inf,Inf,subdivisions=100)$integral ,

    where:
    h <- 1.06*ect*(nlc^-0.2); ect <- apply (data,2,sd); nlc <-length of each column in data, excluding NA's.

The result gives the error:

    "Error in integrate (diffctk, -Inf, Inf, subdivisions = 100) :

        evaluation of function gave a result of wrong length"

Is the any way finding these error? I would be happy to be enlightened.

With kind regards,

Rogério

        [[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 Received on Sat Jun 03 04:58:05 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 Sat 03 Jun 2006 - 06:10:30 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.