2017-05-30 63 views

回答

0

這不是我的代碼,你可以找到原來here

require(boot) 
xy <- data.frame(cbind(ts_a,ts_b)) 

# Bootstrap the Pearson correlation coefficient

pearson <- function(d,i=c(1:dim(xy)[1]){ 
     d2 <- d[i,] 
     return(cor(d2$ts_a,d2$ts_b)) 
    } 
bootcorr <- boot(data=xy,statistic=pearson,R=999) 
bootcorr 
#Making a result table for output using 95% BCa CI 
resultTable <- summary(bootcorr) 
resultTable <- cbind(resultTable , CI95pc = NA) 
for (i in 1:dim(resultTable)[1]) { 
##Extracting CI from boot.ci output 
    a <- boot.ci(bootcorr,index = i, conf=.95, type = 'bca')$bca[4:5] 
##Adding the CI to your output table 
    resultTable $CI95pc[i] <- paste(round(a[1],3),"-",round(a[2],3),sep=" ") 
    rm(a) 
} 
print(resultTable) 
+0

如果可能的話,請包括一些解釋爲什麼這個代碼可以幫助OP與他的問題。 – milo526