Session 6 - More PsychoPy Flashcards

1
Q

Last session we used Psychopy to “code” a simple experiment.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

We can analyse last’s weeks data from RT experiment which is in Google sheet

A

in Colab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

First step of analysing data from Google sheet (importing modules) - (8)

A
  1. Importing plotting library ‘matplotlib’
  2. Importing from authentication modules from ‘google.colab’
  3. Importing authorisation libaries for sheets and colab : ‘from google.auth import default’
  4. Importing ‘pandas’
  5. ‘Importing numpy as np’
  6. Importing ‘scipy as ‘scipy’ which is importing scientific python
  7. Importing from psypy a function called ‘lingress’ which does linear regression
  8. Importing gspread which is a toolbox for working/ accessing with google sheets. Allowa Google Colab to reference by columns, rows , by their names so can ask for first 3 rows etc…
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Second step of analysing data from Google sheet (importing modules) - (4)(authorisation)

auth.authenticate_user()

A

This is where we authenticate to google - asking if you are ‘Gita’

If you authenticate once you do not do it again

Login in to your account (UoY)

In here, we are giving one website (Colab) the permission to access another web document (shared google spreadsheet) using your Google account information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Second step of analysing data from Google sheet (importing modules) - (2)(authorisation)

gc = gspread.authorize(cred)

A

This gets you a ‘google cloud’ handle/an authentication token

If you show this token ten Google will believe its ‘you’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Third step of analysing data from Google sheet (looking at the data) - (6)

A

Use the handle you just acquired to open the spreadsheet. Going to ask Google to open up spreadsheet of psychopy by giving them the handle to the workbook using web address of spreadsheet

  • ‘wb=gc.open_by_url(‘https://docs.goog…’ : Here we get a handle to the workbook (wb) using the web address of the spreadsheet. That gc module is ‘google cloud’.
  • data.wb.sheet1.get_all_values() - gets all the values from spreadsheet

-dArray = np.array(data) - turns all values of spreadsheet into numpy array which is mix of strings and numbers

  • print(dArray[0,[1,2,3,4]]) - using indices [1,2,3,4] of the first row in ‘dArray’ - Access the first row of the numpy array ‘dArray’ using index 0 - print the header strings
  • print(dArray[1:21,[1,2,3,4]])Print data (numbers) from rows 1 to 20 and columns 1 to 4 of ‘dArray’.
  • fArray=dArray[1:21,[1,2,3,4]].astype(float) - Convert the sliced portion of ‘dArray’ containing numerical data into a numpy array of floats (fArray).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Last week we wondered if someone’s height made a difference to

A

RT and test for both hands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

We can plot the data including a regression line and we can

A

Plotting the data and fitting a regression line using scipy’s linregress function for dominant and non-dominant hand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Reminder of what linear regression is - (4)

A

least sum of squares error) to a group of points. It has a slope (m) and a y-intercept (c).

y=mx+c

m’ represents the slope of the line, indicating the rate of change of y with respect to x.

  • ‘c’ denotes the y-intercept, the value of y when x equals zero.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Code plotting the linear regression of dominant and non-dominant hand - explanation

A

RTs=(fArray[0:,[0,1]]) - # Extract RTs and other important variables. The variable ‘RTs’ will contain the data from columns 0 and 1 of ‘fArray’, which represent the RTs for the dominant and non-dominant hands respectively.

handedness=fArray[0:,2] - This line extracts the data from the third column of ‘fArray’, which represents handedness.

height=fArray[0:,3] This line extracts the data from the fourth column of ‘fArray’, which represents height.

for thisRTHand in range(2): - This line initializes a loop that iterates twice, once for each hand (dominant and non-dominant).

plt.subplot(1,2,thisRTHand+1) # Two subplots
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=1, hspace=0) # Make the spacing nice
- These lines set up the subplot configuration, creating two subplots side by side.
They adjust the spacing between subplots for better visualization.

plt.scatter(height,RTs[:,thisRTHand]) - This line creates a scatter plot with height on the x-axis and RTs for the current hand (dominant or non-dominant) on the y-axis.

(m, c, rvalue, pvalue, stderr) = linregress(height,RTs[:,thisRTHand]) # height on x axis and RT on y axis - This line performs linear regression analysis to calculate the slope (m), intercept (c), correlation coefficient (rvalue), p-value (pvalue), and standard error (stderr) of the regression line -height on x axis and RT on y axis, m gradient, c offset, r value and p-value

y_pred = c + m*height # Make predictive y values based on height
plt.plot(height,y_pred, color=”red”, label=”Fit”)

These lines generate the predicted values (y_pred) using the equation of the regression line.
They plot the regression line on the scatter plot, indicating the relationship between height and RTs as a red line

