summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2019-05-17 17:19:57 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2019-05-17 17:19:57 +0100
commit7df02232e97af045abfdc278129f9722be25eaf2 (patch)
tree423ef4ecaf858201eef7e2255416866a42d7007b
parent5f671dafb9e36ea5796bf22caaced54541270040 (diff)
fixup-count
-rw-r--r--ministat.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/ministat.c b/ministat.c
index 94fa996..2a3afe6 100644
--- a/ministat.c
+++ b/ministat.c
@@ -137,7 +137,7 @@ struct dataset {
double *points;
unsigned lpoints;
double sy, syy, median;
- unsigned n, sn;
+ unsigned count, n;
};
static struct dataset *
@@ -156,14 +156,14 @@ AddPoint(struct dataset *ds, double a)
{
double *dp;
- if (ds->n >= ds->lpoints) {
+ if (ds->count >= ds->lpoints) {
dp = ds->points;
ds->lpoints *= 4;
ds->points = calloc(sizeof *ds->points, ds->lpoints);
- memcpy(ds->points, dp, sizeof *dp * ds->n);
+ memcpy(ds->points, dp, sizeof *dp * ds->count);
free(dp);
}
- ds->points[ds->n++] = a;
+ ds->points[ds->count++] = a;
}
static double
@@ -177,14 +177,14 @@ static double
Max(struct dataset *ds)
{
- return (ds->points[ds->n -1]);
+ return (ds->points[ds->count -1]);
}
static double
Avg(struct dataset *ds)
{
- return(ds->sy / ds->sn);
+ return(ds->sy / ds->n);
}
static double
@@ -192,14 +192,14 @@ Median(struct dataset *ds, int low, int high)
{
int mid = (high - low) / 2 + low;
- return (ds->points[mid] + ds->points[ds->n - mid - 1]) / 2;
+ return (ds->points[mid] + ds->points[ds->count - mid - 1]) / 2;
}
static double
Var(struct dataset *ds)
{
- return (ds->syy - ds->sy * ds->sy / ds->sn) / (ds->sn - 1.0);
+ return (ds->syy - ds->sy * ds->sy / ds->n) / (ds->n - 1.0);
}
static double
@@ -213,7 +213,7 @@ tukey(struct dataset *ds, int *low, int *high)
{
int range = *high - *low;
int mid = range / 2 + *low;
- double iqm = (ds->points[mid] + ds->points[ds->n - mid - 1]) / 2;
+ double iqm = (ds->points[mid] + ds->points[ds->count - mid - 1]) / 2;
double iqr = ds->points[(3*range+3)/4 + *low] - ds->points[range/4 + *low];
double lower = iqm - 1.5 * iqr;
double upper = iqm + 1.5 * iqr;
@@ -236,11 +236,11 @@ static double tau(struct dataset *ds)
{
double t;
- if (ds->sn > NSTUDENT + 2)
+ if (ds->n > NSTUDENT + 2)
t = student[0][5];
else
- t = student[ds->sn - 2][5];
- t = t * (ds->sn - 1) / sqrt(ds->sn * (ds->sn - 2 + t * t));
+ t = student[ds->n - 2][5];
+ t = t * (ds->n - 1) / sqrt(ds->n * (ds->n - 2 + t * t));
return t * Stddev(ds);
}
@@ -257,7 +257,7 @@ thompson(struct dataset *ds, int *low, int *high)
ds->sy -= a;
ds->syy -= a * a;
- ds->sn--;
+ ds->n--;
++*low;
return 1;
}
@@ -267,7 +267,7 @@ thompson(struct dataset *ds, int *low, int *high)
ds->sy -= a;
ds->syy -= a * a;
- ds->sn--;
+ ds->n--;
--*high;
return 1;
}
@@ -279,7 +279,7 @@ thompson(struct dataset *ds, int *low, int *high)
static void
FilterOutliers(struct dataset *ds)
{
- int i, low = 0, high = ds->n;
+ int i, low = 0, high = ds->count;
while (tukey(ds, &low, &high))
;
@@ -287,7 +287,7 @@ FilterOutliers(struct dataset *ds)
for (i = low; i < high; i++) {
double a = ds->points[i];
- ds->sn++;
+ ds->n++;
ds->sy += a;
ds->syy += a * a;
}
@@ -310,20 +310,20 @@ Vitals(struct dataset *ds, int flag)
{
printf("%c %3d(%3d) %13.8g %13.8g %13.8g %13.8g %13.8g",
- symbol[flag + 1], ds->n, ds->sn,
+ symbol[flag + 1], ds->count, ds->n,
Min(ds), Max(ds), ds->median, Avg(ds), Stddev(ds));
printf("\n");
}
static double dof(struct dataset *a, struct dataset *b)
{
- double sa = Var(a) / a->sn;
- double sb = Var(b) / b->sn;
+ double sa = Var(a) / a->n;
+ double sb = Var(b) / b->n;
double v;
v = sa + sb;
v *= v;
- v /= sa * sa / (a->sn - 1) + sb * sb / (b->sn - 1);
+ v /= sa * sa / (a->n - 1) + sb * sb / (b->n - 1);
return v;
}
@@ -486,7 +486,7 @@ PlotSet(struct dataset *ds, int val)
m = 1;
i = -1;
j = 0;
- for (n = 0; n < ds->n; n++) {
+ for (n = 0; n < ds->count; n++) {
x = (ds->points[n] - pl->x0) / pl->dx;
if (x == i) {
j++;
@@ -507,7 +507,7 @@ PlotSet(struct dataset *ds, int val)
}
i = -1;
- for (n = 0; n < ds->n; n++) {
+ for (n = 0; n < ds->count; n++) {
x = floor((ds->points[n] - pl->x0) / pl->dx);
if (x == i) {
j++;
@@ -659,12 +659,12 @@ ReadSet(const char *n, int column, const char *delim)
AddPoint(s, d);
}
fclose(f);
- if (s->n < 3) {
+ if (s->count < 7) {
fprintf(stderr,
- "Dataset %s must contain at least 3 data points\n", n);
+ "Dataset %s must contain at least 7 data points\n", n);
return NULL;
}
- qsort(s->points, s->n, sizeof *s->points, dbl_cmp);
+ qsort(s->points, s->count, sizeof *s->points, dbl_cmp);
FilterOutliers(s);
return (s);
}