-1
$\begingroup$

I'm trying to fit the following list data

R = {0, 10^-8, 10^-7, 10^-6};
ub = {500, 25, 1, 0.038}/500
b = N[1 - ub]
data = {R[[#]], b[[#]]} & /@ Range[Length[R]];

with the following function

(ka r)^h/(1 + (ka r)^h)

using FindFit:

FindFit[data, Abs[(ka r)]^h/(1 + Abs[(ka r)]^h), {h, ka}, r] 

I get ridiculous results if I use Abs[] or no Abs[] and if I keep my zero data point or not, or if I change "Method"

I was originally using NonlinearModelFit, except the results it was giving me were oddly written. I've tried all the Methods -> options and none are yielding good models, whether or not I use Abs[] or not, or have an initial guess. If I use an initial guess the results I get returned are using my initial guess, which isn't right.

Does anyone have suggestions for picking Method + using Abs[] to appropriately find ka and h in this model?

$\endgroup$
  • $\begingroup$ Don't blame NonlinearModelFit or Methods->. Blame whoever taught you Statistics. You are attempting to fit 3 parameters (h, ka, and the error variance) with only 4 data points. $\endgroup$ – JimB May 5 at 5:25
0
$\begingroup$

I'm not exactly sure why FindFit has a problem with this one, so maybe others can help with that aspect. I get the error

The gradient is not a vector of real numbers at {h, ka} = {1.5, 1.x10^6}

Since your function evaluates to a real number for positive ka, r, and h, I don't think Abs is necessary. I tried using NMinimize instead. I've seen a few people on this site use it instead of the fitting functions to great effect, so I've started to use it more often myself.

model[ka_, r_, h_] := (ka r)^h / (1 + (ka r)^h)

{rmse, params} = NMinimize[
  Sqrt[Mean[(model[ka, data[[All, 1]], h] - data[[All, 2]])^2]],
    10^6 < ka < 10^10,
    0.5 < h},
  {ka, h}
]
(* {1.59966*10^-7, {ka -> 7.96023*10^8, h -> 1.41938}} *)

Show[
 Plot[
  model[ka, r, h] /. params,
  {r, 0, 10^-6},
  ImageSize -> 500,
  PlotRange -> Full,
  PlotStyle -> ColorData[75][5]
 ],
 ListPlot[
  data,
  PlotStyle -> Directive[ColorData[85][1], AbsolutePointSize[8]]
 ]
]

Fit of data using NMinimize.

Log-log fit of data using NMinimize.

In the second plot, I added ScalingFunctions -> {"Log", "Log"} to both Plot and ListPlot. Sometimes log-log plots show anomalies that might be hidden by linear plots.

It looks to me like this gets us a fairly good fit, and the root-mean-square-error is on the order of $10^{-7}$, which seems pretty decent.

$\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.