Creating a symbolic function dynamically given an array of data

I have a function that is based on the numeric values of a random sample that I would like to maximize:

data = {17.88, 28.92, 33.0, 41.52, 42.12, 45.6, 48.8, 51.84, 51.96,
54.1, 55.56, 67.8, 68.64, 68.88, 84.12, 93.12, 98.64, 105.12,
105.84, 127.92, 128.04, 173.4}

loglike[n_,l_,x_]:= n*Log[n] - n*Log[-Sum[Log[1-Exp[-l*x]],{x,data}]]


If I create an array of values representing my random sample, can I easily create a function dynamically based upon this array and subsequently maximize. For example, passing the above array in as X, n as length of the array, and leaving l symbolic.

• Apologies. I think I've corrected. I would like to use Sum since this I'd like to represent the the summation of a function of the sequence. – PatternMatching Mar 10 '15 at 0:23

As you surely know, the likelihood of a dataset (or log-likelihood) is the (log of) probability you select that dataset randomly from a candidate distribution. As such, the proper way is to use (for a Gaussian, for instance):

LogLikelihood[NormalDistribution[0, 1], data]


(* -73126.5 *)

If you want it as a parameterized function (e.g., by the mean of a Gaussian), you have:

LogLikelihood[NormalDistribution[μ, 1], data]


$-11. \left(\mu ^2-144.802 \mu +6646.03\right)-11 (\log (2)+\log (\pi ))$

More generally, for both the mean and variance:

 LogLikelihood[NormalDistribution[μ, σ], data]


$-\frac{11. \left(\mu ^2-144.802 \mu +6646.03\right)}{\sigma ^2}-22 \left(\log (\sigma )+\frac{1}{2} (\log (2)+\log (\pi ))\right)$

You can put in any appropriate continuous one-dimensional distribution you like (BetaDistribution, LaplaceDistribution, etc.)