1 / 48

Collecting Data with Free Software

Collecting Data with Free Software. Henrik Singmann. Free Software (in the GNU sense). Free Software is first of all not only free of charge but gives you the freedom to do what you want with your software : Freedom 0 : The freedom to run the program for any purpose .

kwalton
Download Presentation

Collecting Data with Free Software

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Collecting Data with Free Software Henrik Singmann

  2. Free Software (in the GNU sense) • Free Software isfirstof all not onlyfreeofcharge but givesyouthefreedomto do whatyouwantwithyoursoftware: • Freedom 0: The freedom to run the program for any purpose. • Freedom 1: The freedom to study how the program works, and change it to make it do what you wish. • Freedom 2: The freedom to redistribute copies so you can help your neighbor. • Freedom 3: The freedom to improve the program, and release your improvements (and modified versions in general) to the public, so that the whole community benefits.

  3. Data Collection • Responses from a limited numberofparticipantsto a limited numberofitems • Items constructedtoanswertheresearchquestions • Experimental research: participantsand/oritemsarerandomlyassigned • Items sharesimilarities: e.g., item orreponseformat, topic, layout… • Further informationfromparticipants: e..g., demographicinformation, priorknowledgeregardingtheresearchquestion, … • Variouswaystocollect such data: • Paper Questionnaires • Web Based Experiments • Computerized Lab Experiments

  4. Data Collection • Responses from a limited numberofparticipantsto a limited numberofitems • Items constructedtoanswertheresearchquestions • Experimental research: participantsand/oritemsarerandomlyassigned • Items sharesimilarities: e.g., item orreponseformat, topic, layout… • Further informationfromparticipants: e..g., demographicinformation, priorknowledgeregardingtheresearchquestion, … • Variouswaystocollect such data: • Paper Questionnaires • Web Based Experiments • Computerized Lab Experiments

  5. General Structureof an Experiment Most experiments follow the following general structure: • Greeting, introduction and instruction to the experiment and task • Main task: repeatedly working on similar items • Demographics, debriefing, … Depending on the design, part 2 may consist of multiple blocks or different tasks intermixed with additional instructions.

  6. Different typesof Items Two "types" ofstimuli/items: • Items whereexactpresentationandexacttimingisimportant. e.g.: • responsetimes, eyetracking, orsimilardependent variables • primingresearch (presentingstimuliverybrief) • psychophysicalresearch (randomdots) • Items thatcontain a lotof (semantic) informationandtheresponseshouldreflectdeliberatecognitiveprocesses.

  7. Different typesof Items Two "types" ofstimuli/items: • Items whereexactpresentationandexacttimingisimportant. e.g.: • responsetimes, eyetracking, orsimilardependent variables • priming Research (presentingstimuliverybrief) • psychophysicalresearch (randomdots) • Items thatcontain a lotof (semantic) informationandtheresponseshouldreflectdeliberatecognitiveprocesses.

  8. Example Experiment

  9. PsychoPy • Free softwarefor "the presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments". • Mainly developed for presenting "type 1" stimuli, but I will show how to easily present "type 2" stimuli. • PsychoPy uses the Python programming language: a free "general-purpose, interpreted high-level programming language whose design philosophy emphasizes code readability" (wikipedia)

  10. PsychoPy: Example "Type 1" Stimuli

  11. PsychoPy: Interfaces PsychoPyhastwo different interfaces: • The builderview: Build an experimentusing a graphicaluserinterface (i.e., via clickandplay) • The coderview: Build an experimentusing Python code. PsychoPyisverygood in controllingthemaintaskof an experiment but not so comfortablewhenitcomesaboutinstructionscreensandcollectingdemographicdata.

  12. The Builder View

  13. The Builder View • Goodforitemswhichconsistof a smallnumberofsingleelements (i.e., not toomuchtext). • The builderviewcanbeusedtoeasilydevelopclassicalpsychological "type 1" paradigms such as e.g., theStrooptask.

  14. Goodfordoingwhateveryouwantto do andis not possiblewithothermethods. • We will learnhowtousethecoderviewtocontrolthestructureoftheexperiment, collectthedata, presentthestimuli (usingadd-on PsyTML), and do all necessary administrative stuff. • We will design the ("type 2") items in htmlusing an external easy touse WYSIWYG editor.

  15. Designing "Type 2" Stimuli

  16. htmlForm Elements

  17. PsyTML • add-on forPsychoPydevelopedbyme • presentshtmlpageandcollectsthestatusof form elements after clickingtheSubmitbutton • htmlformsmaycontainany type ofhtml form element • data will behanded back to Python • See: https://github.com/singmann/psytml

  18. Creating HTML Pages • KompoZeris a free WYSIWYG htmleditor (http://www.kompozer.net/) • Layouting in htmlisdoneusingtableswithborder = 0 Steps in creating a htmlpage: • Create a 1 celltablewithwidthof e.g., 800 pixelcentrally. • Create a form insidethetableusingmethod "get". • Place all elementsinsidethe form (headline, text, form elements, …) • Usetable (andtablesinsidetables) fornicelayouting. • Add a "Submit" button.

  19. Creating HTML forms • html form elementshave a nameand a value • The nameisthe variable nameandthevaluethevalueofthis variable in Python • Ofradiobuttonswiththe same nameonlyonecanbeselected • Form elementsotherthanradiobuttonsshouldhaveuniquenames

  20. A briefintroductionto HTML • Insteadofusingthe WYSIWYG editor, itis easy tochangethings in thehtmlcode. • htmlisplaintextaccompaniedwithmarkup tags. • markup tags areenclosedbwteen< >: <tag> • Usuallyyouhave an openning tag and a closing tag: • <tag> opens • </tag> closes • htmlmaylookdifficult in thebeginning, but is easy tolearn.

  21. A barebonehtmlpage • A htmldocumentissplitintotwoparts: headandbody • The headcontainsmetainformationandthe title • The bodycontainswhatisvisible. <html> <head> <title>Hello HTML</title> </head> <body> <p>Hello World!</p> </body> </html>

  22. Importanthtml Tags • a html form usesisenclosedby<form> and</form>(forPsyTMLmethod="get"ismandatory) • most form elementsarecreatedwith<input …> • <tr> and</tr> create a tablecolumn, <td> and</td> a cell. • <br> adds a linebreak/newline • <p> </p> encloses a paragraphoftext. • <div …> </div> isusedfortextformatting

  23. Advancedhtml • General formatting (backgroundandothercolor, font type, fontsize, …) isdoneusingcascading style sheets (CSS). Add e.g. totheheader:<link rel="stylesheet" type="text/css" href="design.css"> • Tomakebuttonpressesmandatory, Javascriptisnecessary. (See theexamplesofPsyTML) • PsyTMLshouldallow Flash andotherplugins (thisbehaviorisuntested)

  24. Summaryhtml • htmlformsare a simple waytoconstructinstructionscreensor "type 2" items. • htmltutorialscanbefound all overthe web, goodplacestostartare e.g.: www.w3schools.comorwww.boogiejack.com/html_tutorials.html(in German: selfhtml.org) • KompoZeris a freecomfortableeditor (but seemsunstablesometimeswhenopeningmorethanonefile)

  25. Summaryhtml Files • Eachscreenand item is a singlehtmlfile(onecouldreplacecertaincontent, but …) • Instructionsandotherscreens also needtocontain a form and a Submitbutton (otherwisePsyTMLdoes not knowwhentheparticipantisdone). • Items are all ofthe same structureandcontain EXACTLY the same form elementswiththe same names. • <input … type = hidden> canbeusedtocodethe item.

  26. TransformingtheExample Experiment into an own Experiment

  27. The Example Experiment • PsyTMLcontainstheexampleexperiment in thefolderexamples/psychopy/ • The mainfoldercontains: • .pyfilescontainingthe Python scripts • id.lst andmake.idLst.R: forcontrollingwhichisthenextparticipant • README files • thehtmlfoldercontains: • thehtmlfilesrepresenting all screens (instruction, items, …) • thecssfilescontaininggraphicalparameters • jsval.js: a javascriptlibrarycontrollingrequireditems • an imagesfolderwithsomeimages • The datafoldercontainsthedata after runningtheexperiment

  28. The exampleexperiment • PsyTMLcontainstheexampleexperiment in thefolderexamples/psychopy/ • The mainfoldercontains: • .pyfilescontainingthe Python scripts • id.lst andmake.idLst.R: forcontrollingwhichisthenextparticipant • README files • thehtmlfoldercontains: • thehtmlfilesrepresenting all screens (instruction, items, …) • thecssfilescontaininggraphicalparameters • jsval.js: a javascriptlibrarycontrollingrequireditems • an imagesfolderwithsomeimages • The datafoldercontainsthedata after runningtheexperiment

  29. Buildingyourown Experiment I • Write instructionscreensand end screens. • Develop a templateofthe item in themaintask. • Makeasmanycopiesofthisfileasyouneed it. • Exchange thecontentandadaptsettheappropriatehiddenhtmlformstoidentifyeach item. • Feed thehtmlfilestoPsychoPy.

  30. Buildingyourown Experiment I • Write instructionscreensand end screens. • Develop a templateofthe item in themaintask. • Makeasmanycopiesofthisfileasyouneed it. • Exchange thecontentandadaptsettheappropriatehiddenhtmlformstoidentifyeach item. • Feed thehtmlfilestoPsychoPy.

  31. A verybriefIntroductionto Python I • Python has a shell (>>>) so onecaninteractwith Python directly. • Variables aredynamicallytyped (i.e., type of variables does not needtobedeclared):>>> x = 3>>> type(x)<type 'int'> • Whitespaceindentationdelimitblocks (insteadof{}):>>> if (x > 0):... print("Yes")... else:... print("no")... Yes • four spaces (and not tab) represent the indentation to bind blocks of code together.

  32. A verybriefIntroductionto Python II Data types: • Numbers:>>> x = y = z = 0 # Zero x, y andz>>> x0>>> y0>>> z0>>> tax = 12.5 / 100>>> price = 100.50>>> price * tax12.5625 • Strings( use ' ' or " "):>>> word = 'Help' + 'A' >>> word 'HelpA'>>> word[0]'H'>>> word[2:4]'lp' • Unicode Strings (u' '):>>> y = u'Rüdiger'>>> yu'R\xfcdiger'

  33. A verybriefIntroductionto Python III • Lists: A list of comma-separated values between square brackets, that do not have to have the same type:>>> a = ['spam', u'eggs', 100, 1234]>>> a['spam', u'eggs', 100, 1234] • Like string indices, list indices start at 0, and lists can be sliced, concatenated and so on:>>> a[1:-1][u'eggs', 100]>>> a[1:][u'eggs', 100, 1234]>>> a[2] = a[2] + 23>>> a['spam', u'eggs', 123, 1234]

  34. A verybriefIntroductionto Python IV • Dictionaries: An unorderedsetofkey: valuepairsenclosedbybraces{}.>>> tel = {'jack': 4098, 'sape': 4139} >>> tel['guido'] = 4127 >>> tel{'sape': 4139, 'guido': 4127, 'jack': 4098} >>> tel['jack'] 4098

  35. A verybriefIntroductionto Python V • Python containsloops (repeatedoperations):>>> y = 0>>> for x in xrange(5):... y = y + x... >>> y10 • Importantkeywords / elements in Python are: • import: importslibrary • if / else / for: controlflow • . : seperatesfunctionsfromlibraries; methods/elementsfromobjects • # : afterwordscomes a comment

  36. Summary Python • Run a script in PsychoPybypressing • Terminate a scriptbypressing • PsychoPycontains a Python shell (>>>): • Work throughparts 3, 4, and 5 of "The Python Tutorial": http://docs.python.org/tutorial/index.html • The importantdatatypesarestrings (" "), unicodestrings (u" "), lists ( [ ] ), anddictionaries ( { } ) withtheircorrespondingmethods. • Python runs a scriptfromthefirstlinetothe end.

  37. The exampleexperiment • PsyTMLcontainstheexampleexperiment in thefolderexamples/psychopy/ • The mainfoldercontains: • .pyfilescontainingthe Python scripts • id.lst andmake.idLst.R: forcontrollingwhichisthenextparticipant • README files • thehtmlfoldercontains: • thehtmlfilesrepresenting all screens (instruction, items, …) • thecssfilescontaininggraphicalparameters • jsval.js: a javascriptlibrarycontrollingrequireditems • an imagesfolderwithsomeimages • The datafoldercontainsthedata after runningtheexperiment

  38. The exampleexperiment • PsyTMLcontainstheexampleexperiment in thefolderexamples/psychopy/ • The mainfoldercontains: • .pyfilescontainingthe Python scripts • id.lst andmake.idLst.R: forcontrollingwhichisthenextparticipant • README files • PsychoPy1.py containsthecodeoftheexampleexperiment. • PsyTML.py containsthecodethatdisplaysthehtmlpages. • helper.py containssomehelperfunctions (e.g., forwritingthedata).

  39. PsychoPy1.py Besidesnecessarytechnicalstuff, thefilecontains: • Parameters fortheexperiment such asnameandpathofthedatafolder. • List ofitemsforthemaintask (splitforthetwoconditions) • Presentationofinstructions, itemsand end screen. • Functionswritingthedata.

  40. Data Examples

  41. Howdoesthe Data looklike? • Internallysaved in a listofdictionnarieswiththe same keys (dictionarykeysarethenamesofthehtmlforms) • helper.writeTrials() writesdatalisttothedatafolder in a singlefile per participant (filenamecontainsexperimentnameandid) seperatingvaluesbyargumentsep (defaultseperatoristab). • Eachtrialoccupiesonerow in thedatafile. • theheaderargumentdefineswhich variables shouldbewritten (andthe order ofthe variables.)

  42. Demographic Data • Demographicdataof all participantsiswrittento a singlefile. • Eachrowcorrespondstooneparticipantandeachnewparticipantissimplyappendedtothefile. • Comments oftheparticipantsareaddedto a commentsfolder.

  43. Data Examples

  44. HowtodetermineParticipant ID? • id.lst is a textfilecontainingparticipantnumberandcondition, one per row • * indicatesthattheidhasbeenused • helper.getIdFile()triesto open id.lst andreturnsthenextidandconditionandmarksitwith * • Whenrunningexperiments on multiple machinesthisfileisbeststored in a networkfolder • make.idList.Rcontains an R scriptforcreatingfileswithrandomizedconditions

  45. Buildingyourown Experiment II After creatingthedesiredhtmlfiles: • Create a PsychoPy Monitor andsetthecorrectscreensize (http://psychopy.org/general/monitors.html) • Change experimentnameandsetcorrectfolders. • Replacethereferencestothehtmlfileswithyourownhtmlfiles. • Add callstoviewPsyTMLfor additional screens, e.g.: intro.viewPsyTML("html/intro2.html") • Set thedata_headerlisttomatchyour variable names (i.e., html form names). • Create yourown id.lst

  46. Summary • PsychoPyandPsyTMLprovide a frameworkforrunningexperimentswith "type 2" items: • Create thescreensanditemsusinghtmlforms. • Python andPsychoPyareusedforrunningtheexperiment, PsyTMLdisplaystheformsandgathersthedata. • Learning basichtmland Python isprobably a goodinvestment.

More Related