480 likes | 496 Views
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 .
E N D
Collecting Data with Free Software Henrik Singmann
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.
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
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
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.
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.
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.
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)
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.
The Builder View • Goodforitemswhichconsistof a smallnumberofsingleelements (i.e., not toomuchtext). • The builderviewcanbeusedtoeasilydevelopclassicalpsychological "type 1" paradigms such as e.g., theStrooptask.
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.
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
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.
Creating HTML forms • html form elementshave a nameand a value • The nameisthe variable nameandthevaluethevalueofthis variable in Python • Ofradiobuttonswiththe same nameonlyonecanbeselected • Form elementsotherthanradiobuttonsshouldhaveuniquenames
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.
A barebonehtmlpage • A htmldocumentissplitintotwoparts: headandbody • The headcontainsmetainformationandthe title • The bodycontainswhatisvisible. <html> <head> <title>Hello HTML</title> </head> <body> <p>Hello World!</p> </body> </html>
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
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)
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)
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.
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
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
Buildingyourown Experiment I • Write instructionscreensand end screens. • Develop a templateofthe item in themaintask. • Makeasmanycopiesofthisfileasyouneed it. • Exchange thecontentandadaptsettheappropriatehiddenhtmlformstoidentifyeach item. • Feed thehtmlfilestoPsychoPy.
Buildingyourown Experiment I • Write instructionscreensand end screens. • Develop a templateofthe item in themaintask. • Makeasmanycopiesofthisfileasyouneed it. • Exchange thecontentandadaptsettheappropriatehiddenhtmlformstoidentifyeach item. • Feed thehtmlfilestoPsychoPy.
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.
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'
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]
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
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
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.
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
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).
PsychoPy1.py Besidesnecessarytechnicalstuff, thefilecontains: • Parameters fortheexperiment such asnameandpathofthedatafolder. • List ofitemsforthemaintask (splitforthetwoconditions) • Presentationofinstructions, itemsand end screen. • Functionswritingthedata.
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.)
Demographic Data • Demographicdataof all participantsiswrittento a singlefile. • Eachrowcorrespondstooneparticipantandeachnewparticipantissimplyappendedtothefile. • Comments oftheparticipantsareaddedto a commentsfolder.
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
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
Summary • PsychoPyandPsyTMLprovide a frameworkforrunningexperimentswith "type 2" items: • Create thescreensanditemsusinghtmlforms. • Python andPsychoPyareusedforrunningtheexperiment, PsyTMLdisplaystheformsandgathersthedata. • Learning basichtmland Python isprobably a goodinvestment.