我有下列R-代碼:集研發功能錯誤
第一部分工作:
denSim <- function(n,nrow,ncol,v,ar) {
XX <- matrix(NA,nrow=nrow,ncol=ncol)
h1 <- h2 <- kknum <- kksum <- abc <- NULL
for(i in 1:n){
XX[,i] <- arima.sim(list(order=v,ar=ar), n=nrow)
h1[i]<-length(XX[,i])^(-1/5)
h2[i]<-sd(XX[,i])*h1[i]
kknum[[i]] <- exp(-0.5*((XX[nrow,i]-XX[,i])/bw.nrd0(XX[,i]))^2)
kksum[i]<-sum(kknum[[i]][-nrow])
abc[i]<- 1/(h2[i]*sqrt(2*pi))
}
Simls <- list(XX = XX,h1 = h1,h2=h2,kknum = kknum,kksum = kksum,abc = abc)
return(Simls)
}
Sim <- denSim(n=200,nrow=500,ncol=200,v=c(1,0,0),ar=0.6)
第二部分是不工作:
pdf <- function(z,i){
ABC <-Sim$abc[i]
Z <- z - Sim$XX[-1,i]
H2 <- Sim$h2[i]
eta <- ((Z)/H2)^2
KKN <- Sim$kknum[[i]][-500]
KKS <- Sim$kksum[i]
return(ABC*sum(KKN*exp(-0.5*eta))/KKS)
}
cdf <- function(i) integrate(pdf,0.6*mean(Sim$XX[,i]),20,i)$value
cdf(1)
是什麼問題?
它不工作怎麼辦?你有錯誤嗎?或者是你期望沒有發生的事情? – bnjmn