function [y] = lnnormlike(theta,x); % This is the NEGATIVE of the log likelihood function for X ~ N(mu,sig2) %-------------------------------------------------------------- % OUTPUT: y = value of the likelihood function given: % INPUT: theta = is a vector of the parameters of the distribution % theta(1,1) = mu - first entry of the vector is mu % theta(1,2) = sigma2 - second entry is variance % x = our vector of 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 when we %only have one variable. Here we have two variables. m = size(x,1); y = -(m*log(1/sqrt(2*pi*theta(2))) - (1/(2*theta(2)))*(sum((x - theta(1)).^2)));