[R] Cannot calculate confidence intervals NULL

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Wed Nov 15 21:53:54 CET 2023


R-Experts,

Here below my R code working without error message but I don't get the results I am expecting.
Here is the result I get:

[1] "All values of t are equal to 0.28611928397257 \n Cannot calculate confidence intervals"
NULL

If someone knows how to solve my problem, really appreciate.
Best,
S


#########################################################
# Difference in Spearman rho 

library(boot)
 
x1=c(4,6,5,7,8,4,2,3,5.5,6.7,5.5,3.5,2,1,3,5,6,3.5,2.5,2,1,2,3,2,1,2,3,4,3,4)
 
y1=c(10,14,12.5,21,15,16,17.5,11,11.5,21,19,16,17.5,18,18.5,12,13,14,11,11,12,18,20,13,23,12,11,14,16,11)
 
x2=c(5,3,4,2,1,1,1,2,3,4,5,4,3,2,1,3,4.5,4.5,5.5,6,5,4,7,8,3,4,2,5,4,3)
 
y2=c(11,12,13,11,10,19,21,21,13,15,18,13,12,14,19,18.5,17.5,12.5,10,9,11,13,14,16,11,18,14,13,12,12)
 
# Function to calculate the difference in Spearman coefficients
pearson_diff <- function(data, indices) {
 
# Sample the data
  d <- data[indices, ]
 
 # Calculate the Spearman correlation coefficients for every sample
  cor1 <- cor(x1, y1, method="spearman")
  cor2 <- cor(x2, y2, method="spearman")
 
# Return the difference
  return(cor1 - cor2)
}
 
# Create a data.frame with the data
data <- data.frame(x1, y1, x2, y2)
 
# Use the boot function to apply the bootstrap
set.seed(123) # For reproducibility
bootstrap_results <- boot(data = data, statistic = pearson_diff, R = 1000)
 
# Calculate all the 95% confidence interval
boot.ci(bootstrap_results, type = "all")
###############################################################
 



More information about the R-help mailing list