Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

locf.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright 1996-2006 Catherine Loader.
  3. */
  4. #ifndef I_LOCF_H
  5. #define I_LOCF_H
  6. #include "stdlib.h"
  7. #include "ctype.h"
  8. #include "mut.h"
  9. #ifdef WARN
  10. #undef WARN
  11. #endif
  12. #define LERR(args) {mut_printf("Error: "); mut_printf args; mut_printf("\n"); lf_error=1;}
  13. #define WARN(args) {mut_printf("Warning: "); mut_printf args; mut_printf("\n"); }
  14. extern int lf_error;
  15. #define LOGPI 1.144729885849400174143427
  16. #define HUBERC 2.0
  17. #define NOSLN 0.1278433
  18. #define GFACT 2.5
  19. #define EFACT 3.0
  20. #define ISWAP(a,b) { int zz; zz = a; a = b; b = zz; }
  21. #define MAX(a,b) (((a)>(b)) ? (a) : (b))
  22. #define MIN(a,b) (((a)<(b)) ? (a) : (b))
  23. #define SGN(x) (((x)>0) ? 1 : -1)
  24. #define SQR(x) ((x)*(x))
  25. extern int lf_error;
  26. typedef struct {
  27. double *wk, *coef, *xbar, *f;
  28. jacobian xtwx;
  29. int lwk, haspc;
  30. } paramcomp;
  31. #define haspc(pc) ((pc)->haspc)
  32. /*
  33. * MXDIM and MXDEG are maximum dimension and local polynomial
  34. * degree for Locfit. Note that some parts of the code may be
  35. * more restrictive.
  36. */
  37. #define MXDIM 15
  38. #define MXDEG 7
  39. typedef struct {
  40. double *x[MXDIM];
  41. double *y;
  42. double *w;
  43. double *b;
  44. double *c;
  45. double sca[MXDIM];
  46. double xl[2*MXDIM];
  47. int n, d, ord;
  48. int sty[MXDIM];
  49. } lfdata;
  50. #define resp(lfd,i) (((lfd)->y==NULL) ? 0.0 : (lfd)->y[i])
  51. #define base(lfd,i) (((lfd)->b==NULL) ? 0.0 : (lfd)->b[i])
  52. #define prwt(lfd,i) (((lfd)->w==NULL) ? 1.0 : (lfd)->w[i])
  53. #define cens(lfd,i) (((lfd)->c==NULL) ? 0 : (int)(lfd)->c[i])
  54. #define datum(lfd,i,j) ((lfd)->x[i][j])
  55. #define dvari(lfd,i) ((lfd)->x[i])
  56. /*
  57. * The design structure used in Locfit, and associated macro definitions.
  58. */
  59. typedef struct {
  60. int des_init_id;
  61. double *wk;
  62. int *ind;
  63. int lwk, lind;
  64. double *xev; /* fitting point, length p */
  65. double *X; /* design matrix, length n*p */
  66. double *w, *di, *res, *th, *wd, h;
  67. double *V, *P; /* matrices with length p*p */
  68. double *f1, *ss, *oc, *cf; /* work vectors, length p */
  69. double llk, smwt;
  70. double tr0, tr1, tr2; /* traces for local df computation */
  71. jacobian xtwx; /* to store X'WVX and decomposition */
  72. int cfn[1+MXDIM], ncoef;
  73. int *fix; /* integer vector for fixed coefficients. */
  74. int (*itype)(); /* density integration function */
  75. int n, p;
  76. } design;
  77. #define cfn(des,i) (des->cfn[i])
  78. #define d_x(des) ((des)->X)
  79. #define d_xi(des,i) (&(des)->X[i*((des)->p)])
  80. #define d_xij(des,i,j) ((des)->X[i*((des)->p)+j])
  81. #define is_fixed(des,i) ((des)->fix[i]==1)
  82. #define wght(des,i) ((des)->w[i])
  83. #define dist(des,i) ((des)->di[i])
  84. #define fitv(des,i) ((des)->th[i])
  85. #define DES_INIT_ID 34988372
  86. extern int des_reqd(), des_reqi();
  87. typedef struct {
  88. int deflink, canlink, quasi, robust;
  89. int (*vallink)(), (*family)(), (*initial)(), (*like)(), (*pcheck)();
  90. } family;
  91. #define isquasi(fam) ((fam)->quasi)
  92. #define isrobust(fam) ((fam)->robust)
  93. extern int inllmix; /* flag needed to ensure correct behavior in llmix. */
  94. typedef struct {
  95. double nn, fixh, adpen;
  96. int ker, kt;
  97. int deg, deg0, p;
  98. int acri;
  99. int fam, lin;
  100. family fami;
  101. int ubas;
  102. double (*vb)();
  103. void (*vbasis)();
  104. } smpar;
  105. #define nn(sp) ((sp)->nn)
  106. #define fixh(sp) ((sp)->fixh)
  107. #define pen(sp) ((sp)->adpen)
  108. #define ker(sp) ((sp)->ker)
  109. #define kt(sp) ((sp)->kt)
  110. #define deg(sp) ((sp)->deg)
  111. #define deg0(sp) ((sp)->deg0)
  112. #define npar(sp) ((sp)->p)
  113. #define acri(sp) ((sp)->acri)
  114. #define ubas(sp) ((sp)->ubas)
  115. #define fam(sp) ((sp)->fam)
  116. #define fami(sp) (&(sp)->fami)
  117. #define link(sp) ((sp)->lin)
  118. typedef struct {
  119. int deriv[MXDEG+2];
  120. int nd;
  121. } deriv;
  122. /*
  123. * Criteria for adaptive local fitting mi[MACRI]
  124. * 1: localized CP; 2: ICI (katkovnik); 3: curvature model index
  125. * 4: Increase bandwidth until locfit returns LF_OK
  126. */
  127. #define ANONE 0
  128. #define ACP 1
  129. #define AKAT 2
  130. #define AMDI 3
  131. #define AOK 4
  132. /*
  133. * weight functions mi[MKER].
  134. * see Table 3.1 or the function W() in weights.c for definitions.
  135. */
  136. #define WRECT 1
  137. #define WEPAN 2
  138. #define WBISQ 3
  139. #define WTCUB 4
  140. #define WTRWT 5
  141. #define WGAUS 6
  142. #define WTRIA 7
  143. #define WQUQU 8
  144. #define W6CUB 9
  145. #define WMINM 10
  146. #define WEXPL 11
  147. #define WMACL 12
  148. #define WPARM 13
  149. /*
  150. * type of multivariate weight function mi[MKT]
  151. * KSPH (spherical) KPROD (product)
  152. * others shouldn't be used at present.
  153. */
  154. #define KSPH 1
  155. #define KPROD 2
  156. #define KCE 3
  157. #define KLM 4
  158. #define KZEON 5
  159. /*
  160. * Local likelihood family mi[MTG]
  161. * for quasi-likelihood, add 64.
  162. */
  163. #define TNUL 0
  164. #define TDEN 1
  165. #define TRAT 2
  166. #define THAZ 3
  167. #define TGAUS 4
  168. #define TLOGT 5
  169. #define TPOIS 6
  170. #define TGAMM 7
  171. #define TGEOM 8
  172. #define TCIRC 9
  173. #define TROBT 10
  174. #define TRBIN 11
  175. #define TWEIB 12
  176. #define TCAUC 13
  177. #define TPROB 14
  178. #define TQUANT 15
  179. /*
  180. * Link functions mi[MLINK].
  181. * Mostly as in table 4.1 of the book.
  182. * LDEFAU and LCANON are used to select default and canonical
  183. * links respectively. LINIT shouldn't be selected by user...
  184. */
  185. #define LINIT 0
  186. #define LDEFAU 1
  187. #define LCANON 2
  188. #define LIDENT 3
  189. #define LLOG 4
  190. #define LLOGIT 5
  191. #define LINVER 6
  192. #define LSQRT 7
  193. #define LASIN 8
  194. /*
  195. * components of vector returned by the links() function
  196. * in family.c. ZLIK the likelihood; ZMEAN = estimated mean;
  197. * ZDLL = derivative of log-likelihood; ZDDLL = - second derivative
  198. */
  199. #define LLEN 4
  200. #define ZLIK 0
  201. #define ZMEAN 1
  202. #define ZDLL 2
  203. #define ZDDLL 3
  204. /*
  205. * return status for the locfit() function
  206. */
  207. #define LF_OK 0
  208. #define LF_DONE 1 /* done - forced break from iterations */
  209. #define LF_OOB 2 /* out of bounds, or large unstable parameter */
  210. #define LF_PF 3 /* perfect fit; interpolation; deviance=0 */
  211. #define LF_NCON 4 /* not converged */
  212. #define LF_NSLN 5 /* no solution - eg separation in binomial. */
  213. #define LF_NOPT 6 /* no or insufficient points with non-zero wt */
  214. #define LF_INFA 7 /* initial failure e.g. log(0) */
  215. #define LF_DEMP 10 /* density -- empty integration region */
  216. #define LF_XOOR 11 /* density -- fit point outside xlim region */
  217. #define LF_DNOP 12 /* density version of 6 */
  218. #define LF_BADP 81 /* bad parameters e.g. neg prob for binomial */
  219. #define LF_LNK 82 /* invalid link */
  220. #define LF_FAM 83 /* invalid family */
  221. #define LF_ERR 99 /* error */
  222. #define STANGL 4
  223. #define STLEFT 5
  224. #define STRIGH 6
  225. #define STCPAR 7
  226. /*
  227. * Integration type mi[MIT] for integration in
  228. * density estimation.
  229. */
  230. #define INVLD 0
  231. #define IDEFA 1
  232. #define IMULT 2
  233. #define IPROD 3
  234. #define IMLIN 4
  235. #define IHAZD 5
  236. #define ISPHR 6
  237. #define IMONT 7
  238. /* density.c */
  239. extern int densinit(), likeden(), deitype();
  240. extern int fact[];
  241. extern void prodintresp(), prresp();
  242. extern int de_mint, de_itype, de_renorm;
  243. /* dens_haz.c */
  244. extern void haz_init();
  245. extern int hazint();
  246. /* dens_odi.c */
  247. extern int onedint();
  248. extern void recurint();
  249. /* famquant.c */
  250. extern void lfquantile();
  251. /* family.c */
  252. extern int lffamily(), lflink();
  253. extern int links(), stdlinks(), defaultlink(), validlinks();
  254. extern double b2(), b3(), b4(), lf_link(), invlink();
  255. extern void setfamily();
  256. /* lf_adap.c */
  257. extern int alocfit(), lfacri();
  258. /* lf_fitfun.c */
  259. extern void fitfun(), makecfn(), designmatrix();
  260. extern int calcp(), coefnumber();
  261. /* lf_nbhd.c */
  262. extern double kordstat(), rho();
  263. extern void nbhd();
  264. /* lf_robust.c */
  265. extern double median();
  266. extern void lf_robust();
  267. /* lfstr.c */
  268. extern int pmatch();
  269. /* lf_vari.c */
  270. extern void lf_vcov(), comp_vari(), local_df();
  271. /* lf_wdiag.c */
  272. extern int wdiag(), wdiagp();
  273. /* locfit.c */
  274. extern int locfit(), des_reqd(), des_reqi(), likereg();
  275. extern int reginit();
  276. extern void lfdata_init(), smpar_init(), deriv_init(), des_init(), lfiter();
  277. extern int lf_maxit, lf_debug;
  278. extern void lf_status_msg();
  279. /* minmax.c */
  280. extern double ipower(), minmax();
  281. /* weight.c */
  282. extern int lfkernel(), lfketype();
  283. extern double W(), weight(), weightd(), Wd(), Wdd(), wint();
  284. extern double Wconv(), Wconv1(), Wconv4(), Wconv5(), Wconv6(), Wikk();
  285. extern int iscompact(), wtaylor();
  286. #endif /* define I_LOCF_H */