R - Error: argument 1 is not a vector when bootstrapping

R - Error: argument 1 is not a vector when bootstrapping

我正在尝试 bootstrap 我的数据以根据线性回归和 Theil 回归(mblm 函数 w/ repeated=FALSE)获得 2000 个测量值。

我的 bootstrap R 代码非常适合正常回归(据我所知),如下所示:

> fitfunc <- function(formula, data, index) {
+ d<- data[index,]
+ f<- lm(formula,data=d)
+ return(coef(f))
+ }

boot(dataframe, fitfunc, R=2000, formula=`Index A`~`Measurement B`)

但是我在尝试 Theil 估计器时遇到错误 bootstrap:

> fitfuncTheil <- function(formula,data,index) {
+ d<- data[index,]
+ f<- mblm(formula, data=d, repeated=FALSE)
+ return(coef(f))
+ }
> boot(dataframe, fitfuncTheil, R=2000, formula=`Index A`~`Measurement B`)

Error in order(x) : argument 1 is not a vector
    In addition: Warning message:
    In is.na(x) :

错误消息看起来很简单,但我不明白为什么这在一种情况下有效,而在另一种情况下无效。

从列名(在公式字段中引用)中删除 space 后,问题就解决了。