Calling R from Matlab

Update on 8 Jan 2011: A newer set of instructions can be found here. The notes below are somewhat out of date.

This uses the COM interface, so only works on Windows.

Trouble shooting

Example

A matlab wrapper to the glasso function.
function precMat = glassoR(C, rho, useMBapprox)
% Use L1-linear regression to find markov blankets and then Lambda.
% Uses R code from http://www-stat.stanford.edu/~tibs/glasso/
openR;
evalR('C<-1') % must pre-declare variable before writing a matrix
evalR('L<-1') 
putRdata('C',C);
putRdata('rho',rho);
putRdata('useMBapprox', useMBapprox)
evalR('stuff <- glasso(C,rho=rho,approx=useMBapprox)'); 
evalR('L <- stuff$wi') % inverse covariance matrix
precMat = getRdata('L');
closeR;