I tried to run this function in MATLAB:
function llik = log_likelihood(p)
global d;
N = length(d);
tau = fzero(@(t) (t - (t^2 * p + 1 - p) / (2 * (t * p + 1 - p))), [0,1]);
loglik = 0;
for i = 1 : N
loglik = loglik + log(isnan(d(i)) * (1 - p * (1 - tau) + ~isnan(d(i))* p * (1 - tau)));
end
llik = loglik / N;
end
Here, p is a scalar. MATLAB gives me an error warning saying
Error using fzero>localFirstFcnEval
FZERO cannot continue because user-supplied function_handle ==>
@(t)(t-(t^2*p+1-p)/(2*(t*p+1-p))) failed with the error below.
Unrecognized function or variable 'p'.
I am confused since p should be the argument of the function. How can it be unrecongized? Thank you for your help!
