如何计算R中三个核密度函数积的积分?

时间:2015-04-07 16:21:25

标签: r integral kernel-density

我想计算三个核密度函数的乘积。为了做到这一点,在找到内核密度后,我应该找到它们的乘积的近似函数,然后计算积分(具有参数上限)。请参阅下面的代码,这给了我一个错误。我认为在计算近似函数或积分部分时应该存在问题。

library(ks)
library(rgl)

zz <- " longitude  latitude       depth      time       magnitude
       277.728371  139.925845  0.75103658  26.40786514 0.943718276
       426.087586  168.903095  0.2957441   0.241456485 0.759137864
       331.549444  74.168092   0.55140397  66.51363095 0.776176433
       93.078983   78.588053   0.15328453  104.9418546 0.834896464
       492.359229  11.082291   0.08173915  111.3391451 0.874798119
       86.85704    42.34973    0.23081904  152.8098572 0.878111793
       128.038949  73.935782   0.66160123  157.8933315 0.990100773
       295.300125  1.935765    0.49789785  159.9134319 0.842815655
       294.688309  1.024583    0.44789667  165.7092358 0.886545275
       221.246937  151.217171  0.6337224   167.6213491 0.885163617
       111.240376  156.04214   0.55752237  171.2039395 0.885273526
       25.929383   136.975153  0.0271747   172.6574772 0.812214826
       415.726989  158.482975  0.37340509  184.3767148 0.90837174
       73.921877   60.031908   0.15224511  189.6429637 0.791403228
       8.811256    124.676545  0.26806101  193.7498013 0.813638308"

x <- read.table(text=zz, header = TRUE)
y1 <- x[,1:3]
y2<- x[ ,4]
y3<- x[ ,5]
fhat1 <- kde(x=y1)
fhat2 <- kde(x=y2)
fhat3 <- kde(x=y3)

integrand <- function(p){fhat1(p,y1)* fhat2(p,y2)* fhat3(p,y3)}
Vintegrand <- Vectorize(integrand)
integrate(Vintegrand, lower = 0, upper = t)

0 个答案:

没有答案