Answers for "how to bootstrap in r"

R
0

how to bootstrap in r

# Import libaries
library(boot)

# Create sample dataframe
set.seed(1)
x <- rnorm(1000, sd=10)
y <- rnorm(1000, sd=1)
df <- data.frame(x,y)

# Create function to pass to boot()
calc_mean = function(data, index){
  mean_x <- mean(df$x[index]) 
  return(mean_x)
}

boot(df$x, calc_mean, R=1000)
Posted by: Guest on November-24-2021
0

how to bootstrap in r

library(boot)

boot_returns <- function(data, indices){
  d <- data[indices]
  Return.calculate(d, method="log")
}

bret <- boot(end_eq, boot_returns, R=1000)

dim(bret$t)
bretMeans <- colMeans(bret$t, na.rm = TRUE)
Posted by: Guest on November-24-2021

Browse Popular Code Answers by Language