{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array(['IAT', 'tools', 'stats', 'graphics', 'grDevices', 'utils',\n", " 'datasets', 'methods', 'base'],\n", " dtype='\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
blockconditiontrial_wordlatencyerrorscorrectresponsesubjnum
00Death,LifeDead80901Death1
10Death,LifeDeceased85201Death1
20Death,LifeAlive60601Life1
30Death,LifeLiving42001Life1
40Death,LifeSuicide134701Death1
\n", "" ], "text/plain": [ " block condition trial_word latency errors correct response subjnum\n", "0 0 Death,Life Dead 809 0 1 Death 1\n", "1 0 Death,Life Deceased 852 0 1 Death 1\n", "2 0 Death,Life Alive 606 0 1 Life 1\n", "3 0 Death,Life Living 420 0 1 Life 1\n", "4 0 Death,Life Suicide 1347 0 1 Death 1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.head()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "subjnum\n", "1 40\n", "2 200\n", "3 200\n", "4 200\n", "5 200\n", "Name: subjnum, dtype: int64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Number of trials per subject\n", "#Note that Subject 1 has too few trials\n", "d.groupby('subjnum').subjnum.count().head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n", " 18, 19, 20, 21])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Number of subjects in this data set\n", "d.subjnum.unique()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array(['Death,Life', 'Not Me,Me', 'Life,Death', 'Life/Not Me,Death/Me',\n", " 'Death/Not Me,Life/Me'], dtype=object)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Conditions\n", "d.condition.unique()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4, 5, 6])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Blocks\n", "d.block.unique()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([1, 0])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Correct coded as 1, errors coded as 0 in correct column\n", "d.correct.unique()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "Blocks 0,1 & 4 - which contain conditions 'Death,Life', 'Not Me,Me', 'Life,Death' are practice blocks, meaning they do not contain relevant data because they do not contrast the different categories.\n", "
\n", "
\n", "Therefore, we will enter blocks 2,3,5,6 and conditions 'Life/Not Me,Death/Me', 'Death/Not Me,Life/Me' into analyze_iat.\n", "
\n", "
\n", "We are entering the \"correct\" column, which contains 1 for correct and 0 for errors. We could enter the \"errors\" column and then just set the error_or_correct argument to 'error.' \n", "
\n", "
\n", "Finally, we have the option to return the total number and percentage of trials that are removed because they are either too fast (default : 400ms) or too slow (default : 10000ms). This will return the number and percentage across all subjects and across just subjects that do not receive a flag indicating they had poor performance on some metric. \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## pyiat" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Return a weighted d-scores. It will also return all error and too fast/too slow trial information and flags indicating poor performance as well as the number of blocks" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "d1,fs1=pyiat.analyze_iat(d,subject='subjnum',rt='latency',condition='condition',correct='correct'\\\n", " ,cond1='Death/Not Me,Life/Me',cond2='Life/Not Me,Death/Me'\\\n", " ,block='block',blocks=[2,3,5,6],fastslow_stats=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### First 14 columns contain the number of trials, - overall, for each condition and for each block - both before and after excluding fast\\slow trials\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
overall_num_trls_incl_fastslow_rtDeath/Not Me,Life/Me_num_trls_incl_fastslow_rtLife/Not Me,Death/Me_num_trls_incl_fastslow_rtDeath/Not Me,Life/Me_bl1_num_trls_incl_fastslow_rtLife/Not Me,Death/Me_bl1_num_trls_incl_fastslow_rtDeath/Not Me,Life/Me_bl2_num_trls_incl_fastslow_rtLife/Not Me,Death/Me_bl2_num_trls_incl_fastslow_rtoverall_num_trls_excl_fastslow_rtDeath/Not Me,Life/Me_num_trls_excl_fastslow_rtLife/Not Me,Death/Me_num_trls_excl_fastslow_rtDeath/Not Me,Life/Me_bl1_num_trls_excl_fastslow_rtLife/Not Me,Death/Me_bl1_num_trls_excl_fastslow_rtDeath/Not Me,Life/Me_bl2_num_trls_excl_fastslow_rtLife/Not Me,Death/Me_bl2_num_trls_excl_fastslow_rt
subjnum
2120606020402040119596020392040
3120606020402040120606020402040
4120606020402040118586019392040
5120606020402040120606020402040
6120606020402040119596020392040
\n", "
" ], "text/plain": [ " overall_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 120 \n", "3 120 \n", "4 120 \n", "5 120 \n", "6 120 \n", "\n", " Death/Not Me,Life/Me_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 60 \n", "3 60 \n", "4 60 \n", "5 60 \n", "6 60 \n", "\n", " Life/Not Me,Death/Me_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 60 \n", "3 60 \n", "4 60 \n", "5 60 \n", "6 60 \n", "\n", " Death/Not Me,Life/Me_bl1_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 20 \n", "3 20 \n", "4 20 \n", "5 20 \n", "6 20 \n", "\n", " Life/Not Me,Death/Me_bl1_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 40 \n", "3 40 \n", "4 40 \n", "5 40 \n", "6 40 \n", "\n", " Death/Not Me,Life/Me_bl2_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 20 \n", "3 20 \n", "4 20 \n", "5 20 \n", "6 20 \n", "\n", " Life/Not Me,Death/Me_bl2_num_trls_incl_fastslow_rt \\\n", "subjnum \n", "2 40 \n", "3 40 \n", "4 40 \n", "5 40 \n", "6 40 \n", "\n", " overall_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 119 \n", "3 120 \n", "4 118 \n", "5 120 \n", "6 119 \n", "\n", " Death/Not Me,Life/Me_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 59 \n", "3 60 \n", "4 58 \n", "5 60 \n", "6 59 \n", "\n", " Life/Not Me,Death/Me_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 60 \n", "3 60 \n", "4 60 \n", "5 60 \n", "6 60 \n", "\n", " Death/Not Me,Life/Me_bl1_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 20 \n", "3 20 \n", "4 19 \n", "5 20 \n", "6 20 \n", "\n", " Life/Not Me,Death/Me_bl1_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 39 \n", "3 40 \n", "4 39 \n", "5 40 \n", "6 39 \n", "\n", " Death/Not Me,Life/Me_bl2_num_trls_excl_fastslow_rt \\\n", "subjnum \n", "2 20 \n", "3 20 \n", "4 20 \n", "5 20 \n", "6 20 \n", "\n", " Life/Not Me,Death/Me_bl2_num_trls_excl_fastslow_rt \n", "subjnum \n", "2 40 \n", "3 40 \n", "4 40 \n", "5 40 \n", "6 40 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,0:14].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Next 7 columns contain error the number of trials - overall, within each condition and within each block\n", "###### Error rates are calculated prior to excluding fast\\slow trials but there is an option - errors_after_fastslow_rmvd - that if set to True will remove fast/slow trials prior to calculating error rates" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
overall_error_rateDeath/Not Me,Life/Me_error_rateLife/Not Me,Death/Me_error_rateDeath/Not Me,Life/Me_bl1_error_rateLife/Not Me,Death/Me_bl1_error_rateDeath/Not Me,Life/Me_bl2_error_rateLife/Not Me,Death/Me_bl2_error_rate
subjnum
20.0833330.0833330.0833330.100.0750.050.10
30.0583330.0333330.0833330.050.0250.050.10
40.0416670.0500000.0333330.000.0750.000.05
50.1250000.0666670.1833330.050.0750.150.20
60.1500000.1000000.2000000.050.1250.200.20
\n", "
" ], "text/plain": [ " overall_error_rate Death/Not Me,Life/Me_error_rate \\\n", "subjnum \n", "2 0.083333 0.083333 \n", "3 0.058333 0.033333 \n", "4 0.041667 0.050000 \n", "5 0.125000 0.066667 \n", "6 0.150000 0.100000 \n", "\n", " Life/Not Me,Death/Me_error_rate Death/Not Me,Life/Me_bl1_error_rate \\\n", "subjnum \n", "2 0.083333 0.10 \n", "3 0.083333 0.05 \n", "4 0.033333 0.00 \n", "5 0.183333 0.05 \n", "6 0.200000 0.05 \n", "\n", " Life/Not Me,Death/Me_bl1_error_rate \\\n", "subjnum \n", "2 0.075 \n", "3 0.025 \n", "4 0.075 \n", "5 0.075 \n", "6 0.125 \n", "\n", " Death/Not Me,Life/Me_bl2_error_rate \\\n", "subjnum \n", "2 0.05 \n", "3 0.05 \n", "4 0.00 \n", "5 0.15 \n", "6 0.20 \n", "\n", " Life/Not Me,Death/Me_bl2_error_rate \n", "subjnum \n", "2 0.10 \n", "3 0.10 \n", "4 0.05 \n", "5 0.20 \n", "6 0.20 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,14:21].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Next 7 columns contain pct of too fast trials - overall, within each condition and within each block" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
overall_fast_rt_rate_400msDeath/Not Me,Life/Me_fast_rt_rate_400msLife/Not Me,Death/Me_fast_rt_rate_400msDeath/Not Me,Life/Me_bl1_fast_rt_rate_400msLife/Not Me,Death/Me_bl1_fast_rt_rate_400msDeath/Not Me,Life/Me_bl2_fast_rt_rate_400msLife/Not Me,Death/Me_bl2_fast_rt_rate_400ms
subjnum
20.0083330.0166670.00.000.0250.00.0
30.0000000.0000000.00.000.0000.00.0
40.0166670.0333330.00.050.0250.00.0
50.0000000.0000000.00.000.0000.00.0
60.0083330.0166670.00.000.0250.00.0
\n", "
" ], "text/plain": [ " overall_fast_rt_rate_400ms Death/Not Me,Life/Me_fast_rt_rate_400ms \\\n", "subjnum \n", "2 0.008333 0.016667 \n", "3 0.000000 0.000000 \n", "4 0.016667 0.033333 \n", "5 0.000000 0.000000 \n", "6 0.008333 0.016667 \n", "\n", " Life/Not Me,Death/Me_fast_rt_rate_400ms \\\n", "subjnum \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "5 0.0 \n", "6 0.0 \n", "\n", " Death/Not Me,Life/Me_bl1_fast_rt_rate_400ms \\\n", "subjnum \n", "2 0.00 \n", "3 0.00 \n", "4 0.05 \n", "5 0.00 \n", "6 0.00 \n", "\n", " Life/Not Me,Death/Me_bl1_fast_rt_rate_400ms \\\n", "subjnum \n", "2 0.025 \n", "3 0.000 \n", "4 0.025 \n", "5 0.000 \n", "6 0.025 \n", "\n", " Death/Not Me,Life/Me_bl2_fast_rt_rate_400ms \\\n", "subjnum \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "5 0.0 \n", "6 0.0 \n", "\n", " Life/Not Me,Death/Me_bl2_fast_rt_rate_400ms \n", "subjnum \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "5 0.0 \n", "6 0.0 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,21:28].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Next 7 columns contain pct of too slow trials - overall, within each condition and within each block" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
overall_slow_rt_rate_10000msDeath/Not Me,Life/Me_slow_rt_rate_10000msLife/Not Me,Death/Me_slow_rt_rate_10000msDeath/Not Me,Life/Me_bl1_slow_rt_rate_10000msLife/Not Me,Death/Me_bl1_slow_rt_rate_10000msDeath/Not Me,Life/Me_bl2_slow_rt_rate_10000msLife/Not Me,Death/Me_bl2_slow_rt_rate_10000ms
subjnum
20000000
30000000
40000000
50000000
60000000
\n", "
" ], "text/plain": [ " overall_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl1_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl1_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl2_slow_rt_rate_10000ms \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl2_slow_rt_rate_10000ms \n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,28:35].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Column 35 contains the number of blocks" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
num_blocks
subjnum
24
34
44
54
64
\n", "
" ], "text/plain": [ " num_blocks\n", "subjnum \n", "2 4\n", "3 4\n", "4 4\n", "5 4\n", "6 4" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,35].to_frame().head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Next 22 columns contain whether a poor performance criterion\\cutoff was flagged - across error rates, too fast rates, too slow rates, and number of blocks" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
overall_error_rate_flagDeath/Not Me,Life/Me_error_rate_flagLife/Not Me,Death/Me_error_rate_flagDeath/Not Me,Life/Me_bl1_error_rate_flagLife/Not Me,Death/Me_bl1_error_rate_flagDeath/Not Me,Life/Me_bl2_error_rate_flagLife/Not Me,Death/Me_bl2_error_rate_flagoverall_fast_rt_rate_400ms_flagDeath/Not Me,Life/Me_fast_rt_rate_400ms_flagLife/Not Me,Death/Me_fast_rt_rate_400ms_flag...Death/Not Me,Life/Me_bl2_fast_rt_rate_400ms_flagLife/Not Me,Death/Me_bl2_fast_rt_rate_400ms_flagoverall_slow_rt_rate_10000ms_flagDeath/Not Me,Life/Me_slow_rt_rate_10000ms_flagLife/Not Me,Death/Me_slow_rt_rate_10000ms_flagDeath/Not Me,Life/Me_bl1_slow_rt_rate_10000ms_flagLife/Not Me,Death/Me_bl1_slow_rt_rate_10000ms_flagDeath/Not Me,Life/Me_bl2_slow_rt_rate_10000ms_flagLife/Not Me,Death/Me_bl2_slow_rt_rate_10000ms_flagnum_blocks_flag
subjnum
20000000000...0000000000
30000000000...0000000000
40000000000...0000000000
50000000000...0000000000
60000000000...0000000000
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ " overall_error_rate_flag Death/Not Me,Life/Me_error_rate_flag \\\n", "subjnum \n", "2 0 0 \n", "3 0 0 \n", "4 0 0 \n", "5 0 0 \n", "6 0 0 \n", "\n", " Life/Not Me,Death/Me_error_rate_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl1_error_rate_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl1_error_rate_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl2_error_rate_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl2_error_rate_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " overall_fast_rt_rate_400ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_fast_rt_rate_400ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_fast_rt_rate_400ms_flag ... \\\n", "subjnum ... \n", "2 0 ... \n", "3 0 ... \n", "4 0 ... \n", "5 0 ... \n", "6 0 ... \n", "\n", " Death/Not Me,Life/Me_bl2_fast_rt_rate_400ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl2_fast_rt_rate_400ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " overall_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl1_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl1_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Death/Not Me,Life/Me_bl2_slow_rt_rate_10000ms_flag \\\n", "subjnum \n", "2 0 \n", "3 0 \n", "4 0 \n", "5 0 \n", "6 0 \n", "\n", " Life/Not Me,Death/Me_bl2_slow_rt_rate_10000ms_flag num_blocks_flag \n", "subjnum \n", "2 0 0 \n", "3 0 0 \n", "4 0 0 \n", "5 0 0 \n", "6 0 0 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,36:58].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Column 58 contains total number of any poor performance crierion\\cuttoff flags participant received. If 0, participant had okay performance." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
iat_flag
subjnum
20
30
40
50
60
\n", "
" ], "text/plain": [ " iat_flag\n", "subjnum \n", "2 0\n", "3 0\n", "4 0\n", "5 0\n", "6 0" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,58].to_frame().head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### Columns 59-62 contain D scores for early and late trials and a final overall weighted D score" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dscore1dscore2dscore
subjnum
2-0.6646550.055078-0.304788
30.535351-0.3054400.114955
4-0.0749850.052010-0.011487
50.3618800.0320900.196985
6-0.035555-0.212646-0.124100
\n", "
" ], "text/plain": [ " dscore1 dscore2 dscore\n", "subjnum \n", "2 -0.664655 0.055078 -0.304788\n", "3 0.535351 -0.305440 0.114955\n", "4 -0.074985 0.052010 -0.011487\n", "5 0.361880 0.032090 0.196985\n", "6 -0.035555 -0.212646 -0.124100" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d1.iloc[:,59:62].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Compare D scores with R package \"iat\"\n", "##### https://cran.r-project.org/web/packages/IAT/" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Prepare data to enter into r package - need to have blocks be a string and need to divide data into 2 separate\n", "#dataframes for people that received \"Death,Me\" first and for those that received \"Life,Me\" first. \n", "d['block_str']=d.block.astype(str)\n", "\n", "d1_r_subn=d[(d.condition=='Death/Not Me,Life/Me')&(d.block>4)].subjnum.unique()\n", "d1_r=d[d.subjnum.isin(d1_r_subn)]\n", "d2_r_subn=d[(d.condition=='Life/Not Me,Death/Me')&(d.block>4)].subjnum.unique()\n", "d2_r=d[d.subjnum.isin(d2_r_subn)]\n", "\n", "%R -i d1_r\n", "%R -i d2_r" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%R\n", "dscore_first <- cleanIAT(my_data = d1_r,\n", " block_name = \"block_str\",\n", " trial_blocks = c(\"2\",\"3\", \"5\", \"6\"),\n", " session_id = \"subjnum\",\n", " trial_latency = \"latency\",\n", " trial_error = \"errors\",\n", " v_error = 1, v_extreme = 2, v_std = 1)\n", "\n", "dscore_second <- cleanIAT(my_data = d2_r,\n", " block_name = \"block_str\",\n", " trial_blocks = c(\"2\",\"3\", \"5\", \"6\"),\n", " session_id = \"subjnum\",\n", " trial_latency = \"latency\",\n", " trial_error = \"errors\",\n", " v_error = 1, v_extreme = 2, v_std = 1)\n", "\n", "r_dsc <- rbind(dscore_first, dscore_second)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%R -o dscore_first\n", "%R -o dscore_second\n", "#Then we need to combine the separate dataframes\n", "#One of these the scores are flipped so need to flip back\n", "dscore_second.IAT=dscore_second.IAT*-1\n", "iat_r_dsc=pd.concat([dscore_first,dscore_second])\n", "iat_r_dsc.index=iat_r_dsc.subjnum\n", "iat_r_dsc=iat_r_dsc.sort_index()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### pyiat produces same d-scores as R package iat" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dscoreIAT
subjnum
2-0.304788-0.304788
30.1149550.114955
4-0.011487-0.011487
50.1969850.196985
6-0.124100-0.124100
\n", "
" ], "text/plain": [ " dscore IAT\n", "subjnum \n", "2 -0.304788 -0.304788\n", "3 0.114955 0.114955\n", "4 -0.011487 -0.011487\n", "5 0.196985 0.196985\n", "6 -0.124100 -0.124100" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py_r_iat=pd.concat([d1.dscore,iat_r_dsc.IAT],axis=1)\n", "py_r_iat.head()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dscoreIAT
dscore1.01.0
IAT1.01.0
\n", "
" ], "text/plain": [ " dscore IAT\n", "dscore 1.0 1.0\n", "IAT 1.0 1.0" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Correlation between pyiat (dscore) and R package (IAT) = 1\n", "py_r_iat.corr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### In the pyiat command above, we entered an argument to return fast-slow stats\n", "### This returns total perecentage of too fast and too slow trials across all subjects and only subjects without poor performance flags" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fast_slow_rt
fast_rt_count_all_subs28.000000
fast_rt_pct_all_subs0.012281
slow_rt_count_all_subs0.000000
slow_rt_pct_all_subs0.000000
fast_rt_count_included_subs26.000000
fast_rt_pct_included_subs0.012037
slow_rt_count_included_subs0.000000
slow_rt_pct_included_subs0.000000
\n", "
" ], "text/plain": [ " fast_slow_rt\n", "fast_rt_count_all_subs 28.000000\n", "fast_rt_pct_all_subs 0.012281\n", "slow_rt_count_all_subs 0.000000\n", "slow_rt_pct_all_subs 0.000000\n", "fast_rt_count_included_subs 26.000000\n", "fast_rt_pct_included_subs 0.012037\n", "slow_rt_count_included_subs 0.000000\n", "slow_rt_pct_included_subs 0.000000" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fs1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other options" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### D scores for each stimulus (i.e. each word)\n", "###### Requires each_stim=True and name of the column containing the stimuli in the stimulus column" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [], "source": [ "d2,fs2=pyiat.analyze_iat(d,subject='subjnum',rt='latency',condition='condition',correct='correct'\\\n", " ,cond1='Death/Not Me,Life/Me',cond2='Life/Not Me,Death/Me'\\\n", " ,block='block',blocks=[2,3,5,6],fastslow_stats=True,each_stim=True,stimulus='trial_word')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### D scores for each word as well as standard task-wide error and fast\\slow trial output " ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
AliveBreathingDeadDeceasedDieILivingMineMyselfOtherSelfSuicideTheirThemTheyThrive
subjnum
2-0.9853600.888583-0.9288880.849257-0.5835660.0951830.912821-0.271138-0.582636-0.656637-0.9157181.180729-0.2603720.4092890.346441-0.886016
3-0.228326-1.0936800.546770-0.725671-0.6749540.2341890.1247460.6010940.2637910.6262920.2044741.102111-0.0662740.1067960.5281390.376461
41.2876821.170938-0.0849330.7051470.084087-1.290731-0.473819NaN-1.231712-0.134547-0.0276440.2699010.797983-0.6111501.3678610.225041
50.670642-1.481677-0.1313800.218148-0.085340-0.7115480.2859790.043037-0.705098-0.1861021.1214431.5477840.703224-0.342463-1.156475-0.176667
60.3313650.9554851.175333-1.0992630.2003670.176193-1.6539200.317128-1.264377-0.748313-0.9233711.169169-1.1578340.025647-0.7309811.373918
\n", "
" ], "text/plain": [ " Alive Breathing Dead Deceased Die I \\\n", "subjnum \n", "2 -0.985360 0.888583 -0.928888 0.849257 -0.583566 0.095183 \n", "3 -0.228326 -1.093680 0.546770 -0.725671 -0.674954 0.234189 \n", "4 1.287682 1.170938 -0.084933 0.705147 0.084087 -1.290731 \n", "5 0.670642 -1.481677 -0.131380 0.218148 -0.085340 -0.711548 \n", "6 0.331365 0.955485 1.175333 -1.099263 0.200367 0.176193 \n", "\n", " Living Mine Myself Other Self Suicide Their \\\n", "subjnum \n", "2 0.912821 -0.271138 -0.582636 -0.656637 -0.915718 1.180729 -0.260372 \n", "3 0.124746 0.601094 0.263791 0.626292 0.204474 1.102111 -0.066274 \n", "4 -0.473819 NaN -1.231712 -0.134547 -0.027644 0.269901 0.797983 \n", "5 0.285979 0.043037 -0.705098 -0.186102 1.121443 1.547784 0.703224 \n", "6 -1.653920 0.317128 -1.264377 -0.748313 -0.923371 1.169169 -1.157834 \n", "\n", " Them They Thrive \n", "subjnum \n", "2 0.409289 0.346441 -0.886016 \n", "3 0.106796 0.528139 0.376461 \n", "4 -0.611150 1.367861 0.225041 \n", "5 -0.342463 -1.156475 -0.176667 \n", "6 0.025647 -0.730981 1.373918 " ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2.iloc[:,59:].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unweighted D scores\n", "
\n", "The unweighted algorithm does not require the 'block' or 'blocks' arguments. \n", "
" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [], "source": [ "d3,fs3=pyiat.analyze_iat(d,subject='subjnum',rt='latency',condition='condition',correct='correct'\\\n", " ,cond1='Death/Not Me,Life/Me',cond2='Life/Not Me,Death/Me'\\\n", " ,fastslow_stats=True,weighted=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### This produces less output as it does not report any information on a block basis" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
iat_flagdscore
subjnum
20-0.186741
30-0.028275
400.014719
500.134814
60-0.169741
\n", "
" ], "text/plain": [ " iat_flag dscore\n", "subjnum \n", "2 0 -0.186741\n", "3 0 -0.028275\n", "4 0 0.014719\n", "5 0 0.134814\n", "6 0 -0.169741" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d3.iloc[:,24:].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unweighted D scores for each stimulus" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [], "source": [ "d4,fs4=pyiat.analyze_iat(d,subject='subjnum',rt='latency',condition='condition',correct='correct'\\\n", " ,cond1='Death/Not Me,Life/Me',cond2='Life/Not Me,Death/Me'\\\n", " ,fastslow_stats=True,each_stim=True,stimulus='trial_word',weighted=False)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BreathingDeadDeceasedDieILivingMineMyselfOtherSelfSuicideTheirThemTheyThrive
subjnum
20.255883-1.0142220.509232-0.3903871.2953320.7373790.339328-0.741623-0.449167-0.9595770.780971-0.360803-0.3474740.392907-0.369755
3-0.7376110.064561-1.067423-0.224777-0.587997-0.6786210.402110-0.1837750.5878510.2192460.9493260.7186421.2127480.4372290.442829
40.875262-0.0957170.501377-0.825456-1.0281550.0877350.979749-0.947307-0.5092660.937908-0.6459690.3687240.0178800.718572-0.223557
5-1.5036710.865254-0.5969990.793221-0.866229-0.3375160.9819480.018283-0.0193620.6792101.0267620.5069380.476360-0.821311-0.582995
60.7894360.954122-1.1414690.270374-0.756038-1.6589170.891638-0.968083-0.980864-0.7312481.212799-0.793774-0.172779-0.7122421.247653
\n", "
" ], "text/plain": [ " Breathing Dead Deceased Die I Living \\\n", "subjnum \n", "2 0.255883 -1.014222 0.509232 -0.390387 1.295332 0.737379 \n", "3 -0.737611 0.064561 -1.067423 -0.224777 -0.587997 -0.678621 \n", "4 0.875262 -0.095717 0.501377 -0.825456 -1.028155 0.087735 \n", "5 -1.503671 0.865254 -0.596999 0.793221 -0.866229 -0.337516 \n", "6 0.789436 0.954122 -1.141469 0.270374 -0.756038 -1.658917 \n", "\n", " Mine Myself Other Self Suicide Their Them \\\n", "subjnum \n", "2 0.339328 -0.741623 -0.449167 -0.959577 0.780971 -0.360803 -0.347474 \n", "3 0.402110 -0.183775 0.587851 0.219246 0.949326 0.718642 1.212748 \n", "4 0.979749 -0.947307 -0.509266 0.937908 -0.645969 0.368724 0.017880 \n", "5 0.981948 0.018283 -0.019362 0.679210 1.026762 0.506938 0.476360 \n", "6 0.891638 -0.968083 -0.980864 -0.731248 1.212799 -0.793774 -0.172779 \n", "\n", " They Thrive \n", "subjnum \n", "2 0.392907 -0.369755 \n", "3 0.437229 0.442829 \n", "4 0.718572 -0.223557 \n", "5 -0.821311 -0.582995 \n", "6 -0.712242 1.247653 " ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d4.iloc[:,26:].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### There are a few more options, including (1) setting the too fast\\too slow threshold, (2) setting the cutoffs for flags, (3) reporting errors and too fast\\slow trial counts instead of percentages (4) printing the output to an excel spreadsheet. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Brief IAT (BIAT)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "pyiat can also produce D scores and poor performance flags for the Brief IAT (BIAT), according to Nosek, et al., 2014 scoring procedures (trials greater than 2 sec are changed to 2 sec, trials less than 400ms are changed to 400ms), with some options. The first x (default 4) trials of each block can be removed or not or you can determine how many trials should be removed from the beginning of each block, if any. You can set the pct flags. One issue with BIAT flags in pyiat is that currently flags for fast and slow trials use the same cutoff pct. Recommended scoring procedures (Nosek et al. 2014) recommend a flag for fast trials but not slow. This is not currently possible in pyiat. However, you can see the pct of slow and fast trials and create your own flags from this information. \n", "
\n", "\n", "
\n", "The BIAT code can take either 2, 4, or 6 blocks (depending what is listed in the blocks argument) and will dynamically adjust to however many blocks it is given. \n", "
\n", "\n", "
\n", "Results of pyiat BIAT D scores were checked against D scores sent to me from U of Virginia. \n", "
\n" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": true }, "outputs": [], "source": [ "bd=pd.read_csv('biat_data.csv',index_col=0)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
block_numpairtrl_numberwordrespRTerrorssubn
200(unnamed)/Life,Me/Death0DieMe/Death77101
210(unnamed)/Life,Me/Death1SuicideMe/Death39301
220(unnamed)/Life,Me/Death2Alive(unnamed)/Life85901
230(unnamed)/Life,Me/Death3Thrive(unnamed)/Life80901
240(unnamed)/Life,Me/Death4Living(unnamed)/Life58501
\n", "
" ], "text/plain": [ " block_num pair trl_number word resp \\\n", "20 0 (unnamed)/Life,Me/Death 0 Die Me/Death \n", "21 0 (unnamed)/Life,Me/Death 1 Suicide Me/Death \n", "22 0 (unnamed)/Life,Me/Death 2 Alive (unnamed)/Life \n", "23 0 (unnamed)/Life,Me/Death 3 Thrive (unnamed)/Life \n", "24 0 (unnamed)/Life,Me/Death 4 Living (unnamed)/Life \n", "\n", " RT errors subn \n", "20 771 0 1 \n", "21 393 0 1 \n", "22 859 0 1 \n", "23 809 0 1 \n", "24 585 0 1 " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bd.head()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [], "source": [ "biatd1,biatfsl=pyiat.analyze_iat(bd,subject='subn',rt='RT',condition='pair',\\\n", " correct='errors',error_or_correct='error'\\\n", " ,cond2='(unnamed)/Death,Me/Life',cond1='(unnamed)/Life,Me/Death'\\\n", " ,block='block_num',blocks=[0, 1, 2, 3,4,5],biat=True,biat_rmv_xtrls=4,biat_trl_num='trl_number',fastslow_stats=True)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
iat_flagdscore1dscore2dscore3dscore
subn
120.390122NaNNaNNaN
20-0.224629-0.566525-0.306011-0.365722
320.367767-0.031676-0.2792950.018932
44-0.2884850.420364-0.402823-0.090315
51-0.6169050.714779NaNNaN
\n", "
" ], "text/plain": [ " iat_flag dscore1 dscore2 dscore3 dscore\n", "subn \n", "1 2 0.390122 NaN NaN NaN\n", "2 0 -0.224629 -0.566525 -0.306011 -0.365722\n", "3 2 0.367767 -0.031676 -0.279295 0.018932\n", "4 4 -0.288485 0.420364 -0.402823 -0.090315\n", "5 1 -0.616905 0.714779 NaN NaN" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "biatd1.iloc[:,-5:].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### D scores for each stimulus (i.e. each word)\n", "
\n", "D scores can be obtained for each word in the BIAT as well but if you choose weighted, it will result in odd\\repeated values, assumedly b/c words are presented a single time in a block. \n", "
" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [], "source": [ "biatd1stim,biatfslstim=pyiat.analyze_iat(bd,subject='subn',rt='RT',condition='pair',\\\n", " correct='errors',error_or_correct='error'\\\n", " ,cond2='(unnamed)/Death,Me/Life',cond1='(unnamed)/Life,Me/Death'\\\n", " ,block='block_num',blocks=[0, 1, 2, 3,4,5],biat=True,biat_rmv_xtrls=4,\\\n", " biat_trl_num='trl_number',fastslow_stats=True,each_stim=True,stimulus='word',weighted=False)" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
BreathingDeadDeceasedDieILivingMineMyselfOtherSelfSuicideTheirThemTheyThrive
subn
11.4142141.4142141.4142141.414214-1.4142141.4142141.414214-1.414214-1.4142141.4142141.414214-1.4142141.4142141.414214-1.414214
2-0.8567180.581147-0.721409-0.137757-1.248524-1.2856480.0777230.2340200.8306990.2461060.283150-0.460540-1.554008-0.419208-1.388049
3-1.1939730.6385400.026860-0.483864-0.7713231.1653620.273211-0.869386-0.863290-0.6759660.4815880.2925790.312901-0.9404510.669422
4-0.4244510.612571-0.386662-0.720745-0.253506-0.461442-0.3872811.0447360.304453-1.085809-0.3145660.2203120.0740560.1121520.327524
5-0.9878240.9330221.2396510.2416051.0542121.450163-0.9707430.835395-0.417985-1.1341780.5181890.9938710.608800-1.1631361.319345
\n", "
" ], "text/plain": [ " Breathing Dead Deceased Die I Living Mine \\\n", "subn \n", "1 1.414214 1.414214 1.414214 1.414214 -1.414214 1.414214 1.414214 \n", "2 -0.856718 0.581147 -0.721409 -0.137757 -1.248524 -1.285648 0.077723 \n", "3 -1.193973 0.638540 0.026860 -0.483864 -0.771323 1.165362 0.273211 \n", "4 -0.424451 0.612571 -0.386662 -0.720745 -0.253506 -0.461442 -0.387281 \n", "5 -0.987824 0.933022 1.239651 0.241605 1.054212 1.450163 -0.970743 \n", "\n", " Myself Other Self Suicide Their Them They \\\n", "subn \n", "1 -1.414214 -1.414214 1.414214 1.414214 -1.414214 1.414214 1.414214 \n", "2 0.234020 0.830699 0.246106 0.283150 -0.460540 -1.554008 -0.419208 \n", "3 -0.869386 -0.863290 -0.675966 0.481588 0.292579 0.312901 -0.940451 \n", "4 1.044736 0.304453 -1.085809 -0.314566 0.220312 0.074056 0.112152 \n", "5 0.835395 -0.417985 -1.134178 0.518189 0.993871 0.608800 -1.163136 \n", "\n", " Thrive \n", "subn \n", "1 -1.414214 \n", "2 -1.388049 \n", "3 0.669422 \n", "4 0.327524 \n", "5 1.319345 " ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#The first subject had only one block and you can see the repeated numbers\n", "biatd1stim.iloc[:,-15:].head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "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.5.3" } }, "nbformat": 4, "nbformat_minor": 0 }