R

时间:2019-01-18 08:52:06

标签: r kernel-density cumulative-sum

我的任务是绘制渐近内核的累积分布函数。为此,我为Log-normal内核的cdf准备了以下R代码;但是我的问题是CDF图正在向下移动。使用内核作者(Lognormal kernel )提供的转换后。 请提供有关此问题的建议/更正。 R代码:

k <- 200
y <- c(306, 455, 210, 883, 310, 361, 218, 166, 170, 654, 728, 71, 567, 144, 613, 707, 61, 88, 301, 81, 624, 371, 394, 520, 574, 118, 390, 12, 473, 26, 533, 107, 53, 122, 814, 93,731, 460, 153, 433, 145, 583, 95, 303, 519, 643, 765, 735, 189, 53, 246, 689, 65, 5,132, 687, 345, 444, 223, 175, 60, 163, 65, 208, 428, 230, 305, 11, 132, 226, 426, 705,363, 11, 176, 791, 95, 167, 284, 641, 147, 163, 655, 239, 88, 245, 30, 179, 310, 477,166, 450, 364, 107, 177, 156, 11, 429, 351, 15, 181, 283, 201, 524, 13, 212, 524, 288, 363, 442, 199, 550, 54, 558, 207, 92, 60, 293, 202, 353, 267, 371, 387, 457, 337, 201, 222, 62, 353, 163, 31, 340, 229, 182, 156, 329, 291, 179, 268, 142, 194, 320, 181, 285,348, 197, 180, 186, 145, 350, 285, 110, 286, 270, 81, 131, 269, 135, 79, 59, 105, 239, 13, 183, 116)

n <- length(y)
h <- 0.79 * IQR(y) * length(y) ^ (-1/5)
x <- seq(min(y) + 0.05, max(y), length = k)
Fhat <- rep(0, k)
for (j in 1:k) {
for (i in 1:n) {
PhiLN <- matrix(rep(0, k * n), ncol = k)
PhiLN[i, j] <- pnorm((log(y[i])-log(x[j]))/(sqrt(4*log(1+h))))
}
Fhat[j] <- 1/n * (sum(PhiLN[, j]))
}
plot(x, Fhat, type = "l")

0 个答案:

没有答案