add converstion between lognormal form and 90% c.i.
This commit is contained in:
parent
f1834341a9
commit
0d31a4f1ab
|
@ -345,9 +345,10 @@ It emits one warning about something I already took care of, so by default I've
|
|||
- [x] Add prototypes
|
||||
- [x] Use named structs
|
||||
- [x] Add to header file
|
||||
- [x] Provide example
|
||||
- [x] Provide example algebra
|
||||
- [x] Add conversion between 90% ci and parameters.
|
||||
- [ ] Use that conversion in conjuction with small algebra.
|
||||
- [ ] Test results
|
||||
- [ ] Add conversion between 90% ci and parameters.
|
||||
- [x] Move to own file? Or signpost in file? => signposted in file.
|
||||
- [ ] Disambiguate sample_laplace--successes vs failures || successes vs total trials as two distinct and differently named functions
|
||||
- [ ] Write twitter thread.
|
||||
|
|
25
squiggle.c
25
squiggle.c
|
@ -12,7 +12,8 @@
|
|||
#define EXIT_ON_ERROR 0
|
||||
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
||||
|
||||
const double PI = 3.14159265358979323846; // M_PI in gcc gnu99
|
||||
#define PI 3.14159265358979323846 // M_PI in gcc gnu99
|
||||
#define NORMAL95CONFIDENCE 1.6448536269514722
|
||||
|
||||
// # Key functionality
|
||||
// Define the minimum number of functions needed to do simple estimation
|
||||
|
@ -97,7 +98,6 @@ inline double sample_normal_from_95_confidence_interval(double low, double high,
|
|||
// 5. If we want a 90% confidence interval from high to low,
|
||||
// we can set mean = (high + low)/2; the midpoint, and L = high-low,
|
||||
// Normal([high + low]/2, [high - low]/(2 * 1.6448536269514722))
|
||||
const double NORMAL95CONFIDENCE = 1.6448536269514722;
|
||||
double mean = (high + low) / 2.0;
|
||||
double std = (high - low) / (2.0 * NORMAL95CONFIDENCE);
|
||||
return sample_normal(mean, std, seed);
|
||||
|
@ -504,3 +504,24 @@ lognormal_params algebra_product_lognormals(lognormal_params a, lognormal_params
|
|||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
lognormal_params convert_ci_to_lognormal_params(struct c_i x)
|
||||
{
|
||||
double loghigh = logf(x.high);
|
||||
double loglow = logf(x.low);
|
||||
double logmean = (loghigh + loglow) / 2.0;
|
||||
double logstd = (loghigh - loglow) / (2.0 * NORMAL95CONFIDENCE);
|
||||
lognormal_params result = { .logmean = logmean, .logstd = logstd};
|
||||
return result;
|
||||
}
|
||||
|
||||
struct c_i convert_lognormal_params_to_ci(lognormal_params y)
|
||||
{
|
||||
double h = y.logstd * NORMAL95CONFIDENCE;
|
||||
double loghigh = y.logmean + h;
|
||||
double loglow = y.logmean - h;
|
||||
struct c_i result = { .low=exp(loglow), .high=exp(loghigh)};
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -72,4 +72,10 @@ typedef struct lognormal_params_t {
|
|||
} lognormal_params;
|
||||
lognormal_params algebra_product_lognormals(lognormal_params a, lognormal_params b);
|
||||
|
||||
|
||||
lognormal_params convert_ci_to_lognormal_params(struct c_i x);
|
||||
|
||||
|
||||
struct c_i convert_lognormal_params_to_ci(lognormal_params y);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user