You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R语言Compind包ci_bod函数时遇列非数值错误的求助

使用Compind包ci_bod()函数构建BoD复合指标的数值型数据错误排查

问题场景

尝试用R语言Compind包的ci_bod()函数,通过Benefit of the Doubt(BoD)方法构建复合指标。输入数据为名为Data的tibble数据框,包含7个数值型子指标,数据示例如下:

Indic1        Indic2       Indic3       Indic4      Indic5       Indic6    Indic7
1 0.1310393914 -0.0688025494 0.0893357652 0.000000000 4.603536e-03 2.1277933 2.697052e-01
2 0.0573747901 -0.0800260705 0.3375335011 0.160919540 1.437293e-01 3.1103126 0.000000e+00
3 0.3430466905 -0.3456877394 0.1686795550 0.136363636 1.267847e-01 1.4737773 4.872327e-01

运行代码CI = ci_bod(Data)时触发错误:

Error in ci_bod(Data) : Data set not numeric at column: 1

已执行的验证操作

  1. 验证列类型,确认所有列均为数值型:
is.numeric(Data$Indic1)
# [1] TRUE
typeof(Data$Indic1)
# [1] "double"
class(Data$Indic1)
# [1] "numeric"
  1. 尝试先标准化指标,仍出现相同错误:
normalise_ci(Data,c(1:7),"POS", method=1, z.mean=0, z.std=1, ties.method ="average")
  1. 数据结构输出:
> str(Data)
tibble [3 × 7] (S3: tbl_df/tbl/data.frame)
 $ Indic1: num [1:3] 0.131 0.0574 0.343 
 $ Indic2: num [1:3] -0.0688 -0.08 -0.3457 
 $ Indic3: num [1:3] 0.08934 0.33753 0.16868 
 $ Indic4: num [1:3] 0 0.1609 0.1364 0.0976 
 $ Indic5: num [1:3] 0.0046 0.1437 0.1268 
 $ Indic6: num [1:3] 2.128 3.11 1.474 
 $ Indic7: num [1:3] 0.269705 0 0.487233

原因分析与解决方法

原因

ci_bod()函数内部的数值检查逻辑仅兼容基础data.frame类型,无法识别tibble(tbl_df)的类结构。尽管tibble的列是数值型,但函数会误判数据类型。

解决方法

将tibble转换为基础data.frame后传入函数:

# 转换tibble为基础data.frame
Data_df <- as.data.frame(Data)
# 运行ci_bod函数
CI <- ci_bod(Data_df)

若转换后仍有问题,可进一步检查:

  • 确认数据中无隐藏的非数值型元素(如字符型的NA)
  • 查看Compind包官方文档,确认函数输入的格式要求

内容的提问来源于stack exchange,提问作者Null

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 16:10:30