Error in ksdensity function on bivariate data

6 views (last 30 days)
Hi!
When I try to do the example on 'Plot kernel density estimate of bivariate data' in http://au.mathworks.com/help/stats/ksdensity.html#btppv51-1, matlab gives the following error.
Error in ksdensity (line 114)
[axarg,yData,n,ymin,ymax,xispecified,xi,u,m,kernelname,...
I tried the function with another bivariate dataset and it gives the same error. Some advice on estimating the densioty of a bivariate dataset is highly appreciated.
Thanks.
  1 Comment
Anjali
Anjali on 14 Jun 2016
Sorry I have missed the first part of the error massage. It is,
Error using ksdensity>parse_args (line 162)
X must be a non-empty vector.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Jun 2016
In R2015b and earlier, the ydata parameter for ksdensity must be a vector. The example you are using is for the R2016a ksdensity routine, which also accepts a two-column vector. The error message is wrong in referring to the X data instead of the Y data.
  2 Comments
Anjali
Anjali on 14 Jun 2016
Thanks. So does it mean that I cannot fit a bivariate kernel density using ksdensity function in R2015b and earlier?
Walter Roberson
Walter Roberson on 14 Jun 2016
I do not know if there is some work-around; the function is not designed for bivariate until R2016a.

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 14 Jun 2016
This is the code that downloads for me when I open the example:
% Create a two-column vector of points at which to evaluate the density.
gridx1 = -0.25:.05:1.25;
gridx2 = 0:.1:15;
[x1,x2] = meshgrid(gridx1, gridx2);
x1 = x1(:);
x2 = x2(:);
xi = [x1 x2];
% Generate a 30-by-2 matrix containing random numbers from a mixture of
% bivariate normal distributions.
rng default % For reproducibility
x = [0+.5*rand(20,1) 5+2.5*rand(20,1);
.75+.25*rand(10,1) 8.75+1.25*rand(10,1)];
% Plot the estimated density of the sample data.
figure
ksdensity(x,xi);
It runs just fine for me.
  3 Comments
Indrani Manna
Indrani Manna on 2 Dec 2016
this means everytime matlab issues a new version, you must pay and update or risk loss of usage. Thats how matlab will ensure it gets its cashflows. Switch to R or other databases.
Walter Roberson
Walter Roberson on 2 Dec 2016
Indrani Manna, the poster wanted to use functionality that did not exist in the release they had paid for. This was not a "loss of usage": their version continued to do what it was designed to do, and code developed for their version would continue to work in the next version.
Does Mathworks expect to be paid for upgrades? Yes, of course. It takes time and money to research and build and test and document upgrades.
Analogy: I have already paid the interior decorator I am dealing with for the Phase I plans for my house kitchen renovation. Phase II, basement renovation planning, will happen as well but is not paid for. By your logic, I should be able to expect that my decorator will "upgrade" my plans to include the basement, for free, just because I want them to, and that if my decorator refuses, that it would be a Good Thing for me to talk about the decorator as if they were greedy; and that I am justified in expecting that somewhere in the world someone will be willing to do my basement planning for free.
The people who contribute to making R possible at no cost: can they pay their rent with the vague thanks that users of R give, and can they pay for their groceries with the "exposure" of having worked on R? Or do they have to engage in other work to earn enough to have enough left over to have the luxury of contributing? Engage in work like... oh, working for a commercial software company? Or is that somehow "shameful", that an employee might expect to be paid for writing software and that therefore a company might charge for that software?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!