function y = lnbernoufoc(r,x); % This is the FOC w.r.t. r of the log likelihood function for X ~ Bernoulli(p) %-------------------------------------------------------------- % OUTPUT: y = value of the partial of the log likelihood function w.r.t r % INPUT: r = Bernoulli parameter, we've diff w.r.t. it to get the FOC. % 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/r(1) - m*(1-xbar)/(1-r(1));