Statistics Demo Experiment Run Experiment

Statistics

Jaap Murre

Demo of built-in statistics functions


There are a number of built-in basic statistics functions, such as mean and variance. These take an array of numbers as argument and return a single Number value. To avoid confusion with other functions, they must always be prefixed with stat, as in stat.mean(arr), where arr is an array of Numbers.

  • stat.mean()
    • Average
  • stat.median()

    • Median
  • stat.stddev()

    • Standard deviation
  • stat.stderr()

    • Standard error
  • stat.variance()

    • Variance
  • stat.sumsqerr()

    • Sum of squared errors (i.e., sume of squared deviations from mean)
  • stat.min()

    • Lowest value
  • stat.max()

    • Highest value
  • stat.range()

    • Difference between highest and lowest value

If you are a registered user and signed in, you can here copy this script and its stimuli to your own account, where you can edit it and change it in any way you want.

It is absolutely free to register (no credit card info asked!). You can then instantly copy this experiment with one click and edit it, change its accompanying texts, its landing page, stimuli, etc. Invite your colleagues, friends, or students to check out your experiment. There is no limit on how many people can do your experiment, even with a free account.

The catch? There is no catch! Just keep in mind that with a free account, you cannot collect data. For teaching that is usually not a problem. For research, prepaid data collection (unlimited subjects) starts as low as €10.00 for a 10-day period.

var arr = [2,1,4,6,1,3], 
    arr_m = stat.mean(arr),
    arr_sd = stat.stddev(arr);

// Use toFixed(n) to convert a Number to text with n decimals
// Don't use it before further calculations as it returns a text string
text("Average: " + arr_m.toFixed(2));
await(2000);
text("Standard Dev: " + arr_sd.toFixed(2));
await(2000);

/*

The following functions take an array as an argument and return one value

stat.mean()
Average

stat.median()
Median

stat.stddev()
Standard deviation

stat.stderr()
Standard error

stat.variance()
Variance

stat.sumsqerr()
Sum of squared errors (i.e., sume of squared deviations from mean)

stat.min()
Lowest value

stat.max()
Highest value

stat.range()
Difference between highest and lowest value

*/


// Square root, sin, round, etc. are already in Javascript in the Math library
// E.g., see https://www.w3schools.com/js/js_math.asp

var x = Math.sqrt(100);

text("sqrt(100): " + x);
await(2000);

You can download the files as follows: Click on the file (link) and then right-click and choose Save as... from the menu. Some media files (e.g., sound) will have a download button for this purpose.

This experiment has no files of this type
This experiment has no files of this type
This experiment has no files of this type
This experiment has no YouTube links
This experiment has no files of this type