0
$\begingroup$
T101msx = {-0.1, -0.7, -3.4, -0.7, -0.9, 5.5, 3.7, 2.6, 3.9, 3.5, 3.5,
6.7, 12, 21.1, 29.7, 39.5, 52.8, 67.7, 78.9, 95, 109.1, 123.7, 
139.6, 152.7, 163.9, 172, 181.5, 186.7, 192.8, 195.8, 192.4, 188.4, 
182.4, 167.3, 150.8, 136.9, 119.6, 105.3, 88.2, 71.2, 59.1, 44.6, 
30.5, 24.1, 15.8, 10.9, 7.8, 5.2, 3.7, 5.3, 4.3, 3.3, 1, 
0.6, -1.4, -3.3}
gp = ListPlot[T101msx]
eqn[x_] := 1/(Sqrt[2 Pi]*a)*Exp[-(x - b)^2/(2 a^2)]
FindFit[T101msx, eqn[x], {{a, 10}, {b, 30}}, x, Method -> "NMinimize"]

Out[53]:{a -> 0.00197028, b -> 30.0005}

Show[Show[ListPlot[T101msx, PlotStyle -> Red], 
Plot[eqn[x] /. {a -> 0.0019702769777831825`, b -> 30.000510344955828`}, {x, 1, 56}]]]

The parameters given by FindFit is obviously incorrect. Although I give parameter 'a' a initial value 10. What should I do? (Ignore those Chinese comments) Thank u. enter image description here

$\endgroup$
2
  • 3
    $\begingroup$ You should post your actual code instead of an image $\endgroup$
    – mattiav27
    Commented Oct 10, 2018 at 14:18
  • $\begingroup$ For whatever it's worth, my answer and @PratyayGhosh 's answer give identical predictions. Our models are equivalent but just parameterize the model differently. $\endgroup$
    – JimB
    Commented Oct 11, 2018 at 3:04

2 Answers 2

1
$\begingroup$

Mathematica is doing fine with the model you gave it. The problem is your model. You don't have a probability distribution being estimated from a random sample. You have a regression where you want to fit the same shape as a Gaussian curve - but multiplied by an appropriate constant so you need one more parameter.

T101msx = {-0.1, -0.7, -3.4, -0.7, -0.9, 5.5, 3.7, 2.6, 3.9, 3.5, 3.5,
   6.7, 12, 21.1, 29.7, 39.5, 52.8, 67.7, 78.9, 95, 109.1, 123.7, 
  139.6, 152.7, 163.9, 172, 181.5, 186.7, 192.8, 195.8, 192.4, 188.4, 
  182.4, 167.3, 150.8, 136.9, 119.6, 105.3, 88.2, 71.2, 59.1, 44.6, 
  30.5, 24.1, 15.8, 10.9, 7.8, 5.2, 3.7, 5.3, 4.3, 3.3, 1, 
  0.6, -1.4, -3.3}
eqn[x_] := a*Exp[-(x - b)^2/(2 c^2)]
sol = FindFit[T101msx, eqn[x], {{a, 200}, {b, 30}, {c, 10}}, x, 
  Method -> "NMinimize"]
(* {a -> 197.404, b -> 29.3913, c -> 7.46827} *)

Show[ListPlot[T101msx, PlotStyle -> Red], 
 Plot[eqn[x] /. sol, {x, 1, 56}]]

Fit to Gaussian shape

$\endgroup$
0
1
$\begingroup$

The Fit you are getting is absolutely correct. What I understand is you are trying to fit the data with a Normal distribution. In that case, your $a$ should be around $1/(198.5 \sqrt{2\pi})$ and $b$ should be close to $30$. You got it both correct.

However, the blue plot does not match the red plot because it is the 'wrong' function. The function you used is a probability distribution function and hence, $\int_{-\infty}^{\infty}eqn[x]dx=1$, But this is not true for your data. Just to clarify, due to the nature of your data, the parameter $a$ becomes very small. In computation, when you take a Normal distribution and make your $a$ very small you end up getting a Dirac Delta function. That's what you are getting here.

Try doing a normalization (as normal distribution is a probability distribution), that might help.

    data = T101msx/Total[T101msx]
    eqn[x_] := 1/(Sqrt[2 Pi]*a)*Exp[-(x - b)^2/(2 a^2)]
    sol = FindFit[data, eqn[x], {{a, 200}, {b, 30}}, x, Method -> "NMinimize"]

    Show[ListPlot[data, PlotStyle -> Red], 
    Plot[eqn[x] /. sol, {x, 1, 56}]]

enter image description here

$\endgroup$
3
  • $\begingroup$ JimB, sorry I do not have enough reputation to comment. I agree with you. I might be wrong in calling it a Precision error. What I understand is this is how we create a Dirac Delta function distribution. So the function should be zero (or very very small) away from $x=b$. That's what is happening here. $\endgroup$ Commented Oct 10, 2018 at 16:32
  • $\begingroup$ I edited my answer. Jim pointed out the fact that it is the 'wrong' function. I agree. $\endgroup$ Commented Oct 10, 2018 at 16:40
  • 1
    $\begingroup$ +1 The Dirac Delta result is a good observation. (Not scaling "probability distributions" when doing regressions is not an uncommon issue at this site.) $\endgroup$
    – JimB
    Commented Oct 10, 2018 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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