From jechacon@unex.es  Fri Jun 28 12:53:06 2002
From: jechacon@unex.es (jechacon@unex.es)
Date: Fri, 28 Jun 2002 13:53:06 +0200 (MET DST)
Subject: integrate function fails! (PR#1718)
Message-ID: <200206281153.NAA11196@pubhealth.ku.dk>

Full_Name: Jos Enrique Chacn
Version: 1.5.0 and 1.3.1
OS: Windows Millenium
Submission from: (NULL) (158.49.28.155)


Dear reader:
I was trying to evaluate the L2 error produced when estimating the density
function N(0,1) from a sample of size 100 using a kernel density estimate. It
produced a strange value. You can reproduce the process by typing

samp<-rnorm(100)
fker<-function(x,h){sum(dnorm((rep(x,100)-samp)/h))/(100*h)}
integrand<-function(x){(fker(x,5)-dnorm(x))^2}
err<-integrate(integrand,-Inf,Inf)

This value err of the L2 error is generally far from accurate. fker is the
kernel density estimate with bandwidth h and Gaussian kernel. Obviously, h=5 is
a very large choice far from the optimum which is around 0.4, but it makes it
more clear to see the failure. You just have to evaluate integrand(0); then, you
know that the integral between -0.5 and 0.5 cannot be larger than integrand(0),
which was usually around 0.1. But the value that integrate gives is around 1.6!
Anyway, there is a library called rmutil (I don't remember where I got it, but I
found it searching in the forums) which contains a function called int that
works well.

I hope this problem can be solved.

Best regards,
  Jos Enrique Chacn

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


integrate function fails! (PR#1718)
jechacon@unex.es