PSYC 241. Introduction to Programming Web-Based Experiments for Psychology Research

Prof. Timothy Brady
Wednesdays 9am-12pm
Crick conference room, 3rd floor Mandler Hall
Bring a laptop every day!

About this class: The core mission of this class is to help everybody be able to write web-based psychology studies that go beyond simple surveys; collect data on these experiments using crowdsourcing platorms like MTurk/Prolific/Online SONA; and download/access the data from the experiments for analysis offline in R/MATLAB/Python. It is broadly aimed at people who have some basic programming skills but have not previously written experiments for the web, although if you have no programming experience at all you should be able to keep up and hopefully get something out of the class as well. If you have ever written your own web-based experiment using HTML/Javascript, or have existing Javascript experience, this class is likely to be too introductory for you. Because of the nature of skill-based courses like this, we won't be able to learn everything in a group setting and will do a fair amount of independent work in the classroom starting in approximately week 3, including spending classroom time working on final projects -- this will allow everybody to get help from me and from each other.

January 8th

Slides from today: PDF PPT

  1. Who am I
  2. Who everybody else is and what everybody hopes to learn
  3. Broad structure of the class
  4. Basics of the web (browsers, servers, DNS, HTTP, etc.)
  5. Client-side technologies: HTML/CSS/Javascript/JQuery/jsPsych
  6. Server-side technologies: PHP, Python, psiTurk
  7. Glitch.com Test
  8. Introduction to Mechanical Turk
  9. Introduction to Prolific
  10. Introduction to Online SONA
  11. IRB issues and how payments work on MTurk/Prolific
  12. Using MTurk's interface to post our first experiment on the sandbox
  13. Resources for getting a head start on basic HTML/CSS at home:
    https://www.khanacademy.org/computing/computer-programming/html-css
    https://internetingishard.com/html-and-css/introduction/
    https://scrimba.com/g/ghtmlcss

January 15

For today, read Stewart et al. 2017, TiCS PDF

  1. Overview of some non-code based ways to run web experiments
  2. Design issues when running web experiments
  3. Coding our first simple experiment "by hand" (just jQuery):
  4. Some MTurk resources that might be handy:
  5. Code we wrote:

January 22

Homework for today: Make a completely blank document (but copy and paste the jQuery line into it!). Make a single DIV with some text in it, and give it an ID. Then make it 500px wide, centered and have a gray background. Finally, make it so that when you click it, it disappears.

  1. Overview of HTML, CSS, Javascript syntax and theory
  2. Coding a more complex experiment using just jQuery
  3. Making a full "template" for many basic studies
  4. What we wrote on the whiteboard:

    HTML:

    CSS:

    Javascript:

    jQuery:

  5. Code we wrote:

January 29

Homework for today: Take our experiment template and remix it -- don't edit directly! And make it so that if they are correct about it being a word or non-word, it just goes on to the next trial as usual. But if they are incorrect, it waits an extra 2 seconds to go on. And add some words -- make it 10 trials total.

  1. Expanding our experiment template:
    1. Reminder about functions (calling with () vs. passing as variables):
    2. Objects -- like structs (but you can put functions in them):
    3. Arrays/lists:
    4. Loops:
    5. Making a trial structure and re-using a DIV
  2. Saving data to a server
  3. Code we wrote:

February 5

Homework for today: Take our experiment template and remix it -- don't edit directly! Add a few more trials, and for each one, add another part to the trial list: which color each word is in (red or blue, half and half). Then when the word is shown, make it shown in that color instead of black.

  1. Server-side scripting, working with data, and the format I usually save data in (JSON)
  2. Server-side scripting
  3. Very brief introduction to psiTurk as a way to host a server/store a database of data etc.
  4. Loading JSON in R, MATLAB or Python for analysis
  5. Reviewing our existing code and modifying to use images as a refresher (from https://psyc241.ucsd.edu/Tim/Objects/)
  6. Code we wrote:
  7. Discussing/planning your own experiments

February 12

  1. jsPsych as a way to simplify the creation of basic experiments
  2. Introduction to jsPsych
  3. Coding a simple experiment in jsPsych
  4. Code we wrote:
  5. Continuing work on your own experiments

February 19

  1. INPUT, radio buttons, TEXTAREA
  2. Posting a HIT on Turk, SONA and Prolific using our (final) template.
  3. Turk:
  4. Prolific:
  5. SONA:
  6. Continuing work on your own experiments

February 26th

  1. Absolute and relative positioning
  2. Non-jQuery access to elements
  3. Canvas, Audio, etc.
  4. Code we wrote:
  5. Continuing work on your own experiments

March 4

  1. Continuing work on your own experiments

March 11th

  1. FINAL PROJECT: On March 10th before 7pm: Send me an email with a link to your project and 2 paragraphs about the conceptual purpose of the project, and another 2 paragraphs about the technical aspects of what you accomplished. (You can contextualize this with where you started before the class.)
  2. Present your experiments! Tell everybody about you or your group's experiment.
  3. Wrap-up discussion.
  4. For reference, and with code, here are everyone's projects. The descriptions of them are in this PDF..
    1. Yang Wang
    2. Holly Huey
    3. Yuan Chai
    4. Chloe Shields
    5. Mohan Gupta
    6. Kyros Jijia Shen
    7. Dalin Guo
    8. Angus Chapman
    9. Catherine Tallman
    10. Monica Gonugunta
    11. Anne Yilmaz
    12. So Eun Ahn
    13. Jonathan Keefe
    14. Leo Kleiman
    15. Tone Xu
    16. Jamal Williams
    17. Yaqian Huang
    18. Hayden Schill
    19. Sherry Yueyi Jiang
    20. Ana Chkhaidze and Parla Buyruk
    21. Ethan Hurwitz
    22. Reina Mizrahi
    23. Sunyoung Park
    24. Hui Xin Ng
    25. Cameron Holdaway
    26. Michael Allen