Box Cox transformation for multivariate normality in MATLAB - matlab

Has anyone implemented a Box Cox approach in MATLAB to transform multivariate data? I've found an R package that does it, but nothing for MATLAB.
Thanks.

MATLAB do not have built in function to implement multivariate box-cox transformaion.
I have written one myself and it works.
Here is the code.
The input x is the obervation matix, where the rows denote the obervations
and the columns denote the variables.
Reference: Applied Multivariate Statistical Analysis 6th- Johnson R. & Wichern D. Chapter 4.8 Transformations to Near Normality
function lambda=boxcoxn(x)
[m,n]=size(x);
lambda_ini=zeros(n,1);
for ii=1:n
[temp,lambda_ini(ii,1)]=boxcox(x(:,ii));
end
fun=#(lambda)(log(det((cov(((x.^repmat(lambda',m,1)-1)./repmat(lambda',m,1))))))*m/2-(lambda-1)'*(sum(log(x)))');
lambda=fminsearch(fun,lambda_ini);
end
Just feel free to use it.

Googling "MATLAB Box Cox" tells me that:
Box-Cox transformations are available in Financial Toolbox
There is a freely available implementation on MATLAB Central File Exchange.

Related

MATLAB's glmfit vs fitglm

I'm trying to perform logistic regression to do classification using MATLAB. There seem to be two different methods in MATLAB's statistics toolbox to build a generalized linear model 'glmfit' and 'fitglm'. I can't figure out what the difference is between the two. Is one preferable over the other?
Here are the links for the function descriptions.
http://uk.mathworks.com/help/stats/glmfit.html
http://uk.mathworks.com/help/stats/fitglm.html
The difference is what the functions output. glmfit just outputs a vector of the regression coefficients (and some other stuff if you ask for it). fitglm outputs a regression object that packs all sorts of information and functionality inside (See the docs on GeneralizedLinearModel class). I would assume the fitglm is intended to replace glmfit.
In addition to Dan's answer, I would like to add the following.
The function fitglm, like newer functions from the statistics toolbox, accepts more flexible inputs than glmfit. For example, you can use a table as the data source, specifyy a formula of the form Y ~ X1 + X2 + ..., and use categorical variables.
As a side note, the function lassoglm uses (depends on) glmfit.

Neighbour Component Analysis implementation in Octave/Matlab

I've been trying to implement the Neighbourhood Component Analysis (NCA) algorithm in Octave, but apparently there's something wrong with my code and I cannot figure out what it is.
Note: I am using Carl Edward Rasmussen's minimize function for maximization of the negative f.
Note 2: The test data I am using is the Wine dataset available at the UCI Machine Learning repository.
With some external help, I've got the answer to the question. The problem was that I was assuming wrongly that vector product of the difference of datapoints i and j should be a row vector by column vector instead of the opposite:

Does MATLAB use OpenCv CascadeClassifier?

I have a question about CascadeObjectDetector in MATLAB. In source code of CascadeObjectDetector in MATLAB I see:
pCascadeClassifier; % OpenCV pCascadeClassifier
Then I see:
%------------------------------------------------------------------
% Constructor
%------------------------------------------------------------------
function obj = CascadeObjectDetector(varargin)
obj.pCascadeClassifier = vision.internal.CascadeClassifier;
...
end
And in stepImpl:
bbox = double(obj.pCascadeClassifier.detectMultiScale(I, ...
double(obj.ScaleFactor), ...
uint32(obj.MergeThreshold), ...
uint32(obj.MinSize), ...
uint32(obj.MaxSize)));
Do you know, what is vision.internal.CascadeClassifier? Is it simply OpenCV CascadeClassifier? And where is source code of detectMultiScale function?
The thing is that matlab provides the following object detectors
template matching
blob analysis
viola-jones algorithm
More info here : http://www.mathworks.ch/products/computer-vision/description4.html
Now to talk about opencv. The opencv function cv.HaarDetectObjects() which is used for faces detection (and in general for object detection) uses the viola jones algorithm which inturn uses harr like features.
My personal opinion is that the implementations may be slightly different but they essentially have the same algorithm.
If you are still not convinced and would like to use opencv function from matlab, u can use MEX. So this way u can use the cv.HaarDetectObjects() from matlab. More details are available at : http://www.mathworks.ch/discovery/matlab-opencv.html

Generate bifurcation diagram for 2D system

Drawing bifurcation diagram for 1D system is clear but if I have 2D system on the following form
dx/dt=f(x,y,r),
dy/dt=g(x,y,r)
And I want to generate a bifurcation diagram in MATLAB for x versus r.
What is the main idea to do that or any hints which could help me?
You first have to do some math:
Setting each of the functions to zero gives you two functions y(x) (called the nullclines), which you can plot in a phase diagram. Where the two lines intersect are the fixed-points (equilibria) of your system.
Now, you have to take the jacobian of your system and plug each of those fixed-points in, which will give you the linear stability analysis of the system.
The location of the fixed points and the stability of each point can now be computed as a you vary r (the bifurcation parameter).
For the programming:
-use newton's method (fsolve in MATLAB) to find where the equations are zero
-eig will help you find the eigenvalues of the system.
However
It depends on your system.
If you're supposed to be looking for limit cycles or chaos or something, you'll have to use one of the ode solvers and then the analysis becomes more tricky. I suppose you could develop a poincare-bendixson algorithm, but that would be involved and details would depend on your system.
I don't think MATLAB has anything built in that would give you a bifurcation diagram. There is this third-party solution:
http://www.mathworks.com/matlabcentral/fileexchange/8382

Anyone can provide simple MATLAB routine of Kernel Density Estimation?

I am trying to learn the kernel density estimation from the basic. Anyone have the simple routine for 1d KDE would be great helpful. Thanks.
If you have the statistics toolbox in MATLAB, you can use the ksdensity to estimate pdf/cdf using kernel smoothing. Here's an example
data=[randn(2000,1);4+randn(2000,1)];%# create a bimodal Gaussian distribution
x=linspace(-4,8,1e4);%# need to evaluate density at these points
pF=ksdensity(data,x,'function','pdf');%# evaluate the pdf of the data points
If you plot it, it should look like this
You can also get the cumulative distribution or the inverse cumulative or change the kernel that is used. You can look up the list of options from the link provided. This should help you get started :)