function y = lnbernoulike(r,x); % This is the NEGATIVE of the log likelihood function for X ~ Bernoulli(p) %-------------------------------------------------------------- % OUTPUT: y = value of the likelihood function given: % INPUT: r = Bernoulli parameter for minimization, we'll diff w.r.t. it. % parameters % x = vector of iid Bernoulli draws %Strangly, we've found that variables of interest need to be included as "r %subscript 1" which in MatLab is "r(1)". We had to do this even though we %only have one variable. m = size(x,1); xbar = mean(x); y = -(m*xbar*log(r(1)) + m*(1-xbar)*log(1-r(1)));