simondp

Simulation of ratings

Jul 25th, 2022
2,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.98 KB | None | 0 0
  1. ### Simulate observers
  2. library(brms)
  3.  
  4. obs <- 16 # How many observers?
  5. trials <- 70 # How many trials per filter
  6.  
  7. # Plausible ratings
  8. high <- c(rep(2,8),rep(3,27),rep(4,25),rep(5,10))
  9. med <- c(rep(1,4),rep(2,22),rep(3,32),rep(4,11),rep(5,2))
  10. low <- c(rep(1,15),rep(2,31),rep(3,16),rep(4,4))
  11.  
  12. set.seed(42) # Set seed for reproducibility
  13.  
  14. # All observers like the non-filtered equally
  15. filterNon <- sample(high, trials*obs, replace = T)
  16. # Half observers dislike one filter particularly
  17. filterBad <- sample(low, trials*(obs/2), replace = T)
  18. # Rest of observers dislike filters equally
  19. filterMed <- sample(med, trials*(obs*1.5), replace = T)
  20.  
  21. # Create data frame
  22. ratings <- c(filterNon,filterBad,filterMed)
  23. filter <- sort(rep(c("0: None","1: Bad","2: Medium"),obs*trials))
  24. id <- factor(rep(sort(rep(1:obs,trials)),3))
  25. results <- data.frame(ratings,filter,id)
  26.  
  27. # Create brms model
  28. results$rating <- ordered(results$ratings)
  29. # Rating for each filter, random effect per id
  30. mfilter <- brm(rating ~ filter + (filter|id), data = results,
  31.              family = cumulative(threshold = "flexible"),
  32.              chains = 2, cores = 2, iter=3000)
  33.  
  34. # Plot each observer as understood by model
  35. conditional_effects(mfilter)
  36. consub <- make_conditions(results, vars = c("id"))
  37.  
  38. # Look at categorical model
  39. conditional_effects(
  40.   mfilter,
  41.   "filter",
  42.   conditions = consub,
  43.   re_formula = NULL, categorical = F
  44. )
  45.  
  46. # EXPERIMENT 2
  47. set.seed(101) # Set seed for reproducibility
  48.  
  49. # All observers like the non-filtered equally
  50. filterNon2 <- sample(high, trials*obs, replace = T)
  51. # Half observers dislike one filter particularly
  52. filterBad2 <- sample(low, trials*(obs/2), replace = T)
  53. # Rest of observers dislike filters equally
  54. filterMed2 <- sample(med, trials*(obs*1.5), replace = T)
  55.  
  56. # Create data frame for exp 2
  57. ratings <- c(filterNon2,filterBad2,filterMed2)
  58. results2 <- data.frame(ratings,filter,id)
  59. results2$rating <- ordered(results2$ratings)
  60.  
  61.  
  62. # Model Exp 2
  63. # How to compare with Exp 1?
Advertisement
Add Comment
Please, Sign In to add comment