aboutsummaryrefslogtreecommitdiff
path: root/src/statistics.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-09-22 18:45:59 +0200
committerThomas White <taw@physics.org>2012-02-22 15:26:59 +0100
commit86689720f52423fe6a71f7b893a50af653254e2a (patch)
treed17486c839741d720736a010b9749cf81ccf1f48 /src/statistics.c
parentb80016b05e7583dee6ae3e8db0d1a7036b1d09be (diff)
Fix problems with Pearson correlation
Diffstat (limited to 'src/statistics.c')
-rw-r--r--src/statistics.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/statistics.c b/src/statistics.c
index 38dd898e..78b3f13e 100644
--- a/src/statistics.c
+++ b/src/statistics.c
@@ -444,6 +444,7 @@ double stat_pearson_i(const double *ref1, const double *ref2,
int i = 0;
int ni = num_items(items);
double val;
+ int nacc = 0;
vec1 = malloc(ni*sizeof(double));
vec2 = malloc(ni*sizeof(double));
@@ -460,11 +461,12 @@ double stat_pearson_i(const double *ref1, const double *ref2,
i1 = lookup_intensity(ref1, h, k, l);
i2 = lookup_intensity(ref2, h, k, l);
- vec1[i] = i1;
- vec2[i] = i2;
+ vec1[nacc] = i1;
+ vec2[nacc] = i2;
+ nacc++;
}
- val = gsl_stats_correlation(vec1, 1, vec2, 1, i);
+ val = gsl_stats_correlation(vec1, 1, vec2, 1, nacc);
free(vec1);
free(vec2);
@@ -479,6 +481,7 @@ double stat_pearson_f_ignore(const double *ref1, const double *ref2,
int i = 0;
int ni = num_items(items);
double val;
+ int nacc = 0;
vec1 = malloc(ni*sizeof(double));
vec2 = malloc(ni*sizeof(double));
@@ -488,23 +491,31 @@ double stat_pearson_f_ignore(const double *ref1, const double *ref2,
double i1, i2, f1, f2;
struct refl_item *it;
signed int h, k, l;
+ int ig = 0;
it = get_item(items, i);
h = it->h; k = it->k; l = it->l;
i1 = lookup_intensity(ref1, h, k, l);
- if ( i1 < 0.0 ) continue;
+ if ( i1 < 0.0 ) {
+ ig=1;
+ }
f1 = sqrt(i1);
i2 = lookup_intensity(ref2, h, k, l);
- if ( i2 < 0.0 ) continue;
+ if ( i2 < 0.0 ) {
+ ig=1;
+ }
f2 = sqrt(i2);
- vec1[i] = f1;
- vec2[i] = f2;
+ if ( ig ) continue;
+
+ vec1[nacc] = f1;
+ vec2[nacc] = f2;
+ nacc++;
}
- val = gsl_stats_correlation(vec1, 1, vec2, 1, i);
+ val = gsl_stats_correlation(vec1, 1, vec2, 1, nacc);
free(vec1);
free(vec2);
@@ -519,6 +530,7 @@ double stat_pearson_f_zero(const double *ref1, const double *ref2,
int i = 0;
int ni = num_items(items);
double val;
+ int nacc = 0;
vec1 = malloc(ni*sizeof(double));
vec2 = malloc(ni*sizeof(double));
@@ -537,12 +549,13 @@ double stat_pearson_f_zero(const double *ref1, const double *ref2,
i2 = lookup_intensity(ref2, h, k, l);
f2 = i2 > 0.0 ? sqrt(i2) : 0.0;
- vec1[i] = f1;
- vec2[i] = f2;
+ vec1[nacc] = f1;
+ vec2[nacc] = f2;
+ nacc++;
}
- val = gsl_stats_correlation(vec1, 1, vec2, 1, i);
+ val = gsl_stats_correlation(vec1, 1, vec2, 1, nacc);
free(vec1);
free(vec2);