Reaction Times

[Home]   [Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

 

Available Now

Search

Google
 

Search WWW             

Search delphiforfun.org

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Help support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

Google
 

Search WWW

Search delphiforfun.org

 

 

 

Problem Description

Here's a program to test a subject's reaction time by measuring the time between showing a target on the screen and receiving a response indicating that the subject has seen it.  Response may be a mouse click or a key press.   Seems like a great candidate for a Science Fair project.

An option allows the "administrator" to manage trial definitions - size, shape, and color of the target, background color, number of samples per trial, etc.    Multiple trial definitions can be made and each can be marked as active or inactive.     Results are written to a data file for later analysis.

Background & Techniques

The program  was conceived while reading an article about how nerve impulses are transmitted.    Many questions come to mind:  Does reaction time depend on age?  sex?  which hand is used to click?  What about covering one eye?   Target size, color, shape?  If I clicked with a toe instead of a finger?   Converse with or otherwise distract the subject while taking the test?

Here's the basic idea - we'll define a set of parameters defining a trial type (in a TTrialDefObj object) and use the data to control each test.  The trial will start with a blank screen and delay for a random amount of time before displaying a target.  We'll record the time when the target is displayed and again when a response is obtained either by a mouse click or a key press.    The difference is the reaction time for that sample.   When the response is received, we'll erase the target and start the time delay again.   

Timing uses the QueryPerformanceCounter and QueryPerformanceFrequency functions from the Windows API (Applications Program Interface) to get good time resolution.    Use the Windows SDK help button to get more information.

The  reaction times are  accumulated along with  the sum of the squares of the reaction times (we'll discuss why in a minute).  We'll also save the longest and shortest reaction times.    Results will be appended to a comma delimited text (with default name ReactionTimes.rsp) for future analysis.  Addendum - A file of detail time records may also be created, one line for each  response within a trial, preceded by a header line identifying the date/time of the trial, etc.

An original oversight allowed the subject to anticipate the target and press early.   When the target popped up, I  recorded a 0 time.   This was fixed by adding a mode variable to keep track of whether we are waiting for the target or have already displayed.    If a key or mouse press comes in when the target is not displayed, we'll "punish" the subject by displaying  a messagebox requiring him to click OK.   We'll also keep track of these "earlycounts" since we may want to disregard those trials during the analysis. 

A Userid variable is solicited at startup time or via a menu option.  Userid is saved with the reaction time data.

Init File - Reactions.ini

Each trial definition is saved as a Section in an init file created using the TIniFile component.   Trial ids are used as as section names.  

 Fields in each section are:

NbrSamples - number of samples in a trial
Description   - descriptive string to display for user
FixedTargetPosition  - Boolean indicator of whether target may move from sample to sample.    
TargetShape - ordinal  - 2=Ellipse, 1=Rectangle or 0=Rounded Rectangle
XMinsizePct - smallest target width as % of display area width
XmaxsizePct - largest target width as % of display area width
YMinsizePct - smallest target height as % of display area height
YmaxsizePct - largest target height as % of display area height
TargetColor  - 
MinDelay - minimum delay seconds between response and next target
MaxDelay - maximum delay seconds between response and next target 
BgColor - background color
Active - Boolean - true ==> make this trial available for user selection.

 

Results Summary file - ReactionTimes.rsp 

A comma separated text file record is created at the end of each trial.  Fields saved are:

User - user id

Trial - trial id

Date_Time - date and time that trial ended

Samples - number of sample recorded

Longest -  longest response time seconds

Shortest - shortest response time seconds

Total - sum of the response times

Sum_Squares - sum of the squares of response times

Early_count - count of times that user pressed before the target display

 

The first line of the file contains field names separated by commas.

Analyzing results 

Most of the questions about results can be answered by comparing the mean reaction times  from two sets of trials that differ in a single variable.   In statistics,  these are called tests of hypotheses,  definitely a non-trivial subject.  A Math Topics page is in the works that will describe the math necessary to answer these questions.  I'll plan to include a program using reaction time data to illustrate the process.   In the meantime,  a Google search search on "test hypotheses" or "student's t-test"  or "compare population means" will get you a head start.   Also, the comma delimited text format of the ReactionTimes.rsp file is suitable for importing into most spreadsheet programs to get started on analysis.     

Addendum: (July 31,2001):  Revised version was posted today which adds:

  • Added transaction detail file reactiondetail.rsd.  
  • Minor revision to reactiontimes.rsp file format to enclose date_time field in double quotes.
  • Writing to summary and detail files is now an admin option.   Also file names may be changed.  Reaction.ini file now includes a [Files] section to retain the options & file names.
  • Early clicks by the user are ignored - not timed or written to files.  "No cheating" message is still given to subject.
  • Two sample statistic programs, DensityPlot and ResponseStats are included in source download.  Executables available as a separate download.   DensityPlot uses the detail response file and TChart component to display a chart of frequency of occurrence of reaction times (called a density plot).    ResponseStats uses Student's t-test to give information about the difference between the averages for two selected sets of samples.   

Addendum January 30,2004:  A European user pointed out that my choice of comma as the field separator for the detail and summary statistics files was not a good one for countries that use commas for  decimal points.  I guess decimal points also substitute for commas in that system.   I added an option to the Administration  dialog to allow choice of delimiters used to separate fields.    A small change was also required to ResponseStats  to replace '*' and ';' delimiters with blanks.    

Addendum April 2, 2006:  About once a year I hear from a high school or college student trying to use ReactionTimes program for a project. This year, it's a high schooler who wants to compare aural vs. visual response times for his Biology II class.   I added  new audio trial option to the program.  While working on the the changes, i found and hopefully fixed a few other functions that either didn't work or were awkward to use.  ResponseStats used to require two input sample selections to perform Student's T test comparing the average response times. It now also accepts a single sample just to display simple statistics. New versions were posted today.

Addendum February 6, 2008:  Sure enough, another student wrote recently asking for help in getting the Frequency plot produced by he Density plot program in some form that she could insert into her project report.  I hadn't even considered that problem, or that most students these days are using computers routinely to prepare reports and documents for school.   The update today adds some additional chart formatting options (frequency or percent chart type, bar heights labeled or not,  actual or cumulative bar heights).   It also add button to print the chart or save it as a bitmap (BMP) file or as a Wimdows Metafile (WMF) file.   Metafiles have the advantage of being much smaller than BMP files and they also may scale better when inserted into Word documents. 

    

August 19, 2008:  An instructor in the biology field wrote recently asking about the using our Reaction  Times application , specifically about the Response Statistics analysis program.  The program allows users to select specific trial  data to form two sample data sets from which we can decide if they are likely from the same population, i.e. are the means of the response times of the two samples the same or different.  She wants to introduce students to statistical testing as is looking at this application as a tool.  I use Student's two sample T test statistics to display the results of the analysis, but had not been displaying the T Statistic values themselves.  With this revision, I do.  I also added text describing in more detail the statistics are  being displayed and their interpretation.

Response Stats download includes some sample tests results.  (Most reaction times tests automatically save results summaries to a file).  The "ResponseTimesAsterisk.rsp" file allows exploration of whether reaction time increases between ages 64 and 69 for a typical male subject (me).    To find out, load the file into ResponseStats2.exe, select the three T1 trials from 2004 as Sample set 1, the two T1 trials run today as Sample set 2 and click  the "Calculate Statistics" button. 

Running/Exploring the Program 

Note:  Downloads include sample reactions.ini,  reactiontimes.rsp, reactiondetail.rsd  and reactionStatsTest.rsd files. 

Suggestions for Further Explorations

April, 2006: Done.  How would response to sounds compare to visual targets?
Maybe  add a "notes" string field to the output files a part of ID information.  Could contain notes about the trial.
Windows file "WIn.ini" contains the decimal  symbol used for the currently running  version of Windows.   This might lead to a better way to avoid field delimiter conflicts for European usage. 

 

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2008, Gary Darby    All rights reserved.