YoramJF

Untitled

Feb 23rd, 2021 (edited)
693
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Team 36
  2.  
  3. ##########
  4. ### STEP 0
  5. ##########
  6. load("AllData.Rdata")
  7. ##########
  8. ### STEP 1
  9. ##########
  10.  
  11. ### 1. Difficulty of the task. The levels are
  12. ### "Easy scrabble" and "Hard scrabble".
  13. ### 2. Number of correctly generated words that are unique.
  14. ### 3. H0: The number of correctly generated words doesn't depend on the difficulty of the task.
  15. ### H1: The number of correctly generated words depends on the difficulty of the task.
  16.  
  17. ##########
  18. ### STEP 2
  19. ##########
  20.  
  21. ### creating the subset we will use
  22. participants2018 <- allData[allData$SubjectNr >= 301 & allData$SubjectNr <= 348,]
  23. dualTaskSet <- participants2018[participants2018$partOfExperiment == "dualTask",]
  24. dualTaskSet <- droplevels(dualTaskSet)
  25. levels(dualTaskSet$partOfExperiment)
  26.  
  27. ### end of trials
  28. library(plyr)
  29. allDataEndOfTrialsDualTaskOnly <-
  30.   ddply(dualTaskSet, .(SubjectNr, TrialNumber, scrabbleCondition), summarize,
  31.                        nrCorrectScrabbleWords = max(nrCorrectScrabbleWords)
  32. )
  33.  
  34. ### avg number of scrabble words
  35. withoutNeutral <-
  36.   allDataEndOfTrialsDualTaskOnly[
  37.     allDataEndOfTrialsDualTaskOnly$scrabbleCondition != "neutral",
  38.     ]
  39. averageNrScrabbleWords <-
  40.   with(withoutNeutral,
  41.        aggregate(nrCorrectScrabbleWords,
  42.                  list(SubjectNr=SubjectNr,scrabbleCondition=scrabbleCondition),
  43.                  mean))
  44. colnames(averageNrScrabbleWords)[3] <- "averageScrabbleWords"
  45.  
  46. ##########
  47. ### STEP 3
  48. ##########
  49.  
  50. levels(averageNrScrabbleWords$scrabbleCondition)
  51. averageNrScrabbleWords2 <- droplevels(averageNrScrabbleWords)
  52.  
  53. library(ggplot2)
  54.  
  55. my_plot <- ggplot(averageNrScrabbleWords2, aes(x=scrabbleCondition, y=averageScrabbleWords)) +
  56.   geom_boxplot(stat = "boxplot")
  57. my_plot
  58.  
  59. scrabbleConditionMeans <- with(averageNrScrabbleWords2, tapply(averageScrabbleWords, list(scrabbleCondition),mean))
  60.  
  61. barplot(height=scrabbleConditionMeans, main="Average Number of Scrabble Words Generated", ylim=c(0,12))
  62.  
  63. ###
  64. ### So far, the pattern we observe in our plots is in line with our hypothesis.
  65. ### We expected the easy condition to be larger than the hard condition and this
  66. ### is indeed the case.
  67. ###
  68. ### A within-subjects design has been used.
  69. ###
  70.  
  71. source("usefulFunctions.R")
  72. summaryScrabble <- summarySEwithin(averageNrScrabbleWords2,
  73.                                    measurevar="averageScrabbleWords", withinvars=c("scrabbleCondition"))
  74. print(summaryScrabble)
  75.  
  76. library(ggplot2)
  77. g1 <- ggplot(summaryScrabble, aes(x=scrabbleCondition, y=averageScrabbleWords)) +
  78.   geom_bar(stat="identity") +
  79.   geom_errorbar(aes(ymin=averageScrabbleWords-sd, ymax=averageScrabbleWords+sd), width=.2) +
  80.   ylab("Average Number of Words") +
  81.   xlab("Task Difficulty") +
  82.   ggtitle("Standard Deviation") +
  83.   scale_y_continuous(limits = c(0, 20))
  84.  
  85. g2 <- ggplot(summaryScrabble, aes(x=scrabbleCondition, y=averageScrabbleWords)) +
  86.   geom_bar(stat="identity") +
  87.   geom_errorbar(aes(ymin=averageScrabbleWords-se, ymax=averageScrabbleWords+se), width=.2) +
  88.   ylab("Average Number of Words") +
  89.   xlab("Task Difficulty") +
  90.   ggtitle("Standard Errors") +
  91.   scale_y_continuous(limits = c(0, 20))
  92.  
  93. g3 <- ggplot(summaryScrabble, aes(x=scrabbleCondition, y=averageScrabbleWords)) +
  94.   geom_bar(stat="identity") +
  95.   geom_errorbar(aes(ymin=averageScrabbleWords-ci, ymax=averageScrabbleWords+ci), width=.2) +
  96.   ylab("Average Number of Words") +
  97.   xlab("Task Difficulty") +
  98.   ggtitle("Confidence interval") +
  99.   scale_y_continuous(limits = c(0, 20))
  100.  
  101.  
  102. library(cowplot)
  103. print(plot_grid(g1,g2,g3, ncol = 3))
  104.  
  105. ###
  106. ### Since the 95% CI bars do not overlap, we expect that in the experiment
  107. ### the two conditions will differ in line with our hypothesis H1.
  108. ###
  109.  
  110. ##########
  111. ### STEP 4
  112. ##########
  113.  
  114. summaryScrabble$lower <- summaryScrabble$averageScrabbleWords - summaryScrabble$ci
  115. summaryScrabble$upper <- summaryScrabble$averageScrabbleWords + summaryScrabble$ci
  116.  
  117. ##########
  118. ### STEP 5
  119. ##########
  120.  
  121. with(averageNrScrabbleWords2,t.test(averageScrabbleWords~ scrabbleCondition,paired=TRUE))
  122.  
RAW Paste Data