forked from personal/squiggle.c
display # of values above and below 90% confidence interval
This commit is contained in:
parent
2744136d68
commit
3e2eb69e3a
|
@ -334,8 +334,13 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
|
|||
double bin_width = range / n_bins;
|
||||
|
||||
// Fill the bins with sample counts
|
||||
int below_min = 0, above_max = 0;
|
||||
for (int i = 0; i < n_samples; i++) {
|
||||
if((x[i] > min_value) && (x[i] < max_value)){
|
||||
if(x[i] < min_value){
|
||||
below_min++;
|
||||
}else if (x[i] > max_value){
|
||||
above_max++;
|
||||
}else{
|
||||
int bin_index = (int)((xs[i] - min_value) / bin_width);
|
||||
if (bin_index == n_bins) {
|
||||
bin_index--; // Last bin includes max_value
|
||||
|
@ -355,16 +360,17 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
|
|||
double scale = max_bin_count > MAX_WIDTH ? (double)MAX_WIDTH / max_bin_count : 1.0;
|
||||
|
||||
// Print the histogram
|
||||
for (int i = 0; i < n_bins; i++) {
|
||||
double bin_start = min_value + i * bin_width;
|
||||
double bin_end = bin_start + bin_width;
|
||||
|
||||
int decimalPlaces = 1;
|
||||
if((0 < bin_width) && (bin_width < 1)){
|
||||
int magnitude = (int) floor(log10(bin_width));
|
||||
decimalPlaces = -magnitude;
|
||||
decimalPlaces = decimalPlaces > 10 ? 10 : decimalPlaces;
|
||||
}
|
||||
printf( " (-∞, %*.*f): %d\n", 4+decimalPlaces, decimalPlaces, min_value, below_min);
|
||||
for (int i = 0; i < n_bins; i++) {
|
||||
double bin_start = min_value + i * bin_width;
|
||||
double bin_end = bin_start + bin_width;
|
||||
|
||||
printf(" [%*.*f, %*.*f", 4+decimalPlaces, decimalPlaces, bin_start, 4+decimalPlaces, decimalPlaces, bin_end);
|
||||
char interval_delimiter = ')';
|
||||
if(i == (n_bins-1)){
|
||||
|
@ -378,6 +384,7 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
|
|||
}
|
||||
printf(" %d\n", bins[i]);
|
||||
}
|
||||
printf( " (%*.*f, +∞): %d\n", 4+decimalPlaces, decimalPlaces, max_value, above_max);
|
||||
|
||||
// Free the allocated memory for bins
|
||||
free(bins);
|
||||
|
|
Loading…
Reference in New Issue
Block a user