Search code examples
rstatistics-bootstrap

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


I'm attempting to bootstrap my data to get 2000 measurements based on the linear regression and Theil regression (mblm function w/ repeated=FALSE).

My bootstrap R code works perfectly for the normal regression (from what I can tell), given below:

> 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`)

But I get an error when attempting the Theil estimator 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) :

The error message seems basic but I cannot figure out why this would work in one case but not the other.


Solution

  • Once I removed the space from the column names (referenced in the formula field), the issue was resolved.