Workshop 3: Data Analysis and Plotting

Data analysis tools

  • Basic statistics
    • Averages and variability:
      x=randn(20,1);
      mean(x)
      median(x)
      mode(x)
      std(x)
      var(x)
  • T-tests
    • Paired:
      [h, p, ci, stats] = ttest(x – y) or ttest(x)
    • Unpaired:
      [h, p, ci, stats] = ttest2(x, y)
  • ANOVA
    • One-way:
      [p, table, stats] = anova1(x)

      • Where x is a matrix with each column = a group
    • Two-way:
      [p, table, stats] = anova2(x)

      • Where x is a matrix with each columns = factor1 and rows = factor2
    • N-way:
      anovan.m
    • Repeated measures and mixed ANOVAs (not built in)
      RMAOV1.m, RMAOV2.m, RMAOV31.m, RMAOV32.m, RMAOV33.m, BWAOV2.m (between & within factors)
  • Correlations and regression
    • [r p] = corr(x, y) (x and y must be column vectors)
      [b, bint, r, rint, stats] = regress(y, x) (y is a column vector and x is a matrix of column vectors = predictors)
      stepwise(x, y) produces an interactive figure for stepwise regression (x is a matrix of column vectors, y is a column vector)
      p = polyfit(x, y, n) where x and y are column vectors, n is the degree of polynomial (1=line); returns vector of coefficients corresponding to x^n, x^(n-1), …, x, 1.

Additional analysis tools

  • Principal components analysis
    [coeff, score, latent, tsquare] = princomp(x)

Basic plotting tools

  • Scatterplots and line plots:
    x = rand(10,1); y = rand(size(x));
    plot(x, y);
    plot(x, y, ‘g*-’, ‘linewidth’,4)
    plot(x, y, ‘ro‘);
    ye = .2*rand(size(x));
    errorbar(x, y, ye, ‘.’)
  • Bar graphs:
    bar(y)
  • 3D plots:
    x = rand(10,1); y = rand(size(x)); z = rand(size(x));
    plot3(x, y, z,’*’);
    m = rand(5,5);
    bar3(m)
  • Adding text, titles, and labels:
    text(.3, .3, ‘Hello’, ‘fontsize’, 16);
    xlabel(‘Whatever’);
    ylabel(‘Something else’)
    title(‘Anything’,’fontsize’,20)
  • Modifying axis properties:
    errorbar(x, y, ye, ‘.’)
    axis([-1 3 -1 3]);
    axis equal
    axis off
    box off
    set(gca, ‘xtick’, [.1:.2:30])
    set(gca,’xticklabel’, [1:6:400])