plt.text(175,325,f”p={pvalue:.2f}”) # Places p-value of each scatter plot and r value
plt.text(175,340,f”r={rvalue:.2f}”) -These lines add text to the plot, displaying the p-value and correlation coefficient (r-value) with appropriate formatting - showing how much variation is explained in r value

plt.ylim(150,400) # Scale all plots to the same axes
plt.xlabel(“Height (cm)”)
plt.ylabel(“RT (s)”)

These lines set the y-axis limits for consistency across all plots and label the axes appropriately.

plt.show() - This line displays the plot to the user interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Output of this code:

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does this code show? - (2)

A

There doesn’t seem to be a general effect of height on either LH or RH reaction times. We could pool all the RTs in some way to get a more robust estimate but it is still almost certainly n.s.

One thing we might expect is that the dominant hand is faster than the non-dominant hand. To check this we can use a a t-test test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What statistical test can you use to ask if two groups of numbers are different?

A

t-test .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

There are several sorts of t-test. Which one is appropriate here?

One thing we might expect is that the dominant hand is faster than the non-dominant hand. To check this we can use a a t-test test.

A

a paired t-test (because we have two different measurements from each subject).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

scipy has all these statistical tests in them like

A

linear regression, t-tests etc…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Before you conduct at-test you should plot the data - (3)

A

Plotting data from categories is often best done with a boxplot.

This gives you a nice way of comparing the data ‘side by side’ and also computes and plots measures of spread automatically.

The ‘notch’ in the boxplot is very useful: It is a measure of the confidence interval. If notches from two groups don’t overlap it’s a good indication that they have different central tendencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain this code of producing boxplot before conducting t-test:

Boxplots of for the reaction times (RTs) of dominant and non-dominant hands - (7)

A

‘notch=True’ adds a notch indicating the confidence interval around the median - gives estimation of CI around the centre (median)

Label the x-axis ticks as ‘Dominant’ and ‘NonDom’ corresponding to the two boxplots.

plt.show() - display graph

Perform a paired-sample t-test using scipy.stats.ttest_rel() - asks to psypy for relative value t-test

  • The t-test compares the means of two paired groups to determine if there is a significant difference.
  • ‘RTs[:,0]’ and ‘RTs[:,1]’ represent the RTs for dominant and non-dominant hands respectively - of first and second column

Print the results of the paired t-test including the t-value and p-value with 3 significant figures - print(f’Paired t-test t={t:.3} | p={p:.3}’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the output show? - (3)

A
  • Shows the dots and extreme values, someone people have extreme RTs - very slow or very fast
  • Orange lines is median values, these are similar in dominant and non-dominant hand
  • V shape is the notices and rule of thumb is notches overlap probably no sig difference - so we don’t have sig diff - no relationship of RT and height, no relationship between RT and dominantness of hand
19
Q

The code we wrote last week runs many repetitions of the same condition. We did this using the loop component - (5)

A

In which placed a dot on one side and dot on another

It looped the trial 20 times

nReps - asking you how many repetitions of the trial

this loopType says whatever is inside the loop, if its different conditions then we will randomise it

Question is how to randomise different conditions in the loop?

20
Q

But very often we want to have intermixed conditions. For example, we might like to

A

intermix left and right hands at random in the same experiment.

21
Q

Randomizing conditions in this way is often a good idea because it prevents you from confounding effects of time with those of a condition your care about. For example, if you did all

A

LH conditions first, then all RH conditions you might measure a slower RT for the RH. But perhaps that is just because you were bored or tired for the RH?

22
Q

Here we will use an external data file (in .csv or .xls format) to control the

A

conditions.

23
Q

To make 2 conditions in psychopy experiment make csv file containing

A
24
Q

We save this csv file as the

A

n the same directory as your experiment. We will soon import this file into psychopy.

25
Q

In psychopy, in this csv file - (2)

A

Psychopy interprets the column headers as variable names.

And for each ‘iteration’ of the loop it can assign the values from one row to those variables - each containing a number and string from two column

26
Q

Now in our RT experiment from last week (W5) we can add the csv file of two conditions

This tells… - (3)

A

We want psychopy as it loops around the trial, in each iteration of loop we would like to pick a random finger and show us something on screen which finger to use

The way in which psychopy we have a data file available that lists conditions is in conditions tab - we tell where conditions list file CSV and tells you found 5 conditions (how many rows you got), 2 parameters and variables names are called finger, string

Each time Psychopy goes around the loop, it will pick values from one row of each of the 2 variables at random - since set loopType to random

27
Q

We now need to tell the subject which finger to use on each trial. To do this, we will print a little bit of text on the screen just before the trial saying something like Pinky or Thumb.

We will do this by changing the text that originally said ‘Ready’ - (3)

A

Open up the ‘GetReady’ component. There are two items in the timeline: some code (which is used to randomize the ISI) and some text. Last week that text said ‘Ready…’. We will now change it to reflect the finger that you are supposed to use.

Change the text to $String

In each iteration of loop, we want psychopy to tell what value of string is and place into textbox

28
Q

$ means - (2)

A

execute some python code-

for $string means embed python code inside your loop

29
Q

Everytime you set to loop

A

you have to update ‘set by frame’ than constant - updates the variable

30
Q

In experiment we have grating come up then ‘middle, pinky’ etc.. to what finger to use when pressing when grating appears after

A

space bar when grating appears

31
Q

How many trials should we have if nReps is 5 and we have 5 conditions?

A

25 trials

32
Q

We can set trial type into sequential in which or staircase

A

sequential is not randomise

33
Q

Few things to note: - (4)

A

1: You can force it to use the order in the original .csv file by setting Loop Type to ‘Sequential’ . There are other, funner options which we will not look at just yet.

2: The output data file now has columns for ‘Finger’ and ‘String’ that you can use to analyze your trials. Notice the spelling mistake has been ‘inherited’ here - it’s saving exactly what the ‘string’ said each time.

3: You can repeat the whole sequence many times (by setting nReps back to something >1). If you do this the random sequence will change each time. Try it!

4: You can enter a ‘seed’ for the random number generator so that the random sequence is exactly the same each time you run the experiment. Sometimes this is a good thing, sometimes not.

34
Q

We can produce a new experiment which randomising faces of images

this is what we have in our face folder once we unzip:

A
35
Q

What would error be if randomising finger and index but trial type set to sequential - (2)

A

Sequential trial type means that the conditions are presented in a fixed order - that the experiment will progress through the rows of the conditions file in the order they are listed, moving sequentially from one row to the next.

whereas random trial type would allow for randomization of conditions - means that the experiment will randomly select rows from the conditions file for each trial, rather than following a fixed sequence

36
Q

To add our face images, we can add a ‘picture’ stimulus to my trial

can make a CSV file called ‘faceFile’ column and adding images into CSV file from our folder

then name of the picture will be a variable called $faceFile

note… names in column A must match the filenames of the images you just downloaded in the face file

A
37
Q

Finally, add a loop around the image presentation. In the loop point it to your .csv file. It should say that it found 1 parameter with three values… like this:

A
38
Q

If you have done all this correctly, when you run the experiment, it will load the face images in ‘on the fly’ according to which image is currently selected in the (random) loop.

A
39
Q

If you have lots and lots of images then sometimes it’s annoying to have them in the same directory as your experiment. You want to ‘tuck them away neatly’ in a subfolder like this:

A
40
Q

In that case, you just need to tell Psychopy where they are relative to the experiment. There are lots of ways to do this. One way is to add the subdirectory into the “image” location in the image properties - (2)

A

Notice what we have done here - we have embedded some python code directly into the entry box in the image properties tab (os.path.join(xxx,yyy)). To do this, you should preface the code with a dollar sign ($)

There are lots of other ways to make this happen: One way is to include the directory name into the file name in the .csv file. Or you could add a bit of code in the stimulus routine that builds a filename from a constant and the faceFile variable.

41
Q

Calbiration

A

Scientists want to make sure that the stimuli they run are the same no matter where in the world they are. This way someone can replicate your experiments and check your results.

If you make a stimulus that is ‘40% of the screen’ or ‘100 pixels wide’ then it is very hard to know how big it actually appears to someone. How big was the screen? How far away was the subject? What were the brightness / contrast settings? Was it a gaming monitor or a projector or what?

As we all know, things that are far away can appear small.

To standardise our measurements, vision scientists like to measure the size of things in ‘visual angle’. This is the angle that lines from the edges of your stimulus make at your eye. As a rule of thumb (literally), your thumb is about 1.5-2 degrees of visual angle at arm’s length. They also measure other things like the brightness of the screen and how the colors look.

This process of setting up a display is called ‘calibration’. Your experiment right now is using a standard calibration that is often more or less okay. You can see the monitors available to you under the ‘monitor’ menu (Tools->Monitor Centre). Probably there is only one.

The monitor that you are actually using for your experiment is defined in the ‘Experiment settings’ panel. Under ‘screen’ you tell it the monitor name and some other things….

Notice that at the moment you are defining all your measurements in units of ‘screen height’. That’s not ideal - screens have different heights and people can sit at different distances from the screen. In the future we will change this to ‘degrees’ (deg) and define all our sizes in terms of visual angle.

42
Q

It would be this if laid out like this

A

with faceFile as column header of csv

43
Q

Would be this is laid out like this

A