KRIGOLSON TEACHING
  • NEUROSCIENCE
    • NEUROSCIENCE 100 >
      • NEURO 100 INTRODUCTION
      • NEURO 101 ADVANCED
      • NEURO 102 AGING
      • NEURO 103 MEMORY
    • NEURO 500 >
      • 1. THE MOTOR SYSTEM
      • 2 Reflexes and Postural Control
      • 3. Goal Directed Action
      • 4. PERCEPTION
      • 5. ATTENTION
      • 6. MEMORY
      • 7. EXECUTIVE CONTROL
      • 8. LEARNING
      • 9. DECISION MAKING
  • KINESIOLOGY
    • EPHE 245 >
      • COURSE READINGS
      • LABORATORY
      • ADDITIONAL MATERIALS
    • EPHE 380 >
      • COURSE INFORMATION
      • COURSE READINGS
      • In Class Labs
      • LAB >
        • LAB OVERVIEW
        • Lab Schedule
        • How To Write A Research Paper
        • RESEARCH PROJECT
        • POSTER PRESENTATION
    • EPHE 487 / 591
    • EPHE 573
    • EPHE 575
  • STATISTICS
    • LECTURE
    • RESOURCES
    • ASSIGNMENTS >
      • 1. The Basics >
        • 1a. INTRODUCTION TO R
        • 1b. LOADING DATA
        • 1c. DATA FRAMES
      • 2. Descriptive Statistics >
        • 2A. Mean, Median, and Mode
        • 2B. VARIANCE
        • 2C. CONFIDENCE INTERVALS
        • 2D. SHORTCUTS
      • 3. Plotting Data >
        • 3A. PLOTTING BASICS
        • 3B. BAR GRAPHS
        • 3C. BOXPLOTS
        • 3D. HISTOGRAMS
        • 3E USING GGPLOT I
        • 3F USING GGPLOT II
        • 3G USING GGPLOT III
      • 4. Key Concepts >
        • 4A. Sample Size and Variance
        • 4B. DISTRIBUTIONS
        • 4C. TESTING DISTRIBUTIONS
      • 5. T-Tests >
        • 5A Single Sample TTests
        • 5B Paired Sample TTests
        • 5C Independent Sample TTests
      • 6. Correlation and Regression >
        • 6A. CORRELATION
        • 6B. REGRESSION
        • 6C. MULTIPLE REGRESSION
      • 7. ANOVA >
        • 7A ANOVA ASSUMPTIONS
        • 7B ANOVA
        • 7C RM ANOVA
        • 7D TREND ANALYSIS
        • 7E FACTORIAL ANOVA I
      • 9. NON PARAMETRIC STATISTICS >
        • 9A. WILCOXON TEST
        • 9B. WILCOXON SIGNED TEST
        • 9C. MULTIPLE GROUPS
      • 12. ADVANCED CONCEPTS >
        • 12A. BAYESIAN TTESTS
  • Directed Studies
    • Advanced Topics in Motor Control A
    • Advanced Topics in Motor Control B
    • An Introduction to EEG
    • Advanced EEG and ERP Methods
    • Neural Correlates of Human Reward Processing
    • Independent Research Project
  • MATLAB
    • THE BASICS >
      • Hello World
      • BASIC MATHEMATICS
      • VARIABLES
      • Matrices
      • Writing Scripts
      • PATHS AND DIRECTORIES
      • USER INPUT
      • FOR LOOPS
      • WHILE LOOPS
      • IF STATEMENTS
      • RANDOM NUMBERS
    • STATISTICS >
      • LOADING DATA
      • DESCRIPTIVE STATISTICS
      • MAKING FUNCTIONS
      • BAR GRAPHS
      • LINE GRAPHS
      • TTESTS
    • PROGRAMMING EXPERIMENTS >
      • DRAWING A CIRCLE
      • DRAWING MULTIPLE OBJECTS
      • DRAWING TEXT
      • DRAWING AN IMAGE
      • PLAYING A TONE
      • KEYBOARD INPUT
      • BUILDING A TRIAL
      • BUILDING TRIALS
      • NESTED LOOPS
      • RIGHT OR WRONG
      • SAVING DATA
    • ADVANCED TOPICS >
      • STROOP
      • N BACK
      • Animation
      • VIDEO
  • RESOURCES
    • EXCEL
    • HOW TO READ A RESEARCH PAPER
    • HOW TO WRITE A RESEARCH PAPER
  • LAB

