0

I have been using MATLAB to perform Kernel Density Estimations (KDE) on UTM data (X and Y coordinates). I ran into a problem that I do not seem to be understanding.

I perform the KDEs with a sample of 45 points. Everything works fine and I produce the graphs with contours.

[bandwidth,density,X,Y]=kde2d(data)

The function kde2d is code by Zdravko Botev. I obtained it from his file exchange on MathWorks. The variable 'data' is a 45x2 array of my data. The first column holds the X coordinates and the second the Y.

The problem comes when I try to do the same line of code on a subset of those 45 points. I get a recurring error:

Error using fzero (line 274) 
The function values at the interval endpoints must differ in sign. 

Error in kde2d (line 101)
t_star=fzero(@(t)(t-evolve(t)),[0,0.1]);

I get the same error for a bunch of those subsets on a bunch of different sets of 45 points.

The complete set has these 45 values:

1594436.281 572258.1272
1594418.48  572357.5859
1594471.362 572385.5186
1594516.726 572266.8206
1594415.313 572369.2754
1594519.701 572272.7153
1594415.377 572363.4139
1594468.365 572381.5779
1594518.139 572276.6059
1594425.496 572271.6874
1594524.259 572272.7651
1594502.555 572172.8749
1594516.747 572264.867
1594485.314 572360.2689
1594476.027 572375.7997
1594556.087 572419.6609
1594522.718 572274.7021
1594472.775 572395.3039
1594554.568 572419.6443
1594527.255 572276.7054
1594474.315 572393.3669
1594522.697 572276.6557
1594471.319 572389.4262
1594460.854 572373.6799
1594546.022 572228.0609
1594460.79  572379.5414
1594468.323 572385.4855
1594466.953 572371.7926
1594519.722 572270.7614
1594396.76  572398.3826
1594468.131 572403.0693
1594418.288 572375.1697
1594396.377 572433.5499
1594448.287 572271.9361
1594510.541 572276.523
1594424.466 572226.7345
1594413.773 572371.2124
1594511.848 572296.0774
1594513.367 572296.094
1594424.488 572224.7805
1594468.152 572401.1153
1594421.37  572371.2953
1594446.768 572271.9195
1594468.152 572401.1153
1594448.799 572225.0457

One of the subsets I am trying to use is this:

1594436.281 572258.1272
1594418.48  572357.5859
1594471.362 572385.5186
1594516.726 572266.8206
1594415.313 572369.2754
1594519.701 572272.7153
1594415.377 572363.4139
1594468.365 572381.5779
1594518.139 572276.6059
1594425.496 572271.6874

I am not sure if I should include any of Botev's code. I am hoping that the error message can be explained on its own. If not I can provide more. Thank you very much.

Machavity
  • 30,841
  • 27
  • 92
  • 100
squishy
  • 344
  • 3
  • 12
  • 1
    Seems like a question to address to "Zdravko Botev from MathWorks". I'm sure he would be interested in knowing of the issue. `fzero` is telling you that it couldn't find a root between 0 and 0.1 because the function in question has the same sign at those to values of `t` (it may cross zero in between, but `fzero` assumes that functions are monotonic in the search range). These things can occur when your data doesn't sample the underlying distribution sufficiently well or possibly due to noise. 45 points might not be enough, but it might also be because the other dimension only has two. – horchler Jan 30 '14 at 01:31
  • Is it [this `kde2d`](http://www.mathworks.com/matlabcentral/fileexchange/17204-kernel-density-estimation/content/kde2d.m)? You might not copy the code, but you can certainly link to it. (Zdravko Botev is not a MathWorks employee, but a FileExchange contributor.) – horchler Jan 30 '14 at 01:36
  • 1
    horchler, Yes I tried to contact him. I wanted to see if I could gain insight here as well. I think I understand what the error is saying but not really why it is happening. It seems like the code is not handling such a low sample size? And yes, it is that kde2d function and I also realized I made it seem like he was an employee! Opps. The sample size thing seems odd since a hallmark of KDE is ability to handle low sample size. – squishy Jan 30 '14 at 01:42

0 Answers0