错误:“关闭”类型的对象不可保留?

时间:2019-02-12 10:32:40

标签: r

我尝试计算矩阵的元素,我规范地编写了元素,但是当我运行它时,我收到了以下错误消息:

I[1,1] <- ((1/n)*sum(delta*(((1/alp)-h(x)-(M(x)/(1-W(x))))^2)))
  

I [1,1]中的错误<-((1 / n)* sum(delta *(((1 / alp)-h(x)-(M(x)/(1-):   类型为'closure'的对象不可子集

I[2,2] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))
  

I [2,2]中的错误<-((1 / n)* sum(delta *(((1 / b)+ log(A(x))-R(x)))^ 2)) :   类型为'closure'的对象不可子集

I[3,3] <- ((1/n)*sum(delta*(((1/d)-(x^gam)-T(x)+((x^gam)))/((((1-exp(-d*x^gam)))*B(x))^2))))
  

I [3,3]中的错误<-((1 / n)* sum(delta *(((1 / d)-(x ^ gam)-T(x)+((x ^ gam)) )/(((((((1-Â:'closure'类型的对象不可子集化

I[4,4] <- ((1/n)*sum(delta*((1/gam)+log(x)-(d*(x^gam)*log(x))*D(x)-((d*(x^gam)*log(x)*exp(-d*x^gam))/(1-exp(-d*x^gam)))*N(x))^2))
  

I [4,4]中的错误<-((1 / n)* sum(delta *((1/1 / gam)+ log(x)-(d *(x ^ gam))*:类型为'封闭”不可子集化


我不确定为什么在代码中什么都没改变。

1 个答案:

答案 0 :(得分:2)

I()是禁止表达式解释的功能。尽管如此,它可以绑定到一个矩阵值,但是我的猜测(由于缺乏上下文)是您没有将矩阵分配给I而是分配给了其他东西:

> n = 10
> b = 20
> A = function(x) {x+1}
> R = function(x) {x*2}
> delta = 20
> x = 4
> I[1,1] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))
Error in I[1, 1] <- ((1/n) * sum(delta * (((1/b) + log(A(x)) - R(x)))^2)) :
  object of type 'closure' is not subsettable
> I
function (x)
{
    structure(x, class = unique(c("AsIs", oldClass(x))))
}
<bytecode: 0x2fdae80>
<environment: namespace:base>
> I = matrix(c(1,2,3,4), nrow=2)
> I[1,1] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))
> I
         [,1] [,2]
[1,] 80.40546    3
[2,]  2.00000    4