An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131120/67f6b88e/attachment.pl>
integrate
4 messages · dan wang, David Winsemius
On Nov 20, 2013, at 7:12 PM, dan wang wrote:
Hi all,
Can anyone help me with below integrate function?
Basically, I want to calculate the integral of the sum of two kernel
density functions.
But the error shows that:
In x - a :
longer object length is not a multiple of shorter object length
y1 = rnorm(10)
y2 = rnorm(10)
fhat <- function(x,a){h=density(a)$bw;sum(dnorm((x-a)/h)/h/length(a))}
integrand1 <- function(p) {
fhat(p,y1)+fhat(p,y2)
}
integrate(integrand1,lower = -Inf, upper = Inf)
So, .... where is "a"?
David Winsemius Alameda, CA, USA
On Nov 20, 2013, at 8:39 PM, David Winsemius wrote:
On Nov 20, 2013, at 7:12 PM, dan wang wrote:
Hi all,
Can anyone help me with below integrate function?
Basically, I want to calculate the integral of the sum of two kernel
density functions.
But the error shows that:
In x - a :
longer object length is not a multiple of shorter object length
y1 = rnorm(10)
y2 = rnorm(10)
fhat <- function(x,a){h=density(a)$bw;sum(dnorm((x-a)/h)/h/length(a))}
integrand1 <- function(p) {
fhat(p,y1)+fhat(p,y2)
}
integrate(integrand1,lower = -Inf, upper = Inf)
So, .... where is "a"?
Ignore that person. Try this: Vintegrand <- Vectorize(integrand1) integrate( Vintegrand, lower = -Inf, upper = Inf) #---------------- 2 with absolute error < 2.4e-05 David Winsemius Alameda, CA, USA
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20131121/dd2ff850/attachment.pl>