Skip to content

vlt.stats.power.power2sample

  VLT.STATS.POWER.POWER2SAMPLE - Calculate statistical power for a 2-sample test by simulation

    P = VLT.STATS.POWER.POWER2SAMPLE(SAMPLE1, SAMPLE2, DIFFERENCES, ...)

    Calculates the statistical power of a 2-sample test by simulation.

    Inputs:
    - SAMPLE1: A vector of samples.
    - SAMPLE2: A vector of samples.
    - DIFFERENCES: A vector of differences to examine for power.

    Optional Name-Value Pairs:
    - 'test' ('ttest2' | 'kstest2' | 'ranksum' | 'pairedTTest'): The statistical test to use.
      Default is 'ttest2'. For 'pairedTTest', the function uses the MATLAB function
      ttest. Pairs where either value is NaN in the simulated data are removed
      before the test is run.
    - 'alpha' (0 < alpha < 1): The significance level. Default is 0.05.
    - 'numSimulations' (integer > 0): The number of simulations. Default is 10000.
    - 'verbose' (logical): If true, displays progress. Default is true.
    - 'plot' (logical): If true, plots the power curve. Default is true.
    - 'titleText' (string): The title for the plot.
    - 'xLabel' (string): The x-axis label for the plot.
    - 'yLabel' (string): The y-axis label for the plot.

    Output:
    - P: A vector the same size as DIFFERENCES, indicating the fraction of
      simulations where the test yielded a significant difference.

    Example:
      % Generate some data and calculate power
      sample1 = randn(1, 10);
      sample2 = randn(1, 10);
      differences = 0:0.1:1;
      p = vlt.stats.power.power2sample(sample1, sample2, differences, 'test', 'ttest2');

    Example:
      % Load data from an Excel file and calculate power
      % (Assumes the file 'mydata.xls' has columns "Sample 1" and "Sample 2")
      T = readtable('mydata.xls');
      sample1 = T.("Sample 1");
      sample2 = T.("Sample 2");
      differences = 0:0.1:1;
      p = vlt.stats.power.power2sample(sample1, sample2, differences, 'test', 'ttest2');