9 double polint(
double * xa,
double * ya,
double x);
13 const int& level_index,
int index);
16 const int& level_index,
int index);
26 ofstream& ofs3=(ofstream&) _ofs3;
27 ofs3 <<
"Minimum width confidence limits:" <<
endl
28 <<
" significance level lower bound"
29 <<
" upper bound" <<
endl;
30 for (
int i=1;i<=numsig_levels;i++)
32 ofs3 <<
" " << setw(12) << siglevel(i)
33 <<
" " << left_bd(i) <<
" " << right_bd(i) <<
endl;
42 ofstream& ofs3=(ofstream&) _ofs3;
44 for (i=1;i<=numsig_levels;i++)
46 ofs3 <<
"The probability is " << setw(7) << siglevel(i) <<
" that "
48 <<
" is greater than " << left_bd(i) <<
endl;
51 for (i=1;i<=numsig_levels;i++)
53 ofs3 <<
"The probability is " << setw(7) << siglevel(i) <<
" that "
55 <<
" is less than " << right_bd(i) <<
endl;
64 const dvector& siglevel,
const ofstream& _ofs2,
int num_pp,
65 const dvector& _all_values,
const dmatrix& actual_value,
double global_min,
79 const dvector& siglevel,
const ofstream& ofs2,
int num_pp,
97 ofstream& ofs2=(ofstream&) _ofs2;
98 ofstream savef(
"diags");
101 #ifndef CURVE_CORRECT
114 int numsig_levels=siglevel.
indexmax();
119 size_t llen =
length(profrep_name);
120 if (llen>8) profrep_name=profrep_name(1,8);
121 ofstream ofs3((
char*) (profrep_name+
adstring(
".plt")));
126 ofs2 << sigma <<
endl << global_min <<
" " << udet <<
endl;
127 dvector tempint0(-num_pp,num_pp);
128 dvector tempint1(-num_pp,num_pp);
129 dvector tempint2(-num_pp,num_pp);
131 ofstream ofs(
"dgs2");
132 ofs <<
"lprof" << endl << lprof <<
endl;
134 for (
int j=-num_pp;j<=num_pp;j++)
136 all_values(j)=actual_value(ip,j-offset);
137 double lp=lprof(ip,j);
138 #if defined(DO_PROFILE)
139 tempint0(j)=
exp(global_min-lp+.5*(-ldet(ip,j)+ldet(ip,0)));
141 tempint1(j)=
exp(global_min-lp);
144 square((actual_value(ip,j)-actual_value(ip,-offset))/
146 tempint2(j)=
exp(-tempint2(j));
149 for (
int j=-num_pp;j<=num_pp;j++)
151 #if defined(DO_PROFILE)
152 m(1,j)=tempint0(j)/xdist(ip,j);
154 if (xdist(ip,j)<1.e-50)
156 cerr <<
" xdist(" << ip <<
"," << j <<
") too small" <<
endl;
164 m(2,j)=tempint1(j)/xdist(ip,j);
177 savef <<
"tempint1 " << endl << setw(9) << setprecision(3)
179 #if defined(DO_PROFILE)
180 savef <<
"m(1) " << endl << setw(9) << setprecision(3) << m(1) <<
endl;
182 savef <<
"m(2) " << endl << setw(9) << setprecision(3) << m(2) <<
endl;
183 savef <<
"m(3) " << endl << setw(9) << setprecision(3) << m(3) <<
endl;
184 savef <<
"xdistance" <<
endl;
185 savef << xdist(ip) << endl <<
endl;
187 int min_ind = -num_pp;
188 int max_ind = num_pp;
190 dvector xs(7*min_ind,7*max_ind);
191 dmatrix ms(1,3,7*min_ind,7*max_ind);
194 for (
int k=min_ind;k<=max_ind;k++)
196 double val=all_values(k);
200 double diff=all_values(k+1)-all_values(k);
201 for (
int i=1;i<kmult;i++)
203 xs(kmult*k+i)=val+i/double(kmult)*diff;
210 for (
int i=mmin;i<=mmax;i++)
214 for (
int j=cmin;j<=cmax;j++)
216 if (m(i,j)<=0.0) m(i,j)=1.e-50;
223 #if defined(DO_PROFILE)
229 for (
int ii=lowlimit;ii<=3;ii++)
232 for (k=min_ind;k<=0;k++)
237 ms(ii,kmult*k)=lm(ii,k);
242 for (
int i=1;i<kmult;i++)
244 ms(ii,kmult*k+i)=l+double(i)/kmult*(u-l);
250 for (k=1;k<=max_ind;k++)
255 ms(ii,kmult*k)=lm(ii,k);
260 for (
int i=1;i<kmult;i++)
262 ms(ii,kmult*k+i)=l+double(i)/kmult*(u-l);
275 for (
int j=lowlimit;j<=3;j++)
277 for (
int i=7*min_ind;i<7*max_ind;i++)
285 ssum(j)+=ms(j,i)*(xs(i+1)-xs(i));
289 for (
int j=lowlimit;j<=3;j++)
302 for (
int j=lowlimit;j<=3;j++)
308 siglevel,level_index,j);
310 siglevel,level_index,j);
313 while (level_index <= numsig_levels);
316 double min_cutoff = 1.e-3/sigma;
318 for (i=7*min_ind;i<=0;i++)
320 if (
max(ms(2,i),ms(3,i)) > min_cutoff)
break;
322 int new_min_ind = int(
max(i,7*min_ind));
323 for (i=0;i<=7*max_ind;i++)
325 if (
max(ms(2,i),ms(3,i)) < min_cutoff)
break;
327 int new_max_ind =
min(i,7*max_ind);
330 output(1)=xs(new_min_ind,new_max_ind);
332 #if defined(DO_PROFILE)
333 output(2)=ms(1)(new_min_ind,new_max_ind);
335 ofs3 <<
"Adjusted Profile likelihood" <<
endl;
339 ofs3 <<
"One sided confidence limits for the "
340 "adjusted profile likelihood:" << endl <<
endl;
342 lower_bd(1),upper_bd(1),ip);
346 output(2)=ms(2)(new_min_ind,new_max_ind);
348 ofs3 <<
"Profile likelihood" <<
endl;
352 ofs3 <<
"One sided confidence limits for the "
353 "profile likelihood:" << endl <<
endl;
355 lower_bd(2),upper_bd(2),ip);
358 output(2)=ms(3)(new_min_ind,new_max_ind);
360 ofs3 <<
"Normal approximation" <<
endl;
364 ofs3 <<
"One sided confidence limits for the "
365 "Normal approximation:" << endl <<
endl;
367 lower_bd(3),upper_bd(3),ip);
378 int diff=mmax-mmin+1;
380 tmp(mmin)=.8*v(mmin)+.2*v(mmin+1);
381 tmp(mmin+1)=.2*v(mmin)+.6*v(mmin+1)+.2*v(mmin+2);
382 for (
int i=mmin+2;i<=mmin+diff/4;i++)
384 tmp(i)=.1*v(i-2)+.2*v(i-1)+.4*v(i)+.2*v(i+1)+.1*v(i+2);
386 for (
int i=mmin+diff/4+1;i<mmax-diff/4;i++)
390 for (
int i=mmax-diff/4;i<=mmax-2;i++)
392 tmp(i)=.1*v(i-2)+.2*v(i-1)+.4*v(i)+.2*v(i+1)+.1*v(i+2);
394 tmp(mmax)=.8*v(mmax)+.2*v(mmax-1);
395 tmp(mmax-1)=.2*v(mmax)+.6*v(mmax-1)+.2*v(mmax-2);
399 double polint(
double * xa,
double * ya,
double x)
401 double prod1=(xa[1]-xa[2])*(xa[1]-xa[3]);
402 double prod2=(xa[2]-xa[1])*(xa[2]-xa[3]);
403 double prod3=(xa[3]-xa[1])*(xa[3]-xa[2]);
419 double y= (x-xa[2])*(x-xa[3])/prod1*ya[1]
420 +(x-xa[1])*(x-xa[3])/prod2*ya[2]
421 +(x-xa[1])*(x-xa[2])/prod3*ya[3];
static likeprof_params * likeprofptr[500]
void get_onesided_intervals(const dvector &left_bd, const dvector &right_bd, dmatrix &ms, const dvector &xs, const dvector &siglevel, const int &level_index, dvector &xdist, int index)
dvector smooth(const dvector &v)
void report_onesided_confidence_limits(const ofstream &ofs3, int numsig_levels, dvector &siglevel, const dvector &left_bd, const dvector &right_bd, int ip)
dmatrix trans(const dmatrix &m1)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Vector of double precision numbers.
int indexmin() const
Get minimum valid index.
void polint(const dvector &xa, const dvar_vector &ya, int n, double x, const dvariable &y, const dvariable &dy)
void val(const adstring &s, int &v, int &code)
virtual double & get_sigma(void)=0
void get_confidence_interval(const dvector &left_bd, const dvector &right_bd, dmatrix &ms, const dvector &xs, const dvector &siglevel, const int &level_index, dvector &xdist, int index)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
prnstream & endl(prnstream &)
int indexmax() const
Get maximum valid index.
void normalize_posterior_distribution(double udet, const dvector &siglevel, const ofstream &ofs2, int num_pp, const dvector &all_values, const dmatrix &actual_value, double global_min, int offset, const dmatrix &lprof, const dmatrix &ldet, const dmatrix &xdist, const dmatrix &penalties)
Description not yet available.
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Description not yet available.
void initialize(void)
Initialze all elements of dvector to zero.
virtual const char * label()=0
void report_confidence_limits(const ofstream &ofs3, int numsig_levels, dvector &siglevel, const dvector &left_bd, const dvector &right_bd)
Description not yet available.
size_t length(const adstring &t)
Returns the size of adstr.
double square(const double value)
Return square of value; constant object.
static int num_likeprof_params
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.