I'm working on an assignment with the following prompt:
1b) Create a function which will take a vector of numeric values, and an integer n as arguments. The function will perform nonparametric bootstrapping on this data, n times, calculating the most-probable value of the data set. The function should return the output of the boot command.
This is the function I have written:
non.p.bootstrap <- function(vector, n) {
mode.stat <- function(my.data,i) return(my.mode(my.data[i]))
b <- boot(data = vector, statistic = mode.stat, R = n)
return(b)
}
The function my.mode is one I have written which outputs the mode of a vector of continuous data.
Edit: Here is the my mode function I created as well
my.mode <- function(vector) {
hist <-hist(vector, breaks = length(vector), plot = FALSE)
densest <- max(hist$density)
mode <- hist$mid[hist$density == densest]
return(mode)
}
However, when I try to run my bootstrapping function on a vector of 1000 data points, I get an error message.