static void BDRksmooth(double *x, double *y, R_xlen_t n, double *xp, double *yp, R_xlen_t np, int kern, double bw) { R_xlen_t imin = 0; double cutoff = 0.0, num, den, x0, w; /* bandwidth is in units of half inter-quartile range. */ if(kern == 1) {bw *= 0.5; cutoff = bw;} if(kern == 2) {bw *= 0.3706506; cutoff = 4*bw;} while(x[imin] < xp[0] - cutoff && imin < n) imin++; for(R_xlen_t j = 0; j < np; j++) { num = den = 0.0; x0 = xp[j]; for(R_xlen_t i = imin; i < n; i++) { if(x[i] < x0 - cutoff) imin = i; else { if(x[i] > x0 + cutoff) break; w = dokern(fabs(x[i] - x0)/bw, kern); num += w*y[i]; den += w; } } if(den > 0) yp[j] = num/den; else yp[j] = NA_REAL; } }
void BDRksmooth(double *x, double *y, int *n, double *xp, double *yp, int *np, int *kern, double *bandwidth) { int i, imin=0, j; double cutoff=0.0, num, den, x0, w, bw=*bandwidth; /* bandwidth is in units of half inter-quartile range. */ if(*kern == 1) {bw *= 0.5; cutoff = bw;} if(*kern == 2) {bw *= 0.3706506; cutoff = 4*bw;} while(x[imin] < xp[0] - cutoff && imin < *n) imin++; for(j = 0; j < *np; j++) { num = den = 0.0; x0 = xp[j]; for(i = imin; i < *n; i++) { if(x[i] < x0 - cutoff) imin = i; else { if(x[i] > x0 + cutoff) break; w = dokern(fabs(x[i] - x0)/bw, *kern); num += w*y[i]; den += w; } } if(den > 0) yp[j] = num/den; else yp[j] = NA_REAL; } }