0

I used next program code to estimate the standard error using bootstrap for Libras Data movement set:

mydata<-read.table('C:/Users/Desktop/libra.txt', sep=',', header=TRUE)
head(data)
custom.boot <- function(times, data=mydata) {
  boots <- rep(NA, times)
  for (i in 1:times) {
    boots[i] <- sd(sample(data, length(data), replace=TRUE))/sqrt(length(data))  
  }
  boots
}
# Mean standard error
mean(custom.boot(times=1000))

But I got next error:

Error in is.data.frame(x) : 
  (list) object cannot be coerced to type 'double'

Could you help me to figure out the problem and give advice how it can be solved? Thanks in advance!

Siguza
  • 21,155
  • 6
  • 52
  • 89
Student
  • 49
  • 1
  • 6
  • There is a package for bootstraping. Here is a link to the [documentation](http://cran.r-project.org/web/packages/boot/boot.pdf). – marbel Jan 02 '14 at 00:33

1 Answers1

0

The mydata object is being read in as a 395 x 91 data.frame which custom.boot is struggling with. When I added changed to data = mydata[, 1] the function ran without an error. If you want to leave your function as is, I would either loop through every column or stack all the columns into one long column.

EDIT:

If you want to loop through all the columns of this data.frame, I would write a loop similar to what you have but one that slices by each column:

for(i in 1:ncol(mydata)){
  custom.boot(times=1000, data=mydata[, i])
  print(mean(custom.boot(times=1000)))
}
Stedy
  • 7,359
  • 14
  • 57
  • 77
  • Thank You for answer, can you explain how can I loop through every column (I can't understand where should I put another cicle)? – Student Jan 01 '14 at 22:23
  • And one more question is this code Ok for classification error estimation? – Student Jan 01 '14 at 22:49
  • Thank You very much for Your help, but I haven't understood in which part of program should I put this loop? I tried to put in in order of # Mean standard error mean(custom.boot(times=1000)) But I got again error message ("Error in is.data.frame(x) : (list) object cannot be coerced to type 'double'") – Student Jan 02 '14 at 20:05
  • After your suggestions my program looks as follows:require(rpart) mydata<-read.table('C:/Users/tr/Desktop/HPdati/libratable.txt', sep=',', header=TRUE) #C:\Users\tr\Desktop\HPdati.libratable #head(data) custom.boot <- function(times, colNumber){ boots <- rep(NA, times) for (i in 1:times) { boots[i] <- sd(sample(mydata[,colNumber], length(mydata[,colNumber]), replace=TRUE))/sqrt(length(mydata[,colNumber])) } boots } for(i in 1:ncol(mydata)){ custom.boot(times=1000, colNumber=i) print(mean(custom.boot(times=1000))) } # Mean standard error mean(custom.boot(times=1000)) – Student Jan 02 '14 at 22:11
  • However when I try to execute it I get the following error: Error in is.data.frame(x) : (list) object cannot be coerced to type 'double' > May be You have some ideas how to solve it? – Student Jan 02 '14 at 22:15