我们如何解决错误? bca中的错误(f = ...:找不到函数“ bca”

时间:2018-11-15 08:35:41

标签: r

我正在使用“ dst”包(第10,11页:两个质量函数的组合),当我编写一个小示例时,它可以正确运行。但是我写了一个大函数,它会发生这个错误:

Error in bca(f = matrix(c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  : 
  could not find function "bca"

我的功能是: 会出错:

library("dst")

x43 <- bca(f=matrix(c(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
,nrow=23, byrow = TRUE),
m=c(0.02927918,0.03578567,0.01254822,0.04391877,0.06831808,0.06831808,0.05437561,
0.06831808,0.11711670,0.03578566,0.04387215,0.02927918,0.03575976,0.06839579,
0.02927918,0.06839579,0.02927918,0.01585178,0.02396417,0.01953500,0.04405864,0.02927918,0.02927918),
cnames=c("i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8", "i9", "i10", "i11", "i12", "i13", "i14",
"i15", "i16", "i17", "i18", "i19", "i20", "i21", "i22", "i23"),
infovarnames = "x", varnb = 1)

错误:

Error in bca(f = matrix(c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, : could not find function "bca"

一个可以正常运行的小例子:

require("dst")
# Loading required package: dst

x25 <- bca(f=matrix(c(1,0,1,1),nrow=2, byrow = TRUE),
m=c(0.8,0.2), cnames=c("i1", "i2"),
infovarnames = "x", varnb = 1)

x26 <- bca(f=matrix(c(0,1,1,1),nrow=2, byrow = TRUE),

m=c(0.7,0.3), cnames=c("i1", "i2"),
infovarnames = "x", varnb = 1)

print ("combination of x25 and x26")

# [1] "combination of x25 and x26"
x25x26 <- dsrwon(x25,x26)
nzdsr(x25x26)

1 个答案:

答案 0 :(得分:0)

@ user2554330是正确的,请再次检查您的数据。 在bca函数中,参数m中的值必须加1,但在您的示例中,它们不能:

m=c(0.02927918,0.03578567,0.01254822,0.04391877,0.06831808,0.06831808,0.05437561, 0.06831808,0.11711670,0.03578566,0.04387215,0.02927918,0.03575976,0.06839579,   0.02927918,0.06839579,0.02927918,0.01585178,0.02396417,0.01953500,0.04405864,0.02927918,0.02927918)
sum(m)
[1] 0.999993