Guest User

Untitled

a guest
Dec 15th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. participant <- rep(1:10, each=100)
  2. stimuli <- rep(1:100, 10)
  3. judgment <- rnorm(1000)
  4. df1 <- data.frame(participant, stimuli, judgment)
  5. df2 <- data.frame(stimuli=1:100, criterion=rnorm(100))
  6. df <- merge(df1, df2, by='stimuli') %>% arrange(participant, stimuli)
  7.  
  8. participants_id = unique (df$participant)
  9.  
  10. MyFun = function(Data) {
  11.  
  12. HelpFun = function(x, Data) {
  13. # x is the index for the number of participants.
  14. # It Will be used in the lapply call bellow
  15. participants_x = sample(participants_id, x)
  16. filter(Data, participant %in% participants_x) %>%
  17. group_by(stimuli) %>%
  18. summarise( mean_x = mean(judgment),
  19. criterion = unique(criterion) ) %>%
  20. summarise(cor = cor(.$mean_x, .$criterion))
  21. }
  22. N <- length(unique(Data$participant))
  23.  
  24. lapply(1:N, HelpFun, Data) %>% bind_rows()
  25. }
  26.  
  27. MyFun(df)
Add Comment
Please, Sign In to add comment