{cat("--------------- Descriptive Statistics ---------------\n");T}
{
# Function: mean
# Data: test.mat; a test data set suggested by Leland Wilkinson in 
#      Statistic's Statistics Quiz (1985). 
# Reference(s): Sawitzki, G. 1993. Numerical Reliability of Data Analysis 
#      Systems. submitted for publication in Computational Statistics 
#      and Data Analysis.
# Description: test mean for numeric data
tol <- 1e-6
test.mat <- matrix(c(1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,0,0,99999991,99999992,
     99999993,99999994,99999995,99999996,99999997,99999998,99999999,
     0.99999991,0.99999992,0.99999993,0.99999994,0.99999995,0.99999996,
     0.99999997,0.99999998,0.99999999,1e+12,2e+12,3e+12,4e+12,5e+12,6e+12,
     7e+12,8e+12,9e+12,1e-12,2e-12,3e-12,4e-12,5e-12,6e-12,7e-12,8e-12,9e-12, 
     0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5),ncol=7,dimnames=list(NULL,c("X",
     "Zero","Big","Little","Huge","Tiny","Round")))
test.mean <- matrix(0,1,7)
test.mean[1] <- mean(test.mat[,1])
test.mean[2] <- mean(test.mat[,2])
test.mean[3] <- mean(test.mat[,3])
test.mean[4] <- mean(test.mat[,4])
test.mean[5] <- mean(test.mat[,5])
test.mean[6] <- mean(test.mat[,6])
test.mean[7] <- mean(test.mat[,7])
all(c(test.mean[1] == 5,
      test.mean[2] == 0,
      test.mean[3] == 99999995,
      test.mean[4] == 0.99999995,
      test.mean[5] == 5.0e+12,
      test.mean[6] == 5.0e-12,
      test.mean[7] == 4.5))
}
{
# Function(s): median
# Data: test.mat; a test data set suggested by Leland Wilkinson in
#      Statistic's Statistics Quiz (1985).
# Reference(s): Sawitzki, G. 1993. Numerical Reliability of Data Analysis
#      Systems. submitted for publication in Computational Statistics
#      and Data Analysis.
# Description: test median for numeric data, continued from previous test
tol <- 1e-6
test.med <- matrix(0,1,7)
test.med[1] <- median(test.mat[,1])
test.med[2] <- median(test.mat[,2])
test.med[3] <- median(test.mat[,3])
test.med[4] <- median(test.mat[,4])
test.med[5] <- median(test.mat[,5])
test.med[6] <- median(test.mat[,6])
test.med[7] <- median(test.mat[,7])
all(c(test.med[1] == 5,
      test.med[2] == 0,
      test.med[3] == 99999995,
      test.med[4] == 0.99999995,
      test.med[5] == 5.0e+12,
      test.med[6] == 5.0e-12,
      test.med[7] == 4.5))
}
{
# Function(s): var
# Data: test.mat; a test data set suggested by Leland Wilkinson in
#      Statistic's Statistics Quiz (1985).
# Reference(s): Sawitzki, G. 1993. Numerical Reliability of Data Analysis
#      Systems. submitted for publication in Computational Statistics
#      and Data Analysis.
# Description: test variance for numeric data, continued from previous 2 tests 
tol <- 1e-6
test.var <- matrix(0,1,7)
test.var[1] <- var(test.mat[,1])
test.var[2] <- var(test.mat[,2])
test.var[3] <- var(test.mat[,3])
test.var[4] <- var(test.mat[,4])
test.var[5] <- var(test.mat[,5])
test.var[6] <- var(test.mat[,6])
test.var[7] <- var(test.mat[,7])
all(c(abs(test.var[1] - 7.5) < tol,
      test.var[2] == 0,
      abs(test.var[3] - 7.5) < tol,
      abs(test.var[4] - 7.5e-16) < tol,
      abs((test.var[5] - 7.5e+24)/test.var[5]) < tol,
      abs(test.var[6] - 7.5e-24) < tol,
      abs(test.var[7] - 7.5) < tol))
}
{
# Functions: var, sqrt
# Data: test.mat; a test data set suggested by Leland Wilkinson in
#      Statistic's Statistics Quiz (1985).
# Reference(s): Sawitzki, G. 1993. Numerical Reliability of Data Analysis
#      Systems. submitted for publication in Computational Statistics
#      and Data Analysis.
# Description: test standard deviations for numeric data, continued from
#      previous 3 tests
tol <- 2.6e-9
test.var <- matrix(0,1,7)
test.var[1] <- sqrt(var(test.mat[,1]))
test.var[2] <- sqrt(var(test.mat[,2]))
test.var[3] <- sqrt(var(test.mat[,3]))
test.var[4] <- sqrt(var(test.mat[,4]))
test.var[5] <- sqrt(var(test.mat[,5]))
test.var[6] <- sqrt(var(test.mat[,6]))
test.var[7] <- sqrt(var(test.mat[,7]))
all(c(abs(test.var[1] - 2.738612788) < tol,
      test.var[2] == 0,
      abs(test.var[3] - 2.738612788) < tol,
      abs(test.var[4] - 2.738612788e-8) < tol,
      abs(test.var[5] - 2.738612788e+12)/test.var[5] < tol,
      abs(test.var[6] - 2.738612788e-12) < tol,
      abs(test.var[7] - 2.738612788) < tol))
}
{
# Function(s): cor
# Data: Fisher and Van Belle, Example 9.3 p. 374
# Reference: Fisher, L. and G. Van Belle. 1993. Biostatistics: A Methodology
#      for the Health Sciences
# Description: simple correlation coefficient between two vectors
tol <- 1e-3
x.atp <- c(4.18, 5.16, 4.85, 3.43, 4.53, 5.13, 4.10, 4.77, 4.12, 4.65, 6.03,
           5.94, 5.99, 5.43, 5.00, 4.82, 5.25)
y.atp <- c(4.81, 4.98, 4.48, 4.19, 4.27, 4.87, 4.74, 4.53, 3.72, 4.62, 5.83,
           4.40, 4.87, 5.44, 4.70, 4.14, 5.30)
c.test <- cor(x.atp,y.atp)
abs(c.test - 0.597) < tol
}
{
# Clean up after dstats
rm(tol,test.mat,test.mean,test.med,test.var,x.atp,y.atp,c.test)
T
}