TTESTS

Just as it is easy to plot, it is easy to do inferential statistics in MATLAB. However, I want to emphasize that this tutorial is not designed to teach statistics - it is simply designed to show people who already who know statistics how to run tests in MATLAB.

Let's start a new script and go back to our reaction time data. Recall that this data is simulated data of the Stroop task, wherein Condition 1 is congruent words and Condition 2 is incongruent words. Based on the literature, we would expect the mean reaction time for Condition 1 to be shorter than the mean reaction time for Condition 2. 

clc;
clear all;
close all;

my_data = readtable('my_data.txt');
my_data.Properties.VariableNames = {'Subject' 'Condition' 'RT'};

Let's create two new variables isolating the actual data for a paired samples t-test, each persons mean score for each condition:

con1Data = my_data.RT(my_data.Condition == 1);
con2Data = my_data.RT(my_data.Condition == 2);

Paired or Dependent Samples t-test
Now, the t-test is easy. Given the data, this test requires a Paired or Dependent Samples t-test:

[H p CI STATS] = ttest(con1Data,con2Data)

I have deliberately left the semi-colon off the end so you can see the results in the Command Window. This call returns H, the hypothesis (0 = null true, 1 = alternative true). It of course returns a p value. It returns the CI of the mean difference. It also returns STATS which holds the t score, the degrees of freedom, and standard error of the mean.

Single Sample t-test
Let's say that for some reason, we now want to compare the condition 1 data to a known population mean of 300. This would require a single sample t-test since we do not know the population standard deviation.

[H p CI STATS] = ttest(con1Data,300)

Again, the same variables are returned and you should see this test is not significant.

Independent Samples t-test
Let's pretend that con1Data is the incongruent data from one group on a Stroop Task and con2Data is the incongruent data from another group on the Stroop Task. This would now required an independent samples t-test as a dependent samples t-test is inappropriate.

[H p CI STATS] = ttest2(con1Data,con2Data)

You will note you get the same output as before, but now we are using ttest2, which is the MATLAB function for an independent samples t-test.

As I have said, doing inferential statistics in MATLAB is easy.

Things To Do
1. HERE is some data that is more suited for an ANOVA. It reflects mean reaction time scores for three groups (young, middle, old) on a simple reaction time task. See if you can figure out how to use the anova1 function to analyze this data. It is in the same format as your previous RT data so the commands at the top of this tutorial will help you load it but to be statistically correct you should rename Condition as Group.
2. Plot the results of the ANOVA above with error bars. Use a plot style of your choice but customize it to look good.
3. Write a script that does everything covered in the statistics tutorials - load a file, generate descriptive statistics, generate plots, and do a statistical test. This is what we do in my lab.
4. Advanced: Write a script that checks for outliers in your data. This one is not as hard as it sounds - for example, you could use a for loop to check each entry against a known value...
  • NEUROSCIENCE
    • NEUROSCIENCE 100 >
      • NEURO 100 INTRODUCTION
      • NEURO 101 ADVANCED
      • NEURO 102 AGING
      • NEURO 103 MEMORY
    • NEURO 500 >
      • 1. THE MOTOR SYSTEM
      • 2 Reflexes and Postural Control
      • 3. Goal Directed Action
      • 4. PERCEPTION
      • 5. ATTENTION
      • 6. MEMORY
      • 7. EXECUTIVE CONTROL
      • 8. LEARNING
      • 9. DECISION MAKING
  • KINESIOLOGY
    • EPHE 245 >
      • COURSE READINGS
      • LABORATORY
      • ADDITIONAL MATERIALS
    • EPHE 380 >
      • COURSE INFORMATION
      • COURSE READINGS
      • In Class Labs
      • LAB >
        • LAB OVERVIEW
        • Lab Schedule
        • How To Write A Research Paper
        • RESEARCH PROJECT
        • POSTER PRESENTATION
    • EPHE 487 / 591
    • EPHE 573
    • EPHE 575
  • STATISTICS
    • LECTURE
    • RESOURCES
    • ASSIGNMENTS >
      • 1. The Basics >
        • 1a. INTRODUCTION TO R
        • 1b. LOADING DATA
        • 1c. DATA FRAMES
      • 2. Descriptive Statistics >
        • 2A. Mean, Median, and Mode
        • 2B. VARIANCE
        • 2C. CONFIDENCE INTERVALS
        • 2D. SHORTCUTS
      • 3. Plotting Data >
        • 3A. PLOTTING BASICS
        • 3B. BAR GRAPHS
        • 3C. BOXPLOTS
        • 3D. HISTOGRAMS
        • 3E USING GGPLOT I
        • 3F USING GGPLOT II
        • 3G USING GGPLOT III
      • 4. Key Concepts >
        • 4A. Sample Size and Variance
        • 4B. DISTRIBUTIONS
        • 4C. TESTING DISTRIBUTIONS
      • 5. T-Tests >
        • 5A Single Sample TTests
        • 5B Paired Sample TTests
        • 5C Independent Sample TTests
      • 6. Correlation and Regression >
        • 6A. CORRELATION
        • 6B. REGRESSION
        • 6C. MULTIPLE REGRESSION
      • 7. ANOVA >
        • 7A ANOVA ASSUMPTIONS
        • 7B ANOVA
        • 7C RM ANOVA
        • 7D TREND ANALYSIS
        • 7E FACTORIAL ANOVA I
      • 9. NON PARAMETRIC STATISTICS >
        • 9A. WILCOXON TEST
        • 9B. WILCOXON SIGNED TEST
        • 9C. MULTIPLE GROUPS
      • 12. ADVANCED CONCEPTS >
        • 12A. BAYESIAN TTESTS
  • Directed Studies
    • Advanced Topics in Motor Control A
    • Advanced Topics in Motor Control B
    • An Introduction to EEG
    • Advanced EEG and ERP Methods
    • Neural Correlates of Human Reward Processing
    • Independent Research Project
  • MATLAB
    • THE BASICS >
      • Hello World
      • BASIC MATHEMATICS
      • VARIABLES
      • Matrices
      • Writing Scripts
      • PATHS AND DIRECTORIES
      • USER INPUT
      • FOR LOOPS
      • WHILE LOOPS
      • IF STATEMENTS
      • RANDOM NUMBERS
    • STATISTICS >
      • LOADING DATA
      • DESCRIPTIVE STATISTICS
      • MAKING FUNCTIONS
      • BAR GRAPHS
      • LINE GRAPHS
      • TTESTS
    • PROGRAMMING EXPERIMENTS >
      • DRAWING A CIRCLE
      • DRAWING MULTIPLE OBJECTS
      • DRAWING TEXT
      • DRAWING AN IMAGE
      • PLAYING A TONE
      • KEYBOARD INPUT
      • BUILDING A TRIAL
      • BUILDING TRIALS
      • NESTED LOOPS
      • RIGHT OR WRONG
      • SAVING DATA
    • ADVANCED TOPICS >
      • STROOP
      • N BACK
      • Animation
      • VIDEO
  • RESOURCES
    • EXCEL
    • HOW TO READ A RESEARCH PAPER
    • HOW TO WRITE A RESEARCH PAPER
  • LAB
✕