# Tag Info

1

As @SjoerdSmit mentioned in the comments, I had a syntax error for the 'data' section of my FindFit function. It should read {{1000, Pi/2}} instead of how I had written it above. This is because the first argument of FindFit should be a SET of data. Thanks to Sjoerd!

16

A least squares approach: model = a/((x - x01)^2 + c y^2) + a/((x - x02)^2 + c y^2) $\frac{a}{c y^2+(x-\text{x01})^2}+\frac{a}{c y^2+(x-\text{x02})^2}$ If we assume the equation will be model==1, then the sum of the squares of the residuals will be: errorfunc = Total[(1 - (model /. {x -> #[[1]], y -> #[[2]]} &) /@ data)^2]; Then, minimizing ...

5

Others might have a much better way, but wanted to look into the residuals and found that fitting two sines one after the other does actually a pretty good job. Also, I scaled your values up by 10^8 just to be sure there are no numerical issues. I'll just leave the code here and see for yourself how many of the parameters you need. pts = {2.29398, 16.4984, ...

2

One can't use FindDistributionParameters once the data becomes binned. However, one can construct the log of the likelihood function and then use FindMaximum as long as you still have the counts. (The relative frequencies won't do.) (* Generate histogram data with unequal bin widths *) SeedRandom[12345] x = RandomVariate[WeibullDistribution[2, 3], 1000]; {...

5

One can't expect much with estimating 5 coefficients (a, b, c, d, and error variance) with just 7 points. That also makes it difficult for getting convergence to the maximum likelihood or least-squares estimates as good starting values become more critical. (The default starting values are all 1.0 and most of the final estimates are far away from 1.0.) ...

3

This is an extended comment. You do not have a situation where a regression is an appropriate analysis (other than maybe to get starting values). It appears (from the original data and your comment that you are sampling from a distribution) that you have a sample from which you created a histogram on a log scale of the sampled variable. Then you provided ...

3

A simple solution without rationalization and with standard accuracy data = {{172.345, 0.000710716}, {136.899, 0.00238143}, {108.742, 0.00822192}, {86.3772, 0.0117385}, {68.6119, 0.0123856}, {54.5003, 0.0147863}, {43.2912, 0.0148628}, {34.3874, 0.0131214}, {27.3149, 0.00879578}, {21.697, 0.00634049}, {17.2345, 0.00310614}, {13.6899, 0....

3

In order to avoid the overflow you can rationalize the numbers and increase the working precision. In order to get the process going in the direction you want you can put constraints. (Also, you might try to experiment using NonlinearModelFit.) data2 = Map[Rationalize[#, 10^-12] &, data, {-1}]; pars = FindFit[data2, {function, 70 > c > 20, 4 &...

2

I agrees with JimB. Here is a visualization of dataB and the surface you fitted to it which shows how far from a plane both the data and the model are. The low $r^2$ value seems entirely appropriate. Remember that $r^2$ is a measure of linearity (flatness in 3D) and not a measure of goodness-of-fit. Block[{blue, lollies}, blue = RGBColor[0., 0.59, 1.]; ...

5

It's your expectations that are wrong. The estimation process is working fine. Take a look at the data and the predicted surface for both sets of data. Show[ListPointPlot3D[dataA, PlotRange -> {All, All, {-3, 7}}, AxesLabel -> (Style[#, Bold, 18] &) /@ {"x", "y", "z"}], Plot3D[lmA[x, y], {x, 0, 1}, {y, 0, 1}], ImageSize -> Large] Show[...

3

Without the curves identified (both as to collection of points and functional form of curves) there is going to be a lot of arbitrariness and tuning parameters. Here's one approach: (* Bandwidth *) w = 0.4; (* Range of x values to consider *) {xmin, xmax} = MinMax[points[[All, 1]]] x0 = xmin - w/2.2 (* Adjustment of min and max to have the extreme points ...

1

Edit: I added what I hope is a real answer (bad pun intended). The linear model needs to be made explicit as there can be models that might look similar but are really parameterized very differently and would imply possibly very different analysis procedures and interpretation of results. Using the notation from @whuber 's answer from CrossValidated, if ...

0

The default assumption that NonlinearModelFit makes to compute these statistics, is that the residuals are normally distributed. You can access the residuals easily with fit["FitResiduals"] and obviously these are also complex values now, so what does it mean exactly to say that these residuals are normally distributed? Normal distributions generate real ...

25

All 3 previous answers show how to "fix" the issue. Here I'll show "why" there is an issue. The cause of the issue is not the fault of the data. It is because of poor default starting values and because of the form of the predictive function. The predictive function divides by $a+b x$ and this blows things up when $a+b x=0$. Below is the code to show ...

9

Try Method-> "NMinimize", no need to specify something else: sol = FindFit[data, 1./(a + b/x), {a, b}, x, Method -> "NMinimize"] Show[{ListPlot[data],Plot[1./(a + b/x) /. sol, {x, -.1, 0}, PlotRange -> All]}]

7

You can override the default method by DifferentialEvolution which is more robust at the cost of converging slower. FindFit[data, 1./(a + b/x), {a, b}, x, Method -> {"NMinimize", Method -> "DifferentialEvolution"}] {a -> 38.491561, b -> -0.29188008}

8

OK, I got it: the initial guess makes all the difference. FindFit[data, 1./(a + b/x), {{a, 51}, {b, -.3}}, x] (* {a -> 38.4916, b -> -0.29188} *) I was just surprised that MMA went "so far" to find a local minimum.

2

Basically in all variants below we are trying to not let high degree polynomials be used. (Less than degree 12 produced by InterpolatingPolynomial.) Interpolation Using Interpolation instead of InterpolatingPolynomial. Clear[B16] B16[l_] := Evaluate[Interpolation[dados16, l, InterpolationOrder -> 2] // Expand]; Plot[B16[l], {l, Min[dados16[[All,...

2

Does the function have to go through all of the points? If not, how about fitting instead of interpolating. dados16 = {{10, 0.37}, {15, 0.47}, {20, 0.54}, {25, 0.61}, {30, 0.70}, {40, 0.80},{50, 0.90}, {60, 1.01}, {70, 1.10}, {80, 1.20}, {90, 1.31}, {100, 1.42}, {110, 1.53}}; fit = Fit[dados16, {1, x, x^(1/2)}, x] 0.104065 + 0.0701194 Sqrt[x] + 0....

3

The error message you get is the following: That error message concerns the restriction on the parameters when the parameters are replaced with the initial values. The restrictions must be just about the parameters (and any constants you throw in) so NonlinearModelFit doesn't know what x is in your restriction. Because of the form of the desired ...

1

Welcome to MSE. I believe the issue is that a is not defined in your model. I have corrected, so the following should work: data = Table[{x, (((x - 1.6)^2)/(16.456*(1 + Sqrt[1 - (1 + 0.65)*((x - 1.6)^2)/(16.456^2)]))) + 0.00032*(x - 1.6)^4 + .6554}, {x, -0.65, 4.073, .001}]; fit = NonlinearModelFit[ data, (((x - g)^2)/(c*(1 + Sqrt[1 - (...

Top 50 recent answers are included