#stats_test <- function ( ) #*****************************************************************************80 # ## stats_test() tests stats(). # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 11 May 2021 # # Author: # # John Burkardt # #{ source ( "/home/burkardt/public_html/r_src/persistence/stats.R" ) cat ( date ( ), "\n" ) cat ( '\n' ) cat ( 'stats_test():\n' ) cat ( " ", version$version.string, "\n" ) cat ( ' Test stats(), with the interface:\n' ) cat ( ' [n,sum,min,mean,max,var,std] = stats(x)\n' ) cat ( '\n' ) cat ( ' Call 10 times with random values\n' ) cat ( ' Compare results with vector calculation.\n' ) # # Get a vector of random numbers. # n2 = 10 x2 = runif ( n2 ) # # Because we have all the data at once, we can call an R function for # each statistic. # x_sum2 = sum ( x2 ) x_min2 = min ( x2 ) x_mean2 = mean ( x2 ) x_max2 = max ( x2 ) x_var2 = var ( x2 ) x_std2 = sd ( x2 ) # # Initialize stats. # Call once for each value, updating statistics each time. # Request final statistics. # stats ( ) for ( i in 1 : n2 ) { x <- x2[i] stats ( x ) } output <- stats ( Inf ) # # Unpack the output. # n <- output[1] x_sum <- output[2] x_min <- output[3] x_mean <- output[4] x_max <- output[5] x_var <- output[6] x_std <- output[7] # # Compare. # cat ( '\n' ) cat ( ' n1 = ', n, ', n2 = ', n2, '\n' ); cat ( ' sum1 = ', x_sum, ', sum2 = ', x_sum2, '\n' ); cat ( ' min1 = ', x_min, ', min2 = ', x_min2, '\n' ); cat ( ' mean1 = ', x_mean, ', mean2 = ', x_mean2, '\n' ); cat ( ' max1 = ', x_max, ', max2 = ', x_max2, '\n' ); cat ( ' var1 = ', x_var, ', var2 = ', x_var2, '\n' ); cat ( ' std1 = ', x_std, ', std2 = ', x_std2, '\n' ); # # Terminate. # cat ( "\n" ) cat ( "stats_test():\n" ) cat ( " Normal end of execution.\n" ) cat ( date ( ), "\n" ) quit ( ) #}