psychopy.data
- functions for storing/saving/analysing data¶Routines for handling data structures and analysis
ExperimentHandler
¶psychopy.data.
ExperimentHandler
(name='', version='', extraInfo=None, runtimeInfo=None, originPath=None, savePickle=True, saveWideText=True, dataFileName='', autoLog=True)¶A container class for keeping track of multiple loops/handlers
Useful for generating a single data file from an experiment with many different loops (e.g. interleaved staircases or loops within loops
Usage: | exp = data.ExperimentHandler(name=”Face Preference”,version=‘0.1.0’) |
---|---|
Parameters: |
psychopy.info.RunTimeInfo savePickle : True (default) or False saveWideText : True (default) or False autoLog : True (default) or False |
abort
()¶Inform the ExperimentHandler that the run was aborted.
Experiment handler will attempt automatically to save data (even in the event of a crash if possible). So if you quit your script early you may want to tell the Handler not to save out the data files for this run. This is the method that allows you to do that.
addData
(name, value)¶Add the data with a given name to the current experiment.
Typically the user does not need to use this function; if you added your data to the loop and had already added the loop to the experiment then the loop will automatically inform the experiment that it has received data.
Multiple data name/value pairs can be added to any given entry of the data file and is considered part of the same entry until the nextEntry() call is made.
e.g.:
# add some data for this trial
exp.addData('resp.rt', 0.8)
exp.addData('resp.key', 'k')
# end of trial - move to next line in data output
exp.nextEntry()
addLoop
(loopHandler)¶Add a loop such as a TrialHandler
or StairHandler
Data from this loop will be included in the resulting data files.
loopEnded
(loopHandler)¶Informs the experiment handler that the loop is finished and not to include its values in further entries of the experiment.
This method is called by the loop itself if it ends its iterations, so is not typically needed by the user.
nextEntry
()¶Calling nextEntry indicates to the ExperimentHandler that the current trial has ended and so further addData() calls correspond to the next trial.
saveAsPickle
(fileName, fileCollisionMethod='rename')¶Basically just saves a copy of self (with data) to a pickle file.
This can be reloaded if necessary and further analyses carried out.
Parameters: | fileCollisionMethod: Collision method passed to
handleFileCollision() |
---|
saveAsWideText
(fileName, delim=None, matrixOnly=False, appendFile=False, encoding='utf-8', fileCollisionMethod='rename')¶Saves a long, wide-format text file, with one line representing the attributes and data for a single trial. Suitable for analysis in R and SPSS.
If appendFile=True then the data will be added to the bottom of an existing file. Otherwise, if the file exists already it will be overwritten
If matrixOnly=True then the file will not contain a header row, which can be handy if you want to append data to an existing file of the same format.
handleFileCollision()
TrialHandler
¶psychopy.data.
TrialHandler
(trialList, nReps, method='random', dataTypes=None, extraInfo=None, seed=None, originPath=None, name='', autoLog=True)¶Class to handle trial sequencing and data storage.
Calls to .next() will fetch the next trial object given to this handler, according to the method specified (random, sequential, fullRandom). Calls will raise a StopIteration error if trials have finished.
See demo_trialHandler.py
The psydat file format is literally just a pickled copy of the TrialHandler object that saved it. You can open it with:
from psychopy.tools.filetools import fromFile
dat = fromFile(path)
Then you’ll find that dat has the following attributes that
Parameters: |
nReps: number of repeats for all conditions
|
---|---|
Attributes (after creation): | |
.trialList - the original list of dicts, specifying the conditions
.nTotal - the total number of trials that will be run .nRemaining - the total number of trials remaining .thisN - total trials completed so far .thisRepN - which repeat you are currently on .thisTrialN - which trial number within that repeat
.finished - True/False for have we finished yet .extraInfo - the dictionary of extra info as given at beginning
|
addData
(thisType, value, position=None)¶Add data for the current trial
getEarlierTrial
(n=-1)¶Returns the condition information from n trials previously. Useful for comparisons in n-back tasks. Returns ‘None’ if trying to access a trial prior to the first.
getExp
()¶Return the ExperimentHandler that this handler is attached to, if any. Returns None if not attached
getFutureTrial
(n=1)¶Returns the condition for n trials into the future, without advancing the trials. A negative n returns a previous (past) trial. Returns ‘None’ if attempting to go beyond the last trial.
getOriginPathAndFile
(originPath=None)¶Attempts to determine the path of the script that created this data file and returns both the path to that script and its contents. Useful to store the entire experiment with the data.
If originPath is provided (e.g. from Builder) then this is used otherwise the calling script is the originPath (fine from a standard python script).
next
()¶Advances to next trial and returns it. Updates attributes; thisTrial, thisTrialN and thisIndex If the trials have ended this method will raise a StopIteration error. This can be handled with code such as:
trials = data.TrialHandler(.......)
for eachTrial in trials: # automatically stops when done
# do stuff
or:
trials = data.TrialHandler(.......)
while True: # ie forever
try:
thisTrial = trials.next()
except StopIteration: # we got a StopIteration error
break #break out of the forever loop
# do stuff here for the trial
printAsText
(stimOut=None, dataOut=('all_mean', 'all_std', 'all_raw'), delim='\t', matrixOnly=False)¶Exactly like saveAsText() except that the output goes to the screen instead of a file
saveAsExcel
(fileName, sheetName='rawData', stimOut=None, dataOut=('n', 'all_mean', 'all_std', 'all_raw'), matrixOnly=False, appendFile=True, fileCollisionMethod='rename')¶Save a summary data file in Excel OpenXML format workbook (xlsx) for processing in most spreadsheet packages. This format is compatible with versions of Excel (2007 or greater) and and with OpenOffice (>=3.0).
It has the advantage over the simpler text files (see
TrialHandler.saveAsText()
)
that data can be stored in multiple named sheets within the file.
So you could have a single file named after your experiment and
then have one worksheet for each participant. Or you could have
one file for each participant and then multiple sheets for
repeated sessions etc.
The file extension .xlsx will be added if not given already.
Parameters: |
|
---|
saveAsPickle
(fileName, fileCollisionMethod='rename')¶Basically just saves a copy of the handler (with data) to a pickle file.
This can be reloaded if necessary and further analyses carried out.
Parameters: | fileCollisionMethod: Collision method passed to
handleFileCollision() |
---|
saveAsText
(fileName, stimOut=None, dataOut=('n', 'all_mean', 'all_std', 'all_raw'), delim=None, matrixOnly=False, appendFile=True, summarised=True, fileCollisionMethod='rename', encoding='utf-8')¶Write a text file with the data and various chosen stimulus attributes
Parameters: |
---|
handleFileCollision()
saveAsWideText
(fileName, delim=None, matrixOnly=False, appendFile=True, encoding='utf-8', fileCollisionMethod='rename')¶Write a text file with the session, stimulus, and data values from each trial in chronological order. Also, return a pandas.DataFrame containing same information as the file.
This ‘wide’ format, as expected by R for creating dataframes, and various other analysis programs, means that some information must be repeated on every row.
In particular, if the trialHandler’s ‘extraInfo’ exists, then each entry in there occurs in every row. In builder, this will include any entries in the ‘Experiment info’ field of the ‘Experiment settings’ dialog. In Coder, this information can be set using something like:
myTrialHandler.extraInfo = {'SubjID': 'Joan Smith',
'Group': 'Control'}
Parameters: |
|
---|
setExp
(exp)¶Sets the ExperimentHandler that this handler is attached to
Do NOT attempt to set the experiment using:
trials._exp = myExperiment
because it needs to be performed using the weakref module.
StairHandler
¶psychopy.data.
StairHandler
(startVal, nReversals=None, stepSizes=4, nTrials=0, nUp=1, nDown=3, extraInfo=None, method='2AFC', stepType='db', minVal=None, maxVal=None, originPath=None, name='', autoLog=True, **kwargs)¶Class to handle smoothly the selection of the next trial and report current values etc. Calls to next() will fetch the next object given to this handler, according to the method specified.
See Demos >> ExperimentalControl >> JND_staircase_exp.py
The staircase will terminate when nTrials AND nReversals have been exceeded. If stepSizes was an array and has been exceeded before nTrials is exceeded then the staircase will continue to reverse.
nUp and nDown are always considered as 1 until the first reversal is reached. The values entered as arguments are then used.
Parameters: |
Additional keyword arguments will be ignored. |
---|---|
Notes: |
The additional keyword arguments **kwargs might for example be passed by the MultiStairHandler, which expects a label keyword for each staircase. These parameters are to be ignored by the StairHandler.
addData
(result, intensity=None)¶Deprecated since 1.79.00: This function name was ambiguous. Please use one of these instead:
.addResponse(result, intensity) .addOtherData(‘dataName’, value’)
addOtherData
(dataName, value)¶Add additional data to the handler, to be tracked alongside the result data but not affecting the value of the staircase
addResponse
(result, intensity=None)¶Add a 1 or 0 to signify a correct / detected or incorrect / missed trial
This is essential to advance the staircase to a new intensity level!
Supplying an intensity value here indicates that you did not use the recommended intensity in your last trial and the staircase will replace its recorded value with the one you supplied here.
calculateNextIntensity
()¶Based on current intensity, counter of correct responses, and current direction.
getExp
()¶Return the ExperimentHandler that this handler is attached to, if any. Returns None if not attached
getOriginPathAndFile
(originPath=None)¶Attempts to determine the path of the script that created this data file and returns both the path to that script and its contents. Useful to store the entire experiment with the data.
If originPath is provided (e.g. from Builder) then this is used otherwise the calling script is the originPath (fine from a standard python script).
next
()¶Advances to next trial and returns it. Updates attributes; thisTrial, thisTrialN and thisIndex.
If the trials have ended, calling this method will raise a StopIteration error. This can be handled with code such as:
staircase = data.StairHandler(.......)
for eachTrial in staircase: # automatically stops when done
# do stuff
or:
staircase = data.StairHandler(.......)
while True: # ie forever
try:
thisTrial = staircase.next()
except StopIteration: # we got a StopIteration error
break # break out of the forever loop
# do stuff here for the trial
printAsText
(stimOut=None, dataOut=('all_mean', 'all_std', 'all_raw'), delim='\t', matrixOnly=False)¶Exactly like saveAsText() except that the output goes to the screen instead of a file
saveAsExcel
(fileName, sheetName='data', matrixOnly=False, appendFile=True, fileCollisionMethod='rename')¶Save a summary data file in Excel OpenXML format workbook (xlsx) for processing in most spreadsheet packages. This format is compatible with versions of Excel (2007 or greater) and and with OpenOffice (>=3.0).
It has the advantage over the simpler text files
(see TrialHandler.saveAsText()
) that data can be stored
in multiple named sheets within the file. So you could have a
single file named after your experiment and then have one worksheet
for each participant. Or you could have one file for each participant
and then multiple sheets for repeated sessions etc.
The file extension .xlsx will be added if not given already.
The file will contain a set of values specifying the staircase level (‘intensity’) at each reversal, a list of reversal indices (trial numbers), the raw staircase / intensity level on every trial and the corresponding responses of the participant on every trial.
Parameters: |
|
---|
saveAsPickle
(fileName, fileCollisionMethod='rename')¶Basically just saves a copy of self (with data) to a pickle file.
This can be reloaded if necess and further analyses carried out.
Parameters: | fileCollisionMethod: Collision method passed to
handleFileCollision() |
---|
saveAsText
(fileName, delim=None, matrixOnly=False, fileCollisionMethod='rename', encoding='utf-8')¶Write a text file with the data
Parameters: |
|
---|
setExp
(exp)¶Sets the ExperimentHandler that this handler is attached to
Do NOT attempt to set the experiment using:
trials._exp = myExperiment
because it needs to be performed using the weakref module.
MultiStairHandler
¶psychopy.data.
MultiStairHandler
(stairType='simple', method='random', conditions=None, nTrials=50, originPath=None, name='', autoLog=True)¶A Handler to allow easy interleaved staircase procedures (simple or QUEST).
Parameters for the staircases, as used by the relevant
StairHandler
or
QuestHandler
(e.g. the startVal, minVal, maxVal...)
should be specified in the conditions list and may vary between
each staircase. In particular, the conditions /must/ include the
a startVal (because this is a required argument to the above
handlers) a label to tag the staircase and a startValSd
(only for QUEST staircases). Any parameters not specified in the
conditions file will revert to the default for that individual
handler.
If you need to custom the behaviour further you may want to look at the recipe on Coder - interleave staircases.
Params: |
|
---|
Example usage:
conditions=[
{'label':'low', 'startVal': 0.1, 'ori':45},
{'label':'high','startVal': 0.8, 'ori':45},
{'label':'low', 'startVal': 0.1, 'ori':90},
{'label':'high','startVal': 0.8, 'ori':90},
]
stairs = data.MultiStairHandler(conditions=conditions, nTrials=50)
for thisIntensity, thisCondition in stairs:
thisOri = thisCondition['ori']
# do something with thisIntensity and thisOri
stairs.addResponse(correctIncorrect) # this is ESSENTIAL
# save data as multiple formats
stairs.saveDataAsExcel(fileName) # easy to browse
stairs.saveAsPickle(fileName) # contains more info
addData
(result, intensity=None)¶Deprecated 1.79.00: It was ambiguous whether you were adding the response (0 or 1) or some other data concerning the trial so there is now a pair of explicit methods:
- addResponse(corr,intensity) #some data that alters the next
- trial value
- addOtherData(‘RT’, reactionTime) #some other data that won’t
- control staircase
addOtherData
(name, value)¶Add some data about the current trial that will not be used to control the staircase(s) such as reaction time data
addResponse
(result, intensity=None)¶Add a 1 or 0 to signify a correct / detected or incorrect / missed trial
This is essential to advance the staircase to a new intensity level!
getExp
()¶Return the ExperimentHandler that this handler is attached to, if any. Returns None if not attached
getOriginPathAndFile
(originPath=None)¶Attempts to determine the path of the script that created this data file and returns both the path to that script and its contents. Useful to store the entire experiment with the data.
If originPath is provided (e.g. from Builder) then this is used otherwise the calling script is the originPath (fine from a standard python script).
next
()¶Advances to next trial and returns it.
This can be handled with code such as:
staircase = data.MultiStairHandler(.......)
for eachTrial in staircase: # automatically stops when done
# do stuff here for the trial
or:
staircase = data.MultiStairHandler(.......)
while True: # ie forever
try:
thisTrial = staircase.next()
except StopIteration: # we got a StopIteration error
break # break out of the forever loop
# do stuff here for the trial
printAsText
(delim='\t', matrixOnly=False)¶Write the data to the standard output stream
Parameters: |
|
---|
saveAsExcel
(fileName, matrixOnly=False, appendFile=False, fileCollisionMethod='rename')¶Save a summary data file in Excel OpenXML format workbook (xlsx) for processing in most spreadsheet packages. This format is compatible with versions of Excel (2007 or greater) and and with OpenOffice (>=3.0).
It has the advantage over the simpler text files (see
TrialHandler.saveAsText()
)
that the data from each staircase will be save in the same file, with
the sheet name coming from the ‘label’ given in the dictionary of
conditions during initialisation of the Handler.
The file extension .xlsx will be added if not given already.
The file will contain a set of values specifying the staircase level (‘intensity’) at each reversal, a list of reversal indices (trial numbers), the raw staircase/intensity level on every trial and the corresponding responses of the participant on every trial.
Parameters: |
|
---|
saveAsPickle
(fileName, fileCollisionMethod='rename')¶Saves a copy of self (with data) to a pickle file.
This can be reloaded later and further analyses carried out.
Parameters: | fileCollisionMethod: Collision method passed to
handleFileCollision() |
---|
saveAsText
(fileName, delim=None, matrixOnly=False, fileCollisionMethod='rename', encoding='utf-8')¶Write out text files with the data.
For MultiStairHandler this will output one file for each staircase that was run, with _label added to the fileName that you specify above (label comes from the condition dictionary you specified when you created the Handler).
Parameters: |
|
---|
setExp
(exp)¶Sets the ExperimentHandler that this handler is attached to
Do NOT attempt to set the experiment using:
trials._exp = myExperiment
because it needs to be performed using the weakref module.
QuestHandler
¶psychopy.data.
QuestHandler
(startVal, startValSd, pThreshold=0.82, nTrials=None, stopInterval=None, method='quantile', beta=3.5, delta=0.01, gamma=0.5, grain=0.01, range=None, extraInfo=None, minVal=None, maxVal=None, staircase=None, originPath=None, name='', autoLog=True, **kwargs)¶Class that implements the Quest algorithm for quick measurement of psychophysical thresholds.
Uses Andrew Straw’s QUEST, which is a Python port of Denis Pelli’s Matlab code.
Measures threshold using a Weibull psychometric function. Currently, it is not possible to use a different psychometric function.
Threshold ‘t’ is measured on an abstract ‘intensity’ scale, which usually corresponds to log10 contrast.
The Weibull psychometric function:
_e = -10**(beta * (x2 + xThreshold)) p2 = delta * gamma + (1-delta) * (1 - (1 - gamma) * exp(_e))
Example:
# setup display/window
...
# create stimulus
stimulus = visual.RadialStim(win=win, tex='sinXsin', size=1,
pos=[0,0], units='deg')
...
# create staircase object
# trying to find out the point where subject's response is 50 / 50
# if wanted to do a 2AFC then the defaults for pThreshold and gamma
# are good
staircase = data.QuestHandler(staircase._nextIntensity, 0.2,
pThreshold=0.63, gamma=0.01,
nTrials=20, minVal=0, maxVal=1)
...
while thisContrast in staircase:
# setup stimulus
stimulus.setContrast(thisContrast)
stimulus.draw()
win.flip()
core.wait(0.5)
# get response
...
# inform QUEST of the response, needed to calculate next level
staircase.addResponse(thisResp)
...
# can now access 1 of 3 suggested threshold levels
staircase.mean()
staircase.mode()
staircase.quantile(0.5) # gets the median
0.82 which is equivalent to a 3 up 1 down standard staircase
(and might want gamma=0.01)
The variable(s) nTrials and/or stopSd must be specified.
beta, delta, and gamma are the parameters of the Weibull psychometric function.
Parameters: |
Additional keyword arguments will be ignored. |
---|---|
Notes: |
The additional keyword arguments **kwargs might for example be passed by the MultiStairHandler, which expects a label keyword for each staircase. These parameters are to be ignored by the StairHandler.
addData
(result, intensity=None)¶Deprecated since 1.79.00: This function name was ambiguous. Please use one of these instead:
.addResponse(result, intensity) .addOtherData(‘dataName’, value’)
addOtherData
(dataName, value)¶Add additional data to the handler, to be tracked alongside the result data but not affecting the value of the staircase
addResponse
(result, intensity=None)¶Add a 1 or 0 to signify a correct / detected or incorrect / missed trial
Supplying an intensity value here indicates that you did not use the recommended intensity in your last trial and the staircase will replace its recorded value with the one you supplied here.
calculateNextIntensity
()¶based on current intensity and counter of correct responses
confInterval
(getDifference=False)¶Return estimate for the 5%–95% confidence interval (CI).
Parameters: |
|
---|---|
Returns: | scalar or array of length 2. |
getExp
()¶Return the ExperimentHandler that this handler is attached to, if any. Returns None if not attached
getOriginPathAndFile
(originPath=None)¶Attempts to determine the path of the script that created this data file and returns both the path to that script and its contents. Useful to store the entire experiment with the data.
If originPath is provided (e.g. from Builder) then this is used otherwise the calling script is the originPath (fine from a standard python script).
importData
(intensities, results)¶import some data which wasn’t previously given to the quest algorithm
incTrials
(nNewTrials)¶increase maximum number of trials Updates attribute: nTrials
mean
()¶mean of Quest posterior pdf
mode
()¶mode of Quest posterior pdf
next
()¶Advances to next trial and returns it. Updates attributes; thisTrial, thisTrialN, thisIndex, finished, intensities
If the trials have ended, calling this method will raise a StopIteration error. This can be handled with code such as:
staircase = data.QuestHandler(.......)
for eachTrial in staircase: # automatically stops when done
# do stuff
or:
staircase = data.QuestHandler(.......)
while True: # i.e. forever
try:
thisTrial = staircase.next()
except StopIteration: # we got a StopIteration error
break # break out of the forever loop
# do stuff here for the trial
printAsText
(stimOut=None, dataOut=('all_mean', 'all_std', 'all_raw'), delim='\t', matrixOnly=False)¶Exactly like saveAsText() except that the output goes to the screen instead of a file
quantile
(p=None)¶quantile of Quest posterior pdf
saveAsExcel
(fileName, sheetName='data', matrixOnly=False, appendFile=True, fileCollisionMethod='rename')¶Save a summary data file in Excel OpenXML format workbook (xlsx) for processing in most spreadsheet packages. This format is compatible with versions of Excel (2007 or greater) and and with OpenOffice (>=3.0).
It has the advantage over the simpler text files
(see TrialHandler.saveAsText()
) that data can be stored
in multiple named sheets within the file. So you could have a
single file named after your experiment and then have one worksheet
for each participant. Or you could have one file for each participant
and then multiple sheets for repeated sessions etc.
The file extension .xlsx will be added if not given already.
The file will contain a set of values specifying the staircase level (‘intensity’) at each reversal, a list of reversal indices (trial numbers), the raw staircase / intensity level on every trial and the corresponding responses of the participant on every trial.
Parameters: |
|
---|
saveAsPickle
(fileName, fileCollisionMethod='rename')¶Basically just saves a copy of self (with data) to a pickle file.
This can be reloaded if necess and further analyses carried out.
Parameters: | fileCollisionMethod: Collision method passed to
handleFileCollision() |
---|
saveAsText
(fileName, delim=None, matrixOnly=False, fileCollisionMethod='rename', encoding='utf-8')¶Write a text file with the data
Parameters: |
|
---|
sd
()¶standard deviation of Quest posterior pdf
setExp
(exp)¶Sets the ExperimentHandler that this handler is attached to
Do NOT attempt to set the experiment using:
trials._exp = myExperiment
because it needs to be performed using the weakref module.
simulate
(tActual)¶returns a simulated user response to the next intensity level presented by Quest, need to supply the actual threshold level
FitWeibull
¶psychopy.data.
FitWeibull
(xx, yy, sems=1.0, guess=None, display=1, expectedMin=0.5)¶Fit a Weibull function (either 2AFC or YN) of the form:
y = chance + (1.0-chance)*(1-exp( -(xx/alpha)**(beta) ))
and with inverse:
x = alpha * (-log((1.0-y)/(1-chance)))**(1.0/beta)
After fitting the function you can evaluate an array of x-values
with fit.eval(x)
, retrieve the inverse of the function with
fit.inverse(y)
or retrieve the parameters from fit.params
(a list with [alpha, beta]
)
eval
(xx, params=None)¶Evaluate xx for the current parameters of the model, or for arbitrary params if these are given.
inverse
(yy, params=None)¶Evaluate yy for the current parameters of the model, or for arbitrary params if these are given.
FitLogistic
¶psychopy.data.
FitLogistic
(xx, yy, sems=1.0, guess=None, display=1, expectedMin=0.5)¶Fit a Logistic function (either 2AFC or YN) of the form:
y = chance + (1-chance)/(1+exp((PSE-xx)*JND))
and with inverse:
x = PSE - log((1-chance)/(yy-chance) - 1)/JND
After fitting the function you can evaluate an array of x-values
with fit.eval(x)
, retrieve the inverse of the function with
fit.inverse(y)
or retrieve the parameters from fit.params
(a list with [PSE, JND]
)
eval
(xx, params=None)¶Evaluate xx for the current parameters of the model, or for arbitrary params if these are given.
inverse
(yy, params=None)¶Evaluate yy for the current parameters of the model, or for arbitrary params if these are given.
FitNakaRushton
¶psychopy.data.
FitNakaRushton
(xx, yy, sems=1.0, guess=None, display=1, expectedMin=0.5)¶Fit a Naka-Rushton function of the form:
yy = rMin + (rMax-rMin) * xx**n/(xx**n+c50**n)
After fitting the function you can evaluate an array of x-values
with fit.eval(x)
, retrieve the inverse of the function with
fit.inverse(y)
or retrieve the parameters from fit.params
(a list with [rMin, rMax, c50, n]
)
Note that this differs from most of the other functions in not using a value for the expected minimum. Rather, it fits this as one of the parameters of the model.
eval
(xx, params=None)¶Evaluate xx for the current parameters of the model, or for arbitrary params if these are given.
inverse
(yy, params=None)¶Evaluate yy for the current parameters of the model, or for arbitrary params if these are given.
FitCumNormal
¶psychopy.data.
FitCumNormal
(xx, yy, sems=1.0, guess=None, display=1, expectedMin=0.5)¶Fit a Cumulative Normal function (aka error function or erf) of the form:
y = chance + (1-chance)*((special.erf((xx-xShift)/(sqrt(2)*sd))+1)*0.5)
and with inverse:
x = xShift+sqrt(2)*sd*(erfinv(((yy-chance)/(1-chance)-.5)*2))
After fitting the function you can evaluate an array of x-values with fit.eval(x), retrieve the inverse of the function with fit.inverse(y) or retrieve the parameters from fit.params (a list with [centre, sd] for the Gaussian distribution forming the cumulative)
NB: Prior to version 1.74 the parameters had different meaning, relating to xShift and slope of the function (similar to 1/sd). Although that is more in with the parameters for the Weibull fit, for instance, it is less in keeping with standard expectations of normal (Gaussian distributions) so in version 1.74.00 the parameters became the [centre,sd] of the normal distribution.
eval
(xx, params=None)¶Evaluate xx for the current parameters of the model, or for arbitrary params if these are given.
inverse
(yy, params=None)¶Evaluate yy for the current parameters of the model, or for arbitrary params if these are given.
importConditions()
¶psychopy.data.
importConditions
(fileName, returnFieldNames=False, selection='')¶Imports a list of conditions from an .xlsx, .csv, or .pkl file
The output is suitable as an input to TrialHandler
trialTypes or to MultiStairHandler
as a conditions list.
If fileName ends with:
- .csv: import as a comma-separated-value file
(header + row x col)
- .xlsx: import as Excel 2007 (xlsx) files.
No support for older (.xls) is planned.
- .pkl: import from a pickle file as list of lists
(header + row x col)
The file should contain one row per type of trial needed and one column for each parameter that defines the trial type. The first row should give parameter names, which should:
- be unique
- begin with a letter (upper or lower case)
- contain no spaces or other punctuation (underscores are permitted)
selection is used to select a subset of condition indices to be used It can be a list/array of indices, a python slice object or a string to be parsed as either option. e.g.:
- “1,2,4” or [1,2,4] or (1,2,4) are the same
- “2:5” # 2, 3, 4 (doesn’t include last whole value)
- “-10:2:” # tenth from last to the last in steps of 2
- slice(-10, 2, None) # the same as above
- random(5) * 8 # five random vals 0-8
functionFromStaircase()
¶psychopy.data.
functionFromStaircase
(intensities, responses, bins=10)¶Create a psychometric function by binning data from a staircase procedure. Although the default is 10 bins Jon now always uses ‘unique’ bins (fewer bins looks pretty but leads to errors in slope estimation)
usage:
intensity, meanCorrect, n = functionFromStaircase(intensities,
responses, bins)
bootStraps()
¶psychopy.data.
bootStraps
(dat, n=1)¶Create a list of n bootstrapped resamples of the data
SLOW IMPLEMENTATION (Python for-loop)
out = bootStraps(dat, n=1)