function [fcond,Pcond,lambda,yi]=NPcond(y,X,Xc,yi)
%
% Code written by Taesam Lee and Dominique Fasbender 04/03/2009 : INRS-ETE Quebec
% Nonparametric Condtional Distribution
% X : data of condtion variable (numvar*length), y : current variable(length)
% Xc: condtion values
% yi: estimated set for fcond
% example
% t=mvnrnd([0,0],[.9 .4; .4 .3],100);
% X=t(:,1)';y=t(:,2)';yi=-2:0.01:2;Xc=[1];
% [fcond,Pcond,yi]=NPcond(y,X,Xc,yi);
% plot(yi,fcond);plot(yi,Pcond);

Xall=[y;X];
sz=size(Xall);d=sz(1);n=sz(2);

% Estimate the bandwidth ratio
lambda_ref = (4/(d+2))^(1/(d+4))*n^(-1/(d+4));
%min_lambda = 0.25*lambda_ref;max_lambda = 1.1*lambda_ref;
%lambda = fminbnd(@(lambda)LSCV(lambda,Xall',n,d),min_lambda,max_lambda);
lambda=lambda_ref;

% Conditional Distribution
difX=repmat(Xc,1,n)-X;% need to be changed
s1=inv(Sxx)
%for in=1:n
% dmat1(in)=(difX(:,in))'*s1*(difX(:,in));
%end
%es=exp(-1/2*lambda_ref^2*dmat1);

es2 = 0;
for i=size(s1,1)
for j=size(s1,2)
es2 = es2 + exp(-1/2*lambda_ref^2*difX(i,:).*difX(i,:)*s1(i,j));
end
end

wi=es2./sum(es2);
bi=Sxy'*inv(Sxx)*difX;

for it=1:length(yi)
fcond(it)=sum(1/sqrt(2*pi*lambda^2*Sd)*wi.*exp(-(yi(it)-bi).^2./(2*lambda^2*Sd)));
Pcond(it)=sum(wi.*normcdf(yi(it),bi,sqrt(lambda^2*Sd)));
end

It's nice you implemented the KDE mutual information estimator. I tried to reproduce Fig. 1 in Moon et al. 1995 but didn't succeed. I used to following code to generate the time series
T=400;
max_lag = 100;
t=1:T+max_lag;
x=sin(0.02*pi*t);
xt=x(1:T);
xt_lag=x(1+lag:T+lag);

I let lag=25 and called MutualInfo(xt',xt_lag) and got 0.4029, which is different from 43.7 reported in the paper. Any idea why?

Interesting! But, you need to put more comments, depend of what is the ref. variable are not the sames. For newbies with this technic it could be hard to understand the impact of these variables.

This seems to be a derivative of boxplot.m, even with "Copyright 1993-2005 The MathWorks, Inc." inside. I doubt you can put this under the BSD license.

I found this page while looking for a hint on how to calculate an empirical 2-D CDF (cumulative density) from an empirical bivariate PDF (density) in Matlab. I found a nested loop in your code that does this, but subsequently found a much faster way. You may want to try this instead of the i1 and i2 loops in your code: biv_CDF=cumsum(cumsum(N,1),2)/nL

Comment only