Can I call R function in Matlab?

조회 수: 14 (최근 30일)
ABDULAZIZ ALTUN
ABDULAZIZ ALTUN 2020년 4월 3일
댓글: Hung Dao 2021년 1월 20일
I am trying to minimize a function written in matlab using R function known by optim
The matlab function is as follow
%% Like_R: function description
function [outputs] = Like_R(x_lf,S_inter,r,mu,sigma_epsilon, x_init,varphi,C)
% x_lf S the low frequency benchmark (i.e. annual stocks)
% S_inter X the matrix of indicators
% r the value for rho
% mu the autocorraltion of the shock
% sigma_epsilon sigma the standard error of the innovation
% varphi gamma the vector of coefficients associated with the indicators in X
c=size(S_inter,1);
M_1 =r*diag(ones(c-1,1),-1);
ey_M_1=inv(eye(c)-M_1);
Omega=(mu.^abs(repmat((1:c),c,1)'-repmat((1:c),c,1)))*(sigma_epsilon^2)/(1-mu^2);
Omega_x=ey_M_1*Omega*ey_M_1';
M_2=zeros(c,1);
M_2(1,1)=r;
Theta=x_lf-C*ey_M_1*(M_2*x_init+S_inter*varphi);
Log_likelihood = (-c/2)*log(2*pi) - c*log(sigma_epsilon^2)+ log(abs(1-mu^2)) - Theta'*inv(C*Omega_x*C')*Theta;
outputs=-Log_likelihood;
end
I have entries for each of x_lf, S_inter, and C. However, I want to find the input elements that minimizes the above function. In R, if this function has been writen there one can simply define another function in R known by lev.uncons this:
lev.uncons<-function(y){
Like_R(x_lf, S_inter,y[1],y[2],y[3], y[4],as.matrix(c(y[5],y[6])),C)
}
Then one can call the following function in R as
#you can use any optimisation algorithm
#with or without bondaries, priors,
solDnc<-optim(c(0.9,0.9, 0.5,1000,0.3), lev.uncons, method = "L-BFGS-B",
lower = c(0.1,0, -0.5,0.1,0.01), upper = c(1,0.999,Inf,1), hessian = TRUE)
What I want to do is to use matlab to call the minimization function optim in R. I know there is alternative such as min search or minimume constraint. But is there a way to do so from matlab?

답변 (1개)

Anmol Dhiman
Anmol Dhiman 2020년 4월 9일
  댓글 수: 1
Hung Dao
Hung Dao 2021년 1월 20일
Hi,
I got the following error:
"Error using openR (line 68)
Cannot connect to R.
Error using COM.StatConnectorSrv_StatConnector/Init
Error: Object returned error code: 0x80040013"
What should I do?
Thanks,
Hung

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by