/* This program helps you make QQ plots, by generating the */ /* quantiles from the desired theoretical distributions. */ /* This version also brings in the empirical data for comparison. */ /* Written by Carey Williamson for CPSC 531 in November 2017 */ /* Usage: cc -o qq qq.c -lm */ /* qq */ #include #include #include /* use man 3 log for the math functions */ #define NUM_DATA_VALUES 1191 #define GRANULARITY 1.0/NUM_DATA_VALUES #define A 10.0 /* left edge of Uniform distribution */ #define B 80.0 /* right edge of Uniform distribution */ #define P 0.1217 /* parameter of Geometric distribution */ #define MU 15.0 /* mean of Exponential distribution */ #define ALPHA 1.0 /* tail index of Pareto distribution */ #define MAX_DATA 10000 int main() { int i, num; float x, value; float datavalues[MAX_DATA]; num = 0; while( scanf("%f\n", &value) > 0 ) { datavalues[num] = value/1024.0; /* convert to KB */ datavalues[num] = value; num++; } #ifdef DEBUG printf("That file had %d values\n", num); #endif x = 0.0; i = 0; while( x <= 1.0 ) { value = A + floor((B-A+1)*x); /* for EquiLikely(A,B) */ value = x; /* for Uniform(0,1) */ value = A + (B-A)*x; /* for Uniform(A,B) */ value += 2.2; value = floor(log(1-x)/log(1-P)); /* for Geometric(P) */ value = 1/pow((1-x), 1/ALPHA); /* for Pareto(ALPHA) */ value = -MU*log(1-x); /* for Exponential(MU) */ printf("%f %f ", value, x); /* Theoretical model values */ printf("%f %f", datavalues[i], 1.0*i/num); /* Empirical data values */ printf("\n"); x += GRANULARITY; i++; } }