Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(tidyverse)
- library(rsample)
- #the data
- ttSample <- data.frame(grad = c(0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
- #the function bootstrapping it n number of times
- bootstrapper <- function(n) {bootstraps(data = ttSample, times = n)}
- #the function calculating p_hat for each cell
- meanTaker <- function(columnVal)
- {
- for(i in 1:length(columnVal))
- {
- meanHolder <- vector("double", nrow(columnVal[[i]]))
- for(j in 1:nrow(columnVal[[i]]))
- {
- meanHolder[[j]] <- mean(as.data.frame(columnVal$splits[[j]])$grad)
- print(meanHolder[[j]])
- }
- print(meanHolder)
- mean(meanHolder)
- }
- }
- #the data frame- everything will run smoothly before the last pipe
- bootFrame <- data.frame(n = rep(c(250, 1000, 5000, 10000), 3), confLev = rep(c(0.9, 0.95, 0.99))) %>%
- arrange(n, confLev) %>%
- mutate(alpha = 1 - confLev,
- upperCI = confLev + (alpha / 2),
- lowerCI = confLev - (alpha / 2),
- samples = map(ttSample, list),
- boots = map(.x = .$n, .f = bootstrapper)) %>%
- #this is where I get the problem.
- #I was trying to get p-hat from finding the mean of the means of each sample
- mutate(p_hat = map(.x = .$boots, .f = meanTaker))
Add Comment
Please, Sign In to add comment