'PROGRAM: descriptiveStatistics.bas
'================= Descriptive Statistics ================
' written by Bruno Schaefer, Losheim am See, Germany
' created: 15.12.2016
' last review: 16.06.2018
'============================================================================================================
' This programm calculates basic descriptive statistics of univariate data:
' n, Std.error, sum, standard error, mean, geometrical mean, variance,
' standard deviation, coefficient of variation, minimum, 1st quartile, median,
' 2rd quartile, maximum,skewness, kurtosis, and excess kurtosis.
' A dataset must have at least 4 values.
' For kurtosis and skewness the same equation as SPSS, PAST and Excel is used.
' Slightly different results may occur using other programs, especially for
' small sample sizes.
' kurtosis: peak shape > 3 (excess > 0) leptokurtic: distribution with tapered peak and fat tails
' = 3 (excess = 0) mesokurtic: similar to normal bell-curved distribution
' < 3 (excess < 0) platykurtic: flat distribution with thin tails
' skewness: symmetry > 0 skewed right: its right tail is longer and most of the distribution is at the left.
' = 0 symmetrical (not skewed)
' < 0 skewed left: the left tail is longer and most of the distribution is at the right
'===============================================================================================================
_TITLE "descriptive statistics" WEITER$ = "y" 'loop variable
PRINT " ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» " PRINT " º DESCRIPTIVE STATISTICS OF UNIVARIATE DATA º " PRINT " ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ " PRINT " number of values (n>3): ";
INPUT "", n
'input of the number of values sample(I) = Wert# ' fills the data array with values
' ----- SORT of the values ----------
ic = 0
IF sample
(I
) > sample
(I
+ 1) THEN h = sample(I)
sample(I) = sample(I + 1)
sample(I + 1) = h
ic = 1
' ----------- calculations and output of the results ------------
PRINT " =========================== RESULTS ==================================" PRINT " n (number of values): "; n
PRINT " sum (sum of values): "; sum#
(sample
()) PRINT " standard error: "; StdDev.s#
(sample
()) / SQR(n
) ' stderr#(sample()) PRINT " mean: "; mean#
(sample
()) PRINT " geometrical mean: "; geomean#
(sample
()) PRINT " root mean square RMS: "; rms#
(sample
()) PRINT " variance (sample): "; variance.s#
(sample
()) PRINT " std.dev. (sample): "; StdDev.s#
(sample
());
" = ";
_ROUND((StdDev.s#
(sample
()) * 100 / mean#
(sample
())) * 100) / 100;
" %" PRINT " coeff. of variation: ";
100 * StdDev.s#
(sample
()) / mean#
(sample
()) PRINT " variance (population): "; variance.p#
(sample
()) PRINT " std.dev. (population): "; StdDev.p#
(sample
());
" = ";
_ROUND((StdDev.p#
(sample
()) * 100 / mean#
(sample
())) * 100) / 100;
" %" PRINT " coefficient of variation: ";
100 * StdDev.p#
(sample
()) / mean#
(sample
()) PRINT " 1st quartile (percentile 25%): "; quantile#
(sample
(), 0.25) PRINT " median (percentile 50%): "; quantile#
(sample
(), 0.50) PRINT " standard error of the median: "; variance.p#
(sample
()) / SQR(n
) PRINT " 3rd quartile (percentile 75%): "; quantile#
(sample
(), 0.75) PRINT " interquartile range: "; quantile#
(sample
(), 0.75) - quantile#
(sample
(), 0.25) PRINT " skewness (sample): ";
_ROUND(skew#
(sample
()) * 100000) / 100000 PRINT " kurtosis (sample): ";
_ROUND(kurt#
(sample
()) * 100000) / 100000 PRINT " excess kurtosis(sample): ";
_ROUND(kurt#
(sample
()) * 100000) / 100000 - 3 PRINT " skewness (population): ";
_ROUND(skew#
(sample
()) * (n
- 2) / SQR(n
* (n
- 1)) * 100000) / 100000 PRINT " kurtosis (population): ";
_ROUND((kurt#
(sample
()) * (n
- 2) * (n
- 3) / (n
- 1) - 6) / (n
+ 1) * 100000) / 100000 PRINT " excess kurtosis (population): ";
_ROUND((kurt#
(sample
()) * (n
- 2) * (n
- 3) / (n
- 1) - 6) / (n
+ 1) * 100000) / 100000 - 3 PRINT " ======================================================================" _CLIPBOARD$ = _CLIPBOARD$ + " excess kurtosis (population): " + STR$(_ROUND((kurt#
(sample
()) * (n
- 2) * (n
- 3) / (n
- 1) - 6) / (n
+ 1) * 100000) / 100000 - 3) + CrLf
PRINT " All results are stored in the clipboard!" PRINT " Do you want to start a new statistical evaluation [y/n]? ";
'FUNCTIONS
'============= sum =========="
s# = 0
s# = s# + x(i)
sum# = s#
'============= mean =========="
mean# = sum#(x()) / n
'========= variance (sample) =========="
m# = mean#(x())
s# = 0
s# = s# + (x(i) - mean#(x())) ^ 2
variance.s# = s# / (n - 1)
'========= variance population) =========="
m# = mean#(x())
s = 0
s# = s# + (x(i) - mean#(x())) ^ 2
variance.p# = s# / n
'======= standard deviation (sample) ========"
StdDev.s#
= SQR(variance.s#
(x
()))'======= standard deviation (population) ========"
StdDev.p#
= SQR(variance.p#
(x
()))'============== median ====================="
'even
median# = (sample(n / 2) + sample((n / 2) + 1)) / 2
'odd
median# = sample((n + 1) / 2)
'============================ quantile ========================
rang# = a * (n - 1) + 1
gewicht# = rang# - index%
quantile# = x(index%) + gewicht# * (x(index% + 1) - x(index%))
'============================ skewness ========================
m# = mean#(x())
s# = StdDev.s#(x())
sk# = 0
sk# = sk# + ((x(J) - m#) / s#) ^ 3
skew# = sk# * (n / ((n - 1) * (n - 2)))
skew# = 0
'============================ kurtosis ========================
m# = mean#(x())
s# = StdDev.s#(x())
krt# = 0
krt# = krt# + ((x(j) - m#) / s#) ^ 4
kurt# = ((krt# * (n + 1) * n) / ((n - 1) * (n - 2) * (n - 3))) - ((3 * (n - 1) ^ 2) / ((n - 2) * (n - 3)))
kurt# = 0
'====================== geometrical mean ========================
gm# = 1
gm# = gm# * x(j)
geomean# = gm# ^ (1 / n)
'============ mean square error ===================
ms# = 0
ms# = ms# + x(j) ^ 2