我正在尝试进行累积分发。我知道matlab脚本要做,但我无法弄清楚如何在R
中做到这一点这是我的matlab代码:
[p2,xp2,up2] = ksdensity(X(:,2),xi,'Kernel','epanechnikov','function','cdf','Support',[m(2),M(2)]);
有什么想法吗?
答案 0 :(得分:0)
好吧,我设法用密度函数和一点点钱。以下是我想要的代码:
dens = density(X[,1], kernel = 'epanechnikov', from = m[1], to = M[1])
x = matrix(unlist(dens[1]))
y = matrix(unlist(dens[2]))
c1 <- cdf(x,y)
plot(x, c1)
cdf <- function(x,y) {
S <- matrix(0, length(y), 1)
S[1] <- y[1]
for(k in seq(2, length(y))) {
S[k] <- S[k-1] + y[k]
}
return(S)
}