# Tag Info

## Hot answers tagged fitting

12

The Experimental function FindFormula at the moment is using a combination of different methods: it combines non linear regression with Markov chain Monte Carlo methods (e.g. Metropolis–Hastings algorithm). In the future (possibly in 10.3) there will be an option allowing the user to choose which method to use.

8

Once upon a time, one of the Standard Packages bundled with Mathematica was the package NumericalMathTrigFit​. As the package has now been deprecated, I have taken it upon myself to slightly clean up the implementation inside the package. Here it is: trigFit[data_?VectorQ, n_Integer, {x_, x0_: 0, x1_}] := Module[{c0, clist, cof, k, m, t}, m = Min[n, ...

7

Two problems: first, Gaussian is not a built-in function in Mathematica; you need to use the form involving PDF and NormalDistribution instead. Second, the arguments of FindFit need to be in the order data, model, parameters, variable; you have the last two switched. The correct version would be as follows: model[x_] = ampl ...

6

Your problem is that you are not fitting raw data to a distribution, you are fitting the emperical PDF of that distribution (probably in terms of values, percentages pairs). That won't work as the functions you are using (I guess EstimatedDistributionor FindDistributionParameters) expect the raw measurement data, not frequencies. To deal with your specific ...

6

I am not sure FindDistributions is the approach you want. If I understand you wish to fit Gaussians (i.e. the probability density functions) to your data to estimate the peaks rather than estimate the Gaussian distribution parameters for a dataset you have some prior belief is normal. If the former is your aim there are obviously a variety of symmetric peak ...

6

If you're pretty sure it's an exponential, you can always take the logarithm of the data and do a linear fit to that: logdata = {#[[1]], Log[#[[2]]]} & /@ data; FindFit[logdata, c x + d, {c, d}, x] (* {c -> 8.2386*10^-8, d -> -87.7291} *) Note that c and d are related to the original parameters by $c = k$ and $d = \ln a$. This means that the ...

5

This is a perfect place to use WeightedData. dist = EstimatedDistribution[WeightedData @@ Transpose[data], WeibullDistribution[a, b]] Show[ListPlot[data], Plot[PDF[dist, x], {x, 0, 30}]] It is worth noting that observations with zero weights are ignored because they do not contribute to the likelihood.

5

First things first, let's shift the data to the origin. data = data - ConstantArray[{10*^8, 0}, 18]; Try some nice initial values: nlm = NonlinearModelFit[data, a Exp[k t], {{a, 0.01}, {k, 0.0000001}}, t]; nlm["BestFitParameters"] Show[ListPlot[data], Plot[nlm[t], {t, 0, 7*^7}], Frame -> True] (* {a -> 0.00497293, k -> 8.16492*10^-8} *) And ...

4

Using some of the other parameters of FindPeaks used in answer by @ubpdqn data = {{6, 2.1}, {6.25, 1.82394}, {6.5, 2.056}, {6.75, 2.48818}, {7, 5.73034}, {7.25, 11.3611}, {7.5, 11.5297}, {7.625, 10.6597}, {7.75, 14.5473}, {7.875, 13.7337}, {8, 14.291}, {8.125, 15.4141}, {8.25, 13.2849}, {8.375, 16.785}, {8.5, 14.6091}, {8.625, 17.0505}, ...

4

I doubt that this is very robust. Consider a simple change in the DE example in the Documentation: sol = y /. NDSolve[{y'[x] == y[x] Cos[x], y[0] == 2}, y, {x, -5, 300}][[1]]; times = N[Range[-5, 600]/9]; data = Transpose[{times, sol[times] + RandomReal[0.05, Length[times]]}]; lp = ListPlot[data, PlotRange -> All] Now FindFormula[data, x, 1, ...

4

With Guess who it is' idea, there is a temporary workaround to convert population data to lists and make it work with FindFormula. Assume data has been set like in the question. data2 = Transpose[{(AbsoluteTime /@ List /@ Range[First@#[[1]], First@#[[2]], First@#[[3]]]) &[#[[2]]], #[[1]]}] &[ Flatten[data[[2]][[1 ;; 2]], 1]]; ...

3

Here is a (simplified) implementation of Reinsch's smoothing spline, which is effectively equivalent to csaps() in MATLAB's Curve Fitting Toolbox. Fancier methods have come along since then (e.g. Wahba's cross-validation splines), but this old workhorse has still proved serviceable: SmoothingSplineFunction[dat_?MatrixQ, p : (_?NumericQ | Automatic) : ...

3

In order to fit various parts of the data you can use this Manipulate to set the start and stop indices (Note: In version 10.1 when you first open up the Manipulate variables to type in an index it will jump to a bad value. Just type in the good value and it will resurrect itself). Manipulate[ landfit = FindFit[signalpart2[[startIndex ;; stopIndex]], ...

3

I have to fit complex functions all the time and it is annoying that NonlinearModelFit does not take complex values. However, it will take a function of two variables so I split into real and imaginary parts and introduce a dummy second variable. Here is your function ClearAll[f]; f[r_] := A Cos[k r - \[Pi]/4 + \[Phi]1] Exp[I (-2 Log[r] + \[Phi]2)] Now ...

3

If all you want is a least-squares fit, the easiest way to do might just be to construct a function that is the sum of the squares of the residuals, and then feed it into FindMinimum. As a example, let's construct a data set of complex variables as a function of a real variable x: data = Table[{x, (0.719) x^(0.907 I) + RandomComplex[{-0.005 (1 + I), 0.005 ...

3

This may not be exactly what you want but maybit it will help you pose the question better ( I get the feeling you are jumping in to writing code without knowing what result you actually expect ) d = Import["D:/1092.txt", "Table"][[;; -2, {1, 3}]]; smooth = MovingAverage[d, 20]; ListPlot[smooth] d1 = Select[smooth, 1092.855 < #[[1]] < 1092.88 ...

3

You need to create a pure Function and Map it over the first level of tstlst like so: LinearModelFit[#, x, x] & /@ tstlst Now tstlst can have as many sets as you like without you having to know how many in advance.

3

In version 10.2 there is a new experimental function which might be what you are looking for: FindFormula. I suspect that a genetic programming algorithm (symbolic regression) is behind this new feature. See also my question here: What is behind Mathematica's experimental FindFormula function?

2

In version 10.2 there is a new experimental function which might be what you are looking for: FindFormula. I suspect that a genetic programming algorithm (symbolic regression) is behind this new feature. See also my question here: What is behind Mathematica's experimental FindFormula function?

2

As @Sjoerd C. de Vries states: one really wants to use the raw data. However, your data is binned with (I assume) the bin midpoints along with the associated relative frequency. And ideally you should account for the binning (although in this case it doesn't make much difference in the estimates and because as stated by others the fit is not hot anyway). ...

2

The original issue of a lack of convergence is because of the very large values of the independent variable and the use of the default starting values (and my understanding is that the default starting value for all parameters is 1.0). This can be fixed by standardizing the independent variable. (This is not a bad practice for just about any regression ...

2

There is no built-in way to accomplish what you want with NonlinearModelFit, or with the other fitting functions, unfortunately. Of course, you could write your own target function and NMinimize that, as belisarius has mentioned already in his answer. This is very general and not particularly difficult to do, but it does not give you access to the wealth of ...

2

If you are trying to estimate the best fitting distribution you might also try something along these lines. I typically prefer to work with distributions through the powerful built-in framework. I've chosen a RayleighDistribution* since your data does not contain values below zero. dist = EstimatedDistribution[WeightedData@@Transpose[data], ...

1

I don't think you need to bother with Dynamic for what you want to do. Consider the following, which uses a different model because you did not provide a sufficient information for me to use the one you are reefer to in your post. data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}}; fit = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x] ...

1

If you know the form you want to minimize, Mathematica provides several ways to do that. For example: data = {{1, 2, 1}, {2, 6, 7}, {3, 8, 9}, {4, 6, 5}, {5, 10, 12}, {6, 23, 18}}; y1[A_, B_, x_] := A*x + B y2[A_, B_, x_] := (A/2)*x + B s = Sum[(i[[2]] - y1[A, B, i[[1]]])^2 + (i[[3]] - y2[A, B, i[[1]]])^2, {i, data}]; NMinimize[s, {A, B}] (* {211.085, {A ...

1

Try this: t=Import["For Studies/Temperature.xlsx","Data"] And if your data has headers in the first row use this: t=Import["For Studies/Temperature.xlsx","Data"][[1]][[2;;]] and this will select only the first two columns: t=Import["For Studies/Temperature.xlsx","Data"][[1]][[2;;,{1,2}]] Hope this helps.

Only top voted, non community-wiki answers of a minimum length are eligible