-1

i have generated data using some other code and that is perfectly fine

the below written code is for estimating and i am getting error as Check for incorrect argument data type or missing argument in call to function 'matlabFunction'.

Error in newMLE (line 27) custLogFn = matlabFunction(custLog);

CODE

syms alphahat betahat thetahat i A;
Ayi = (1 + thetahat*y0); % ()=(1+);

rn1 = r(1:n1);
Term2 = (rn1+1).*(Ayi.^alphahat);

Byi = (1+ thetahat*(tau + betahat *(y1 -tau))); %{1+(+(−))};

rn2 = r(n1+1:m);
Term3 = (rn2+1).*(Byi.^alphahat);

q1=m*log(alphahat);
q2=m*log(thetahat);
q3=(m - n1)*log(betahat); 
q4=(alphahat - 1)*log(sum(Ayi));
q5=sum(Term2);
q6=(alphahat-1)*log(sum(Byi)) ;
q7=sum(Term3);

custLog = @(y,alphahat,betahat,thetahat)(q1 + q2 +q3 + q4 - q5 + q6 - q7);

custLogFn = matlabFunction(custLog); 

% alpha = 1.7; beta = 1.3; theta = 1.5;%Assumed values
[phat, pci] = mle(y, 'nloglf', custLogFn, 'start',[1.7, 1.3, 1.5]);

1 Answers1

1

You are mixing up symbolic expressions and anonymous functions. custLog is now an anonymous function with inputs @(y,alphahat,betahat,thetahat), but the symbolic variables in q1 till q7 will not be substituted by them.

You didn't post an minimal reproducible example, but look at the following:

syms a b c

% define separate symbolic expressions
f1 = a*sin(b);
f2 = c*cos(a);

% combine them as required into a new symbolic expression 
f3 = (f1 + f2); 

% convert this symbolic expression to an anonymous 
%     function with input variables in specified order
fn = matlabFunction(f3, 'Vars', [a,b,c])
rinkert
  • 6,593
  • 2
  • 12
  • 31
  • I modify code to this `custLog = (q1 + q2 +q3 + q4 - q5 + q6 - q7); custLogFn = matlabFunction(custLog,'Vars', [alphahat,betahat,thetahat]);` but now mle is giving error as too many imput arguments Caused by: Error using symengine>@(alphahat,betahat,thetahat)log(alphahat).*3.4e.... – Mayank Aggarwal Apr 07 '21 at 17:37