|
[Home] [Projects] [Delphi Techniques] [Math Topics] [Library] [Utilities] |
|
|
Problem DescriptionHere'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 & TechniquesThe 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.iniEach 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
Results Summary file - ReactionTimes.rspA 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 resultsMost 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:
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.
Running/Exploring the ProgramNote: Downloads include sample reactions.ini, reactiontimes.rsp, reactiondetail.rsd and reactionStatsTest.rsd files.
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2008, Gary Darby
All rights reserved.
|