43 dbout.
y_end = dbin.y_end;
46 if (ad.maxyear < dbout.
y_end) dbout.
y_end = ad.maxyear;
51 for (row = 0; row < ad.numrecs; row++) {
52 for (year = dbout.
y_start; year <= dbout.
y_end; year++) {
53 setval(dbout, (*f)(
getval(dbin, row, year, ad)), row, year, ad);
74 result.
y_start = a.y_start > b.y_start ? a.y_start : b.y_start;
75 result.
y_end = a.y_end < b.y_end ? a.y_end : b.y_end;
78 if (ad.maxyear < result.
y_end) result.
y_end = ad.maxyear;
81 for (row = 0; row < ad.numrecs; row++) {
82 for (year = result.
y_start; year <= result.
y_end; year++) {
84 case '+':
setval(result,
getval(a, row, year, ad) +
getval(b, row, year, ad), row, year, ad);
break;
85 case '-':
setval(result,
getval(a, row, year, ad) -
getval(b, row, year, ad), row, year, ad);
break;
86 case '*':
setval(result,
getval(a, row, year, ad) *
getval(b, row, year, ad), row, year, ad);
break;
87 case '/':
setval(result,
getval(a, row, year, ad) /
getval(b, row, year, ad), row, year, ad);
break;
88 default:
setval(result, NAN, row, year, ad);
108 result.
y_end = dbin.y_end;
111 if (ad.maxyear < result.
y_end) result.
y_end = ad.maxyear;
114 for (row = 0; row < ad.numrecs; row++) {
115 for (year = result.
y_start; year <= result.
y_end; year++) {
116 setval(result, scalar *
getval(dbin, row, year, ad), row, year, ad);
129 return 0.5 * erfc(-M_SQRT1_2 * x);
141 double a0 = 2.30753, a1 = 0.27061, b1 = 0.99229, b2 = 0.04481;
151 t = sqrt(-2.0 * log(p));
154 denom = 1.0 + b1 * t + b2 * t * t;
156 return sign * (t - num/denom);
169 double pstar, pderiv, x;
182 for (niter = 0; (fabs(pstar - p) >
EPSILON) && (niter <
MAXITER); niter++) {
184 x = x + (p - pstar)/pderiv;
213 double ztransf(
double y,
double ybar,
double sigma) {
216 if (ybar == 0 || sigma == 0) {
220 }
else if (isinf(y) == 1) {
223 z = (1/sigma) * log(y/ybar) + 0.5 * sigma;
236 if (gini <= 0 || gini >= 100) {
239 return M_SQRT2 *
qnorm(0.5 * (1.0 + gini/100.0));
259 for (year = result.
y_start; year <= result.
y_end; year++) {
261 for (i = 0; i < ad.numrecs; i++) {
284 for (i = 0; i < ad.
numrecs; i++) {
For the application, basic dimensions: number of countries and bounding years.
int y_start
The start year.
struct datablock binop(struct datablock a, struct datablock b, char op, struct appdata ad)
Carry out a binary operation (+, -, *, /) on two datablock structures.
double qnorm(double p)
The inverse cumulative standardized normal distribution.
double quick_qnorm(double p)
Abramowitz & Stegun approximation to qnorm to get a good first guess.
A one-dimensional array that contains information on countries that is the same for all years...
int numrecs
Number of records (i.e., number of countries)
double * data
The array, dimensioned (y_start - y_end + 1) * ad.numrecs when created.
A one-dimensional array that contains global information that is the same for all countries...
struct datablock scalmult(double scalar, struct datablock dbin, struct appdata ad)
Multiply a datablock by a scaling factor.
int allocdata(struct datablock *dblock, struct appdata ad)
Create a datablock in memory, using application-specific dimensions.
void settsval(struct timeseries ts, double val, int year, struct appdata ad)
Set the value for a particular year in a timeseries.
double gini2sdlog(double gini)
The standard deviation of the log of income corresponding to a given Gini, assuming lognormal...
double ztransf(double y, double ybar, double sigma)
The transformed value .
double getval(struct datablock db, int row, int year, struct appdata ad)
Get the data value from the datablock for specified row & year.
double dnorm(double x)
The standard normal probability density.
int allocts(struct timeseries *ts, struct appdata ad)
Create a timeseries in memory, of length = y_start - y_end + 1.
struct datablock z(double y, struct gdrs_struct *gdrs, int ppp_or_mer)
Calculate the "z" transformed version of an income level for all countries and years.
double * data
The data, length = y_start - y_end + 1 when created.
double pnorm(double x)
The cumulative standardized normal distribution.
double filteryr(int year, struct datablock data, struct fixedfactor filter, struct appdata ad)
Aggregate data in a datablock using a fixedfactor "filter" for a particular year. ...
int y_start
The start year.
A two-dimensional array that contains information for country/year combinations.
struct timeseries filter(struct datablock data, struct fixedfactor filter, struct appdata ad)
Aggregate data in a datablock using a fixedfactor "filter" to produce a timeseries.
void setval(struct datablock db, double val, int row, int year, struct appdata ad)
Set a specific value in a datablock, specified by row and year.
struct datablock transform(struct datablock dbin, double(*f)(double), struct appdata ad)
Apply a function to a datablock.