Skip to main content
Removed an extra ",]".
Source Link
JimB
  • 44k
  • 3
  • 54
  • 110

You are fitting a curve that has a shape of a known probability distribution and NOT fitting a probability distribution. This is a regression.

After throwing out the complex numbers (as suggested by @BobHanlon) and throwing out the negative response values, one can use NonlinearModelFit. Fitting the log of the curve is more numerically stable when using NonlinearModelFit.

xmax = Max[data[[All, 1]]] + 0.0001; data2 = data; data2[[All, 2]] = Log[data[[All, 2]]]; nlm = NonlinearModelFit[data2, {logc - (xmax - x)/b + a Log[xmax - x], b > 0 && a > 0}, {{a, 0.5}, {b, 2}, {logc, -11}}, x]; nlm["BestFitParameters"] (* {a -> 0.523033, b -> 2.03643, logc -> -11.2393} *) Show[ListPlot[data, PlotRange -> All, Joined -> True, PlotStyle -> {{Yellow, Thickness[0.02]}}],], Plot[Exp[nlm[x]], {x, Min[data[[All, 1]]], xmax}, PlotRange -> All, PlotStyle -> Red]] 

Data and fit

You are fitting a curve that has a shape of a known probability distribution and NOT fitting a probability distribution. This is a regression.

After throwing out the complex numbers (as suggested by @BobHanlon) and throwing out the negative response values, one can use NonlinearModelFit. Fitting the log of the curve is more numerically stable when using NonlinearModelFit.

xmax = Max[data[[All, 1]]] + 0.0001; data2 = data; data2[[All, 2]] = Log[data[[All, 2]]]; nlm = NonlinearModelFit[data2, {logc - (xmax - x)/b + a Log[xmax - x], b > 0 && a > 0}, {{a, 0.5}, {b, 2}, {logc, -11}}, x]; nlm["BestFitParameters"] (* {a -> 0.523033, b -> 2.03643, logc -> -11.2393} *) Show[ListPlot[data, PlotRange -> All, Joined -> True, PlotStyle -> {{Yellow, Thickness[0.02]}}],], Plot[Exp[nlm[x]], {x, Min[data[[All, 1]]], xmax}, PlotRange -> All, PlotStyle -> Red]] 

Data and fit

You are fitting a curve that has a shape of a known probability distribution and NOT fitting a probability distribution. This is a regression.

After throwing out the complex numbers (as suggested by @BobHanlon) and throwing out the negative response values, one can use NonlinearModelFit. Fitting the log of the curve is more numerically stable when using NonlinearModelFit.

xmax = Max[data[[All, 1]]] + 0.0001; data2 = data; data2[[All, 2]] = Log[data[[All, 2]]]; nlm = NonlinearModelFit[data2, {logc - (xmax - x)/b + a Log[xmax - x], b > 0 && a > 0}, {{a, 0.5}, {b, 2}, {logc, -11}}, x]; nlm["BestFitParameters"] (* {a -> 0.523033, b -> 2.03643, logc -> -11.2393} *) Show[ListPlot[data, PlotRange -> All, Joined -> True, PlotStyle -> {{Yellow, Thickness[0.02]}}], Plot[Exp[nlm[x]], {x, Min[data[[All, 1]]], xmax}, PlotRange -> All, PlotStyle -> Red]] 

Data and fit

Source Link
JimB
  • 44k
  • 3
  • 54
  • 110

You are fitting a curve that has a shape of a known probability distribution and NOT fitting a probability distribution. This is a regression.

After throwing out the complex numbers (as suggested by @BobHanlon) and throwing out the negative response values, one can use NonlinearModelFit. Fitting the log of the curve is more numerically stable when using NonlinearModelFit.

xmax = Max[data[[All, 1]]] + 0.0001; data2 = data; data2[[All, 2]] = Log[data[[All, 2]]]; nlm = NonlinearModelFit[data2, {logc - (xmax - x)/b + a Log[xmax - x], b > 0 && a > 0}, {{a, 0.5}, {b, 2}, {logc, -11}}, x]; nlm["BestFitParameters"] (* {a -> 0.523033, b -> 2.03643, logc -> -11.2393} *) Show[ListPlot[data, PlotRange -> All, Joined -> True, PlotStyle -> {{Yellow, Thickness[0.02]}}],], Plot[Exp[nlm[x]], {x, Min[data[[All, 1]]], xmax}, PlotRange -> All, PlotStyle -> Red]] 

Data and fit