redickio

Untitled

Sep 22nd, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.17 KB | None | 0 0
  1. library(tidyverse)
  2. library(rsample)
  3.  
  4. #the data
  5. 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))
  6. #the function bootstrapping it n number of times
  7. bootstrapper <- function(n) {bootstraps(data = ttSample, times = n)}
  8. #the function calculating p_hat for each cell
  9. meanTaker <- function(columnVal)
  10. {
  11.   for(i in 1:length(columnVal))
  12.   {
  13.     meanHolder <- vector("double", nrow(columnVal[[i]]))
  14.     for(j in 1:nrow(columnVal[[i]]))
  15.     {
  16.       meanHolder[[j]] <- mean(as.data.frame(columnVal$splits[[j]])$grad)
  17.       print(meanHolder[[j]])
  18.     }
  19.     print(meanHolder)
  20.     mean(meanHolder)
  21.   }
  22. }
  23. #the data frame- everything will run smoothly before the last pipe
  24. bootFrame <-  data.frame(n = rep(c(250, 1000, 5000, 10000), 3), confLev = rep(c(0.9, 0.95, 0.99))) %>%
  25.   arrange(n, confLev) %>%
  26.   mutate(alpha = 1 - confLev,
  27.     upperCI = confLev + (alpha / 2),
  28.     lowerCI = confLev - (alpha / 2),
  29.     samples = map(ttSample, list),
  30.     boots = map(.x = .$n, .f = bootstrapper)) %>%
  31. #this is where I get the problem.  
  32. #I was trying to get p-hat from finding the mean of the means of each sample
  33.   mutate(p_hat = map(.x = .$boots, .f = meanTaker))
Add Comment
Please, Sign In to add comment