0

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.

Shawn
  • 353
  • 1
  • 14
  • Do you have a `factor` anywhere? Since `is.vector(factor(1:3))` returns `FALSE` What is the result of `data[index,]` too - should you be doing `data[index,,drop=FALSE]`? Just some common catches that R might throw at you. – thelatemail Mar 06 '18 at 01:27
  • @thelatemail based on the formula, there have to be at least two columns in the data. So, it doesn't seem `drop = FALSE` is required? – kangaroo_cliff Mar 06 '18 at 02:34
  • @Suren - you're right. Still, there could be something going wrong with `data[index,]` subsetting that is breaking things. It's hard to nail something down without example data so I was just guessing. – thelatemail Mar 06 '18 at 02:38
  • @thelatemail There are 2 labeled columns in the dataframe with 10 total samples (equal # for both, none zero). Column names 'Index A' and 'Measurement B' – Shawn Mar 06 '18 at 02:55
  • Also, no factor used anywhere. The result of data[index,] appears to be formatted correctly, it displays the 2 column data with a number on the left – Shawn Mar 06 '18 at 03:23

1 Answers1

0

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

Shawn
  • 353
  • 1
  • 14