Kernel Density Estimation - Find the pdf and perform integration and derivative on this function
2 views (last 30 days)
I have performed KDE on data:
[f,xi] = ksdensity(data,'bandwidth',0.5,'Function','pdf');
I have the following code which aims to solve for theta - roots of first derivative of the pdf. What I did was plot the pdf from kernel estimation, using Basic Fitting to obtain the function, then solve for theta.
syms theta %create symbolic variable theta
assume(theta,'real') %theta is real
pf = poly2sym(fit.coeff,theta); %calling our fitted polynomials
g = diff(pf,theta);
theta = double(g0);
However, Basic Fitting doesn't fit very well with the pdf. How can I obtain pdf and take derivative without producing too much residuals? (see pic)
Additionally, theta has to follow three conditions: -smaller than the highest pdf value -pdf evaluation of theta must be smaller than 0.8 times of that of the highest pdf value -integral from min x value to theta of pdf must be larger than 0.05
θ < μ, f(θ)<0.8·f(μ) and ∫ f (x)dx > 0.05 from min x to θ.
Is there a way to incorporate loop and boolean to automate solving for theta.