{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from IPython.core.display import HTML, Markdown, display\n", "\n", "import numpy.random as npr\n", "import numpy as np\n", "import pandas as pd\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "import scipy.stats as stats\n", "import statsmodels.formula.api as smf\n", "import ipywidgets as widgets\n", "\n", "import os" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 1C: Mental Rotation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As described in the reading, in the Shepard & Metzler (1971) experiments, the time it took people to decide if an object was the same (just rotated) or different (a mirror reflection) depended on the angle of rotation: \n", "\n", "\n", "\n", "In other words, it would take you longer to decide if the 30 degree rotated version of your cup was the same as the upright version relative to the 15 degree rotated version. The idea is that in order to make the same/mirror judgement, people actually mentally rotate the object. Bigger angles require more time to “rotate” in your mind just as they would in the real world (see Figure above)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 1
\n", " Rather than collecting data in class, we will use raw data from this replication of the Shepard and Metzler study (see here). This study ran N=54 participants. Using a for loop, read each of the files from the list below into a pandas dataframe. Then, using the pandas `concat` function (Refer back to the dataframes lab) combine them into a single data frame. \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a key to the structure of the dataframe:\n", "\n", "- Trial: trial number. \n", "- Condition: Filename of stimulus\n", "- Time: Response time\n", "- correct: Correct (desired) response, in other words, the trial type\n", "- response: Actual response\n", "- angle: Angle (angular disparity, see paper)\n", "- correct/incorrect: Was the response correct or incorrect?" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# this is an example list comprehension which reads in the all the files.\n", "# the f.startswith() part just gets rid of any junk files in that folder \n", "filenames=['lab2-data/'+f for f in os.listdir('lab2-data') if not f.startswith('.')]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", " Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 2
\n", " Jump to the methods section of the paper where the data comes from, this paper. Read the methods to determine what quality control measures they applied to their data. For instance, what kind of trials were analyzed and which were excluded? Was there any basis for excluding an entire participant? In a markdown cell, describe the set of exclusion criterion that the authors used. Next, create a new data frame of the data from our experiment applying the same exclusion criterion. \n", " \n", "Hint: For calculating mean and sd for different groups of trials, I suggest making a new column of the dataframe called 'tag' that contains the concatenated strings/fields that define a group. Then you can use the groupby function to find the mean and sd. There are other ways to do this, however.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 3
\n", " Use the pandas 'groupby' function to compute the average reaction time as a function of the angle of the stimulus. It may help to go back to the notebook on dataframes and plotting and searching for the groupby example.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 4
\n", " Using the seaborn 'scatterplot()' function (docs), create a plot of angle versus reaction time collapsing across all the subjects in the task. You should restrict you analysis the same trials that were analyzed in the target reading.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 5
\n", " As you have seen the regplot() and scatterplot() types in seaborn are quite related. Replot the data from above this time using regplot so you can get a sense of the best fit regression line fit to the overall dataset. Again, you should restrict you analysis the same trials that were analyzed in the target reading.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 6
\n", " Using the statsmodels ordinary least squares regression peform a regression of angle (predictor) onto reaction time (outcome) for the whole data frame. Compare the cofficients you obtained to the ones reported in the results section of the paper. (I wouldn't expect the coefficients to match exactly.. they didn't for me)\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 7
\n", " Although in the previous step we might see evidence of the increase of reaction time with angle, there are some caveats because we averaged across a number of other relevant aspects of our data frame. For instance, we averaged across both the subjects (Subject column) and the type of stimuli (if it was 'same' or 'different' - this is in the Correct column). Using the example groupby command displayed in class, find the average reaction time as a function of angle and same/different for each individual subject.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 8
\n", " Using the dataframe you constructed in the last step recreate Figure 3 from the paper. Hint: the plot in Figure three is akin to the 'catplot' in seaborn. Consult the seaborn documentation for information on this plot type.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 9
\n", " The analyses we have considered so far combine across subjects. However we would often like to analyze the effect in terms of individuals. Do individuals show this pattern, or only the group? Let's approach this two ways. One, graphically by making a plot of every individual subject. Two, analytically by running a separate regression model for individual subjects. For the plot use the seaborn `regplot`. \n", " \n", " Please conduct this analysis for 3 randomly chosen individual participants.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Question 10
\n", " In your own words, please summarize the results of the analyses you conducted above. Specifically you should mention what the regresssion results imply about the data. How consistent is the pattern across subjects?\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Your Answer
\n", "Delete this text and put your answer here. The text/code for your analysis should appear in the cells below.
" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }