0
$\begingroup$

I have imported data (mat is the name, 1x100 dimensional vector)and written a likelihood function for normal distribution.

f[miu_, sigma_] := -1/2 Log[2 Pi sigma] - (mat - miu)^2/(2 sigma^2)
Minimize[{Total[f[miu, sigma]] && miu ≥ 1 && sigma ≥ 1}, {miu, sigma}]

However this gives me error

NMinimize::nnum: Function value False at{miu, sigma} = {-0.936293, 0.280416}is not a number

Can anyone tell me what I am doing wrong?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Apr 10 '15 at 2:51
  • $\begingroup$ If this error occurs with a shorter vector, please provide it, so that readers can reproduce your problem. $\endgroup$ – bbgodfrey Apr 10 '15 at 2:54
  • $\begingroup$ You are giving a Boolean expression in the place of an objective function. The error message kind of makes that clear.. $\endgroup$ – Daniel Lichtblau Apr 10 '15 at 15:21
1
$\begingroup$
mat = RandomVariate[NormalDistribution[2, 6], 200];
f[miu_, sigma_] := -1/2 Log[2 Pi sigma] - (mat - miu)^2/(2 sigma^2) // N // Total;
NMaximize[{f[miu, sigma], 1 <= miu <= 5 && 1 <= sigma <= 5}, 
           {miu, sigma}, Method -> "NelderMead"]

(* {-502.338, {miu -> 2.01306, sigma -> 5.}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.