04-stimuli_latex_tables.R 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. library(tidyverse)
  2. ggplot2::theme_set(theme_bw())
  3. round_apa <- function(x, n=2, absolute_zero=TRUE) {
  4. kept_zeroes <- if (absolute_zero) x==0 else rep(FALSE, length(x))
  5. pos_neg <- sign(x)
  6. z <- abs(x)*10^n
  7. z <- z + 0.5 + sqrt(.Machine$double.eps)
  8. z <- trunc(z)
  9. z <- z/10^n
  10. z <- gsub(" ", "", as.character(format(z * pos_neg, scientific=FALSE)), fixed=TRUE)
  11. has_point <- grepl(".", z, fixed=TRUE)
  12. if (any(has_point)) {
  13. nchars_after_point <- nchar(ifelse(has_point, sub("^.*\\.", "", z), ""))
  14. z_zeroes <- strrep("0", max(nchars_after_point)-nchars_after_point)
  15. z_suff <- ifelse(has_point, z_zeroes, sprintf(".%s", z_zeroes))
  16. z <- paste(z, z_suff, sep="")
  17. }
  18. z <- sub("^0\\.", ".", z)
  19. z <- sub("^-0\\.", "-.", z)
  20. z <- ifelse(kept_zeroes, "0", z)
  21. if (any(grepl(sprintf(".%s", strrep("0", n)), z, fixed=TRUE))) {
  22. xmin <- as.double(sprintf(".%s1", strrep("0", n-1)))
  23. lt_xmin <- x < xmin & x > 0 & grepl("^\\.0", z)
  24. z[lt_xmin] <- sprintf("<.%s1", strrep("0", n-1))
  25. }
  26. if (any(
  27. (grepl(sprintf("^-\\.%s", strrep("0", n)), z) | grepl(sprintf("^\\.%s", strrep("0", n)), z))
  28. )) {
  29. xmax <- as.double(sprintf("-.%s1", strrep("0", n-1)))
  30. gt_xmax <- x > xmax & x < 0 & grepl("^-\\.0|^\\.0", z)
  31. z[gt_xmax] <- sprintf(">.%s1", strrep("0", n-1))
  32. }
  33. z[is.na(z)] <- "-"
  34. z
  35. }
  36. # picture word stimuli ----------------------------------------------------
  37. stim_tidy <- read_csv("stim_tidy.csv")
  38. tbl <- stim_tidy %>%
  39. rowwise() %>%
  40. mutate(cos_ppmi_sim = min(c(cos_ppmi_sim_A1, cos_ppmi_sim_A2))) %>%
  41. ungroup() %>%
  42. select(
  43. filename_A1,
  44. perc_name_agree_A1,
  45. order_grp,
  46. string_A1, string_A2,
  47. Length_A1, Length_A2,
  48. Zipf.SUBTLEX_UK_A1, Zipf.SUBTLEX_UK_A2,
  49. ON.OLD20_A1, ON.OLD20_A2,
  50. BG.SUBTLEX_UK_A1, BG.SUBTLEX_UK_A2,
  51. CNC.Brysbaert_A1, CNC.Brysbaert_A2,
  52. cos_ppmi_sim
  53. ) %>%
  54. arrange(perc_name_agree_A1) %>%
  55. mutate(
  56. perc_name_agree_A1 = sprintf("%s\\%%", perc_name_agree_A1),
  57. Zipf.SUBTLEX_UK_A1 = round_apa(Zipf.SUBTLEX_UK_A1, 2),
  58. Zipf.SUBTLEX_UK_A2 = round_apa(Zipf.SUBTLEX_UK_A2, 2),
  59. ON.OLD20_A1 = round_apa(ON.OLD20_A1, 2),
  60. ON.OLD20_A2 = round_apa(ON.OLD20_A2, 2),
  61. BG.SUBTLEX_UK_A1 = round_apa(BG.SUBTLEX_UK_A1, 4),
  62. BG.SUBTLEX_UK_A2 = round_apa(BG.SUBTLEX_UK_A2, 4),
  63. CNC.Brysbaert_A1 = round_apa(CNC.Brysbaert_A1, 2),
  64. CNC.Brysbaert_A2 = round_apa(CNC.Brysbaert_A2, 2),
  65. cos_ppmi_sim = round_apa(cos_ppmi_sim, 4)
  66. ) %>%
  67. mutate(rn = row_number()) %>%
  68. select(rn, everything())
  69. tbl %>%
  70. mutate(across(everything(), function(x) sprintf(" %s ", x))) %>%
  71. write_delim(file.path("latex_tables", "pw_stim_latex.txt"), delim="&", col_names = FALSE, eol = "\\\\\n")
  72. # localiser stimuli -------------------------------------------------------
  73. loc_stim <- read_csv("localiser_stim.csv")
  74. loc_tbl <- loc_stim %>%
  75. select(string, Length, Zipf.SUBTLEX_UK, PREV.Brysbaert, ON.OLD20, BG.SUBTLEX_UK, PoS.SUBTLEX_UK, CNC.Brysbaert, AoA.Kuperman, VAL.Warriner, AROU.Warriner, DOM.Warriner, RT.BLP, Accuracy.BLP) %>%
  76. mutate(
  77. Zipf.SUBTLEX_UK = round_apa(Zipf.SUBTLEX_UK, 2),
  78. PREV.Brysbaert = round_apa(PREV.Brysbaert, 2),
  79. ON.OLD20 = round_apa(ON.OLD20, 2),
  80. BG.SUBTLEX_UK = round_apa(BG.SUBTLEX_UK, 4),
  81. CNC.Brysbaert = round_apa(CNC.Brysbaert, 2),
  82. AoA.Kuperman = round_apa(AoA.Kuperman, 2),
  83. VAL.Warriner = round_apa(VAL.Warriner, 2),
  84. AROU.Warriner = round_apa(AROU.Warriner, 2),
  85. DOM.Warriner = round_apa(DOM.Warriner, 2),
  86. RT.BLP = round_apa(RT.BLP, 1),
  87. Accuracy.BLP = round_apa(Accuracy.BLP, 2)
  88. ) %>%
  89. mutate(rn = row_number()) %>%
  90. select(rn, everything())
  91. loc_tbl %>%
  92. mutate(across(everything(), function(x) sprintf(" %s ", x))) %>%
  93. write_delim(file.path("latex_tables", "loc_stim_latex.txt"), delim="&", col_names = FALSE, eol = "\\\\\n")