-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernden.c
41 lines (35 loc) · 1.16 KB
/
kernden.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*###################################################################################################
#Engagement - UCLA MAS - STAT 404 - Project #
#FileName - kernden.c #
#By - Jeremy Guinta (ID 604882679) #
# #
#Last Update Date: 2/16/2017 #
# #
#Purpose: - 1. Gaussian Kernel Density with Rejection Sampling. #
# #
####################################################################################################*/
#include <R.h>
#include <RMath.h>
//x - data
//lenx - length of x
//grd - grid to estimate over
//lengrd - length of xpts
//bw - bandwidth
//res - output
void kernden(double *x, int *lenx, double *grd, int *lengrd, double *bw, double *res) {
/*
Kernel Density Estimator using Scott's bandwidth
*/
int i;
int j;
double d;
double kest;
for(i = 0; i < *lengrd; i++){
kest = 0.0;
for(j=0; j < *lenx; j++){
d = grd[i] - x[j];
kest = kest + dnorm( (d / *bw) , 0, 1, 0) ;
}
res[i] = kest / ( (*lenx) * (*bw) );
}
}