请有人帮我解决这个错误信息吗?

问题描述

我正在尝试使用 R 计算 Maxent 模型的真实技能统计 (TSS)。我正在执行我在互联网上找到的脚本,但收到此错误消息:

Error in `$<-.data.frame`(`*tmP*`,"variable",value = character(0)) : replacement has 0 rows,data has 11

有人可以帮我解决这个问题吗?谢谢 !我把我的脚本包括在这里

#### libraries ####
library("reshape2")
library("plyr")
library("reshape")


##### Directory ####
# Root directory #
dir <- c('C:\\Users\\johan\\Documents\\projects\\2021_Dryophytes_immaculatus_review\\range_study\\')

# output directory
all_out <- paste0(dir,'results_n147_12_variables_10replicates_20randoms_without_threshold\\')


#### tss function ####
calc_tss<-function( samples,background,threshold ){
  sensitivity <- sum( samples$predict >= threshold ) / nrow( samples )
  specificity <- sum( background$predict < threshold ) / nrow( background )
  sensitivity + specificity - 1
}


#### Extract MaxSSS threshold values ####
# Create an empty vector
s_thresh_df <- list()

# For-loop
for(run in 1:4){
  # Read CSV file of maxent results (generated by maxent earlier)
  res_df <- read.csv(paste0("C:\\Users\\johan\\Documents\\projects\\2021_Dryophytes_immaculatus_review\\range_study\\results_n147_12_variables_10replicates_20randoms_without_threshold\\maxentResults.csv"),header=TRUE)
  # Select only logistic threshold values and invert the table
  thresh_df <- res_df[,c(grep("logistic.threshold",names(res_df)))]
  thresh_df$id <- 1:nrow(thresh_df)
  thresh_df <- melt(thresh_df,id.vars=c("id"))
  # Add a column to indicate corresponding run within the table
  thresh_df <- data.frame(run,thresh_df)
  thresh_df$run <- run
  # Clean up text within rows and rename column
  thresh_df$variable <- gsub(".logistic.threshold","",thresh_df$variable)
  thresh_df <- rename(thresh_df,c("variable"="threshold"))
  # Add to List
  s_thresh_df[[run]] <- thresh_df
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)