Tag Info

New answers tagged

1

You can check the documentation about the option NominalVariables http://reference.wolfram.com/language/ref/NominalVariables.html NominalVariables is an option for machine learning functions such as LinearModelFit or Classify that specifies which variables should be treated as having discrete values specified by names. So LogitModelFit[{{300, 0, ...


10

Inspired by WReach's answer, I started playing with Query based approach and here's what I came up with: data = {"days" -> {1, 2, 6, 8}, "area" -> {3, 6, 8, 2}, "frequency" -> {1, 4, 4, 2}, "height" -> {2, 3, 11, 6}} With the data in the above form, we just create a Dataset simply as follows: dataset = Dataset[data]; Don't worry ...


13

I was playing around, trying to come up with a purely query-based solution. The result is by no means natural, but perhaps it holds some academic interest or will spark some insight into a better answer: Dataset[ { "days" -> {1, 2, 6, 8} , "area" -> {3, 6, 8, 2} , "frequency" -> {1, 4, 4, 2} , "height" -> {2, 3, 11, 6} } ][ Transpose, ...


3

If your data is most conveniently expressed as in the form {key_1 -> (val_11, val_12, ..., val_1n}, ..., key_m -> (val_m1, val_m2, ..., val_mn},} then it would be a good idea to define a function to create datasets directly form such data, which can be done as follows: rulesToDataset[data : {Rule[_, {__}] ..}] := Dataset[Association /@ ...


7

For your first question assuming you have the data in the following arrangement: data = {{1, 2, 6, 8}, {3, 6, 8, 2}, {1, 4, 4, 2}, {2, 3, 11, 6}} header = {"days", "area", "frequency", "height"} You can create the Dataset as follows: dataset = Dataset @ Map[AssociationThread[header, #] &] @ Transpose[data] While I think the above method is most ...


2

A similar thing happens in this question: How can the behavior of InterpolationOrder->0 be controlled? As @seismatica has pointed out, ListInterpolation[data, InterpolationOrder -> 0][0] yields data[[2]], not data[[1]] as might be expected. Thus the range of the interpolating function, over the fundamental domain does not include the first point in ...


3

End running the problem we can readily construct our own "zero order" interpolation function: myzero[t_] := (#[[1 + (Ceiling[Mod[t, 1] (Length@# - 1) ] )]]) &@ dataSource which gives your desired plot: ParametricPlot[myzero[t], {t, 0, 1}, AspectRatio -> Automatic] same closed figure as your InterpolationOrder-> 1 result note the ...


5

Even though OP's problem is resolved in the question's comments, I hope to provide an explanation of why the gap appears in the parametric plot. Namely, I think InterpolationOrder -> 0 (specifically as an option to ListInterpolation*) is the culprit, as it starts with a jump/step from the first data point to the second data point. As a result, the ...


0

Somebody could verify my code regarding the theory? To start getting the variance-covariance matrix I followed the code found here: Standard errors for maximum likelihood estimates in FindDistributionParameters And I elimitated the last part (Sqrt[Diagonal[cov]/len]]) as I also want to abtain the covariance matrix, so my code is: covariance[data_, dist_, ...


4

First, as @phosgene says in the comments, FindFit is your best bet. We can rearrange your de equation to be: g == Abs[c Sin[omega t + phi]] + k Now we can invoke FindFit: FindFit[data, Abs[c Sin[omega t + phi]] + k, {k, c, phi, omega}, t] {k -> -0.440862, c -> -0.31467, phi -> -2.60329, omega -> 1.08524} And Plot: Show[ListPlot[data, ...


1

An Alternative: a = Transpose[{ExpDataCycles, ExpDataMpa}]; b = Interpolation[a, InterpolationOrder -> 2]; c = LogLinearPlot[b[x], {x, 6., 10^6.}, GridLines -> Automatic]; d = ListLogLinearPlot[a, PlotStyle -> Red]; Show[c, d, PlotRange -> All, ImageSize -> 400]


4

@rcollyer's answer is 100% correct, though it is telling that the ListLogLinearPlot of your data follows a polynomial shape. This tells me that your y-values follows a polynomial function with your Log[x] values. The plots seem to confirm this, as the curve fits your data much better: Clear[ExpDataCyclesMpa, LeastSqr] ExpDataCyclesMpa = ...


1

Use LogLinearPlot, instead: ExpDataCyclesMpa = Transpose[{ExpDataCycles, ExpDataMpa}]; LeastSqr = Fit[ExpDataCyclesMpa, {1, x, x^2}, x]; Show[ListLogLinearPlot[Transpose[{ExpDataCycles, ExpDataMpa}]], LogLinearPlot[LeastSqr, {x, 1, 1100000}]]


0

Fit is a function that finds the linear combination of some given terms that best fits the data. This can also be used since sine Fourier series are linear combinations of Sin. len = Subtract @@ data[[{-1, 1}, 1]]; func = Fit[ data, Table[ Sin[(π n)/len x], {n, 1, 40}], x ] Show[ ListPlot[data], Plot[func, {x, 0, len}, PlotStyle -> {{Thick, ...


2

I took george2079's statement "Now I expect someone will show a built-in way to get this..." as a challenge, so I did the same thing using FindFit. Also, writing it this way seems more clear to me what the actual function being fitted is (but obviously relying on the internal FindFit function) len = (Max[#] - Min[#]) &@data[[All, 1]]; func = ...


4

I've done this from first principles: some random data: data = Table[{x + RandomReal[{-.05, .05}] + 4, Sin[x] + Sin[x/3] + RandomReal[{-.3, .3}]}, {x, 0, 12 Pi , .1}]; treat the discrete data as a function and and use trapezoidal integration: trule = Mean /@ Partition[ Differences@ {data[[1, 1]], ...


1

Searching the documentation for FitResiduals leads directly to LinearModelFit and NonlinearModelFit, where it is stated that "FitResiduals" -- difference between actual and predicted responses For example, pts = Table[{x, x + RandomReal[.1 {-1, 1}]}, {x, 0, 5, .2}]; fm = LinearModelFit[pts, x, x] Now fm["FitResiduals"] is the same as #2 - ...


1

One way to do this is to take the log of the data, and do a linear fit: fit = FindFit[ Transpose@{Log@ExpDatN, ExpDatMPa} , a + b ln , {a, b}, ln ] or fit to the log expression: fit=FindFit[ Transpose@{ExpDatN, ExpDatMPa} , a + b Log[n] , {a, b}, n ] (same result) Show[{ListLogLinearPlot[{Transpose[{ExpDatN, ExpDatMPa}]}, ...


10

I think what you're seeing is a consequence of the special model that you're using. The parameters a and b appear only linearly, so as long as they are the only fit parameters it is clear that the best approach for FindFit would be to perform a simple LeastSquares calculation. This is a matrix method that works over the complex numbers, and that's why you ...


7

For the reason why find fit fails when c is variable, please see the answer of Jens. One way to solve this is to use create the complex target function from real-valued parameters and set the NormFunction explicitely: f1[t_] := (br + I bi) + (ar + I ai)/(cr + I ci + t) fit = FindFit[data, f1[t], {ar, ai, br, bi, cr, ci}, t, NormFunction -> ...


4

My answer below is mostly inspired by the answers of @Matariki and @george2079, so thank you both for your efforts and insight. I also got some ideas (about minimizing least square) from here (warning: it's a Matlab SO). My approach is to minimize the least square errors/residuals/differences between the data and the fit function in terms of both real and ...


5

Your model function isn't allowing for a better fit. Are you sure that the model is correct? Below is a plot using a different model which allows to find better start values for a fit. Mind you I haven't done a fit. Show[ListPlot[Re[data]], Plot[Re[b + a/((-1.028 + 0.0492 I) + s)] /. {a -> -0.248 - 0.306 I, b -> -0.403 + 0.106 I}, {s, 0.45, ...


3

If you fit the real part of the data directly: FindFit[ Re[data] , Re[b + a/((-0.977727 + 0.0601085 I) + s)] , {{a, -.1}, {b, -.1}}, s] {a -> -0.0791299, b -> -0.121803} Gives a pretty good fit, and surprisingly not too bad in the complex part either. Better ... <-- not.. This explicitly does the least squares minimization over ...


2

You may be interested to know that we are working on a FindSimpleFit function that is intended to automate the finding of many common classes of curve, exponentials obviously included. This is similar to what Wolfram|Alpha Pro currently does when you upload a dataset that looks like a timeseries or scatterplot. Automation for the win!


3

As has been already commented you can specify Method or specify approximate parameter values as per Rahul Narain's comment. You can also use NonlinearModelFit,e.g.: nlm=NonlinearModelFit[data, {a Exp[- k t]}, {{a, 53000}, {k, 1/100}}, t] yields :448761. E^(-0.0128453 t) Visualizing fit: Plot[nlm[t], {t, 80, 200}, Epilog -> {Red, PointSize[0.02], ...


4

fit = FindFit[data, model, {a, k}, t, Method -> "NMinimize"]


1

The problem is that you specify a parametric function with 4 arguments (*{kme, kmn, j, eo}*) but only feed the function call two. You'd need to set the proper parameters but then this will work: x = ParametricNDSolveValue[{eqnBo == 0, Eb1[r, 0] == 0, eqnDe == 0, Ef1[r, 0] == 0, Derivative[1, 0][Ef1][rn, t] == 0, Ef1[ro, t] == eo}, Eb1, {r, ...


1

p1 = Histogram[data, {0, 9, 1}, "Count", ChartLegends -> {"Experimental Result"}, ChartStyle -> "Pastel"]; p2 = DiscretePlot[ Length@data*PDF[PoissonDistribution[2.2766917293233084`], x], {x, 0, 10}, PlotStyle -> {Red, Medium}, PlotLegends -> {"Theoretical Poisson"}]; Show[{p1, p2}, AxesLabel -> {"Time (s)", "Counts"}] ...


1

I've noticed that sometimes I get some small imaginary components due to error etc. You may want to use the Chop[] function to kill anything like that.


1

You might want to limit "shift" to positive only? Otherwise your function can be complex? I am guessing the value of "shift" Mathematica obtained from FindFit is negative.


2

I don't think there is anything unusual here that can't be found in the documentation. Normalization parameters in the x and y dimensions (b, and a, respectively) can be added into the model, as can the x-axis shift (parameter c). Parameter estimates are taken from a look at the original data. nlm = NonlinearModelFit[data, a Erfc[b (x + c)], {{a, 8 ...


2

I am a little unsure what the aim is here. Looking at the data only the first third of the plot could be fitted to Erfc like function. I post this, perhaps, as motivation. d = Transpose@data; ListPlot[ds = SortBy[d, #[[1]] &], Joined -> True] Extracting the part of plot I referred to: fd = ds[[1 ;; 35]] fdlp = ListPlot[fd] Now as a rather ...


5

The coordinates of the parametric curve consist of the solution of a fourth-order linear differential equation and its derivative. This is clear by inspection. First, we need the x coordinate in a form that can be differentiated: xOP = Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I 2.36121) Exp[(0.455 + I 1.099) t] + (-2.35438 ...


2

This maybe not an efficient way of doing this problem, but here is my approach: First you need to convert the parametric data into polar data. my way of doing this is as follows ( I don't know any better way to convert data from {x,y} to {t,r}): data = Table[{Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I ...


6

You can try to implicitize, sort of. I do this step by step so we can see what substitutions are needed. exprs = ExpToTrig[ Expand[Simplify[ Chop[ComplexExpand[{Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I 2.36121) Exp[(0.455 + I 1.099) t] + (-2.35438 + I 1.36651) Exp[(0.455 - I 1.099) t] ...



Top 50 recent answers are included