Assuming this is your datasets with realisation of random variables X_i:
data data_set_X_i;
call streaminit(42);
do _N_ = 1 to 123;
X_i = RAND("NORMAL", 10, 5);
output;
end;
run;
you could do calculation of f_hat like this(using hash tables [not robust]):
data want;
X_i=.;
declare hash XX;
h = 2.5;
n = 123;
do x=-10 to 30 by 0.1;
XX = _new_ hash (dataset:cats("data_set_X_i(where=(",x-h,"<=X_i<=",x+h,"))"), multidata:"Y");
XX.defineKey("X_i");
XX.defineDone();
f_hat = XX.num_items/(2*h*n);
XX.delete();
output;
end;
run;
/*
proc print;
run;
*/
proc sgplot data=want;
series x=x y = f_hat;
run;
or with arrays (faster):
[EDIT: no sorting needed]
data want2;
array XX[123] _temporary_;
do until(end);
set data_set_X_i curobs=curobs end=end;
XX[curobs] = X_i;
end;
h = 2.5;
n = 123;
do x=-10 to 30 by 0.1;
num_items=0;
do _N_ = 1 to n;
num_items + (x-h<=XX[_N_]<=x+h);
end;
f_hat = num_items/(2*h*n);
output;
end;
stop;
run;
proc sgplot data=want2;
series x=x y = f_hat;
run;
For CALL STREAMINIT(42) and RAND("NORMAL", 10, 5), and H=2.5, nnd N=123, both result with the following plot:
Bart
... View more