[rsplus] r ai

Viewer

  1. # install required packages
  2. install.packages(c("languageR""tidyverse""magrittr"))
  3.  
  4. # load required packages
  5. library(languageR)
  6. library(tidyverse)
  7. library(magrittr)
  8.  
  9. # randomly select 10 rows from danish
  10. danish %>%
  11.   sample_n(10)
  12.  
  13. # calculate number of different words in danish
  14. danish %>%
  15.   distinct(word) %>%
  16.   nrow()
  17.  
  18. # calculate average response time for each affix
  19. danish %>%
  20.   group_by(affix) %>%
  21.   summarise(mean_rt = mean(logRT))
  22.  
  23. # create linear plot showing relation between log word frequency and log RTs
  24. ggplot(data = danish, aes(= logFreq, y = logRT)) +
  25.   geom_smooth(method = "lm")
  26.  
  27. # convert logRT to raw RTs
  28. danish %>%
  29.   mutate(RT = exp(logRT))
  30.  
  31. # compute average RTs by Sex
  32. danish %>%
  33.   group_by(Sex) %>%
  34.   summarise(mean_rt = mean(RT))
  35.  
  36. # plot histogram of RTs by Sex
  37. ggplot(data = danish, aes(= RT)) +
  38.   geom_histogram(color = "black", fill = "white") +
  39.   facet_wrap(~Sex)
  40.  
  41. # create 'frequency' variable and compute average RTs by frequency
  42. danish %>%
  43.   mutate(frequency = ifelse(logFreq > median(logFreq)"high freq""low freq")) %>%
  44.   group_by(frequency) %>%
  45.   summarise(mean_rt = mean(RT))
  46.  
  47. # plot histogram of RTs by frequency
  48. ggplot(data = danish, aes(= RT)) +
  49.   geom_histogram(color = "black", fill = "white") +
  50.   facet_wrap(~frequency)
  51.  

Editor

You can edit this paste and save as new:


File Description
  • r ai
  • Paste Code
  • 02 Dec-2022
  • 1.29 Kb
You can Share it: