1

file.data has the following values to fit with Weibull distribution,

x       y 
2.53    0.00
0.70    0.99
0.60    2.45
0.49    5.36
0.40    9.31
0.31    18.53
0.22    30.24
0.11    42.23

Following the Weibull distribution function f(x)=1.0-exp(-lambda*x**n), it is giving error:

fit f(x) 'data.dat' via lambda, n

and finally plotting f(x) and xy graph have large discrepancy.

Any feedback would be highly appreciated. Thanks!

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
kuki
  • 403
  • 1
  • 5
  • 17

2 Answers2

1

Several things:

  1. You must skip the first line (if it really is x y).

  2. You must use the correct function (the pdf and not the CDF, see http://en.wikipedia.org/wiki/Weibull_distribution, like you did in https://stackoverflow.com/q/20336051/2604213)

  3. You must use an additional scaling parameter, because your data are not normalized

  4. You must select adequate initial values for the fitting.

The following works fine:

f(x) = (x < 0 ? 0 : a*(x/lambda)**(n-1)*exp(-(x/lambda)**n))
n = 0.5
a = 100
lambda = 0.15
fit f(x) 'data.dat' every ::1 via lambda, n, a

set encoding utf8
plot f(x) title sprintf('λ = %.2f, n = %.2f', lambda, n), 'data.dat' every ::1

That gives (with 4.6.4):

enter image description here

Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • 1. my file has multiple columns but {fit f(x) 'data.dat' u 4:($7) via lambda, n, a} did not work, 2. Thanks for the link, 3. How did you conclude additional parameter a = 100?, and 4. How did you make the right guess for n, a, and lambda? Many many thanks! – kuki Dec 03 '13 at 22:03
  • How did you do "half" pdf? I am always having "full bell shape" @Christoph – kuki Dec 03 '13 at 22:11
  • I used another parameter `a`, because your data is not normalized. I just played around with `a`, `lambda` and `n` to get close enough so that `fit` can work. The Weibull-distribution is defined only for positive `x`-values. The distinction is done inside `f(x)` with the check `(x < 0 ? ... : ...)`. – Christoph Dec 03 '13 at 22:29
  • Thanks, but how did you do the half plot? I am always having full bell shape. :/ – kuki Dec 04 '13 at 03:47
  • I used exactly the script shown in the answer with version 4.6.4. and `set terminal pngcairo size 600,400; set output 'foo.png'`. – Christoph Dec 04 '13 at 08:18
  • Oh I guess output.png shows the rendered half. On screen without output shows a full shape. Thanks! – kuki Dec 04 '13 at 17:00
  • No, that doesn't depend on the terminal, I see the same behaviour with `wxt` and version 4.2.6, 4.4.4, 4.6.4 and 4.7 (development version). Put a `reset` at the start of the script to exclude effects of previous commands. – Christoph Dec 04 '13 at 17:08
0

If that's the actual command you provided to gnuplot, it won't work because you haven't yet defined f(x).

Lee Phillips
  • 1,168
  • 8
  • 12