Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Hot answers tagged

14

Addition: 95% confidence bands for the mean added. (* Convert from degrees to radians *) datar = Import["https://pastebin.com/raw/CM7Rj6jC", "Table"]; datar[[All, 1]] = 2 π datar[[All, 1]]/360; (* Fit curves *) nlm1 = NonlinearModelFit[datar[[All, {1, 2}]], a Cos[t + ϕ]^2, {a, ϕ}, t]; nlm2 = NonlinearModelFit[datar[[All, {1, 3}]], a Cos[t + ϕ]^2, {a, ϕ}, ...


9

data = {{Sin[21*2*Pi/360], 587.6}, {Sin[339.5*Pi/180], 587.6}, {Sin[(360 - 342.5)*Pi/180], 501.5}, {Sin[18*Pi/180], 501.5}, {Sin[(360 - 343.8)*Pi/180], 471.3}, {17.8*Pi/180, 471.3}, {Sin[16.6*Pi/180], 438.8}, {Sin[(360 - 343)*Pi/180], 438.8}, {Sin[19.6*Pi/180], 546.1}, {Sin[(360 - 341)*Pi/180], 546.1}, {Sin[15.5*Pi/180], 435.8}, {Sin[(360 ...


7

An alternative to Jim's proposal is to directly use the definition for least-squares fitting: datar = Import["https://pastebin.com/raw/CM7Rj6jC", "Table"]; datar[[All, 1]] = datar[[All, 1]] °; d1 = Drop[datar, None, {3}]; d2 = Drop[datar, None, {2}]; {a1, φ1} = NArgMin[Norm[Function[{θ, r}, a Cos[θ + φ]^2 - r] @@@ d1], {a, φ}] {0.530572, -0.584595} {...


6

Notice the y-axis range of the data (~20000), compared to the plot of the model (~0.005) . If you add an amplitude parameter to the model, it works much better. peakresponse[a_, β_, e1_, e2_] := a (Abs[β*e2*π])^(-1/2)*Exp[(-(e1 - e2)^2/(2*β*e2))] nlmbeta = NonlinearModelFit[databeta, peakresponse[a, β, e1, e2], {{a, 3000000}, {β, 80}, {e2, 100}}, ...


5

$Version (* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *) data = Table[{x, N[x Sin[x]]}, {x, 0, 4, .3}]; FindFormula does not necessarily give a consistent result. Its algorithms make use of a random seed and as the seed evolves so can the results. For example, Table[FindFormula[data, x], {10}] (* {1. x Sin[x], x Sin[x], x Sin[x], x Sin[Abs[x]], ...


5

LogPlot plots $\log y$ vs. $x$, so the slope in the plot is given by $$m = {d \over dx} \log y = {dy/dx \over y} \,.$$ If you let f be your function, whether that is an InterpolatingFucntion[...][x] or some other function, the slope of the tangent to use in the LogPlot at x == x0 will be given by D[f, x]/f /. x -> x0 Note that the tangent "line" ...


4

You'll likely want NonlinearModelFit rather than LogitModelFit as the latter assumes that the response variable has a binomial distribution given the prediction model. Consider the following "logit" model: $y=a/(1+\exp(-k(t-b)) + e$ where $e\sim N(0,\sigma^2)$ and $a$, $b$, $k$, and $\sigma^2$ are parameters to be estimated. That's 4 parameters with only ...


4

The usual way that I would treat this sort of data would be to assign explicit x-values and then fit to a known model while excluding the Missing[] points. Your data looks pretty Gaussian to me, though it's usually best if you can justify the model first and then apply it. Here, I'm taking a guess at a model and then justifying it because it looks good, but ...


4

Sorry, I didn't realize that you linked to the data in your post, but as @Roman noted, the InterpolatingFunction seems broken. Anyhow, I managed to extract enough to find another problem besides @Roman's comment to use LogPlot[Exp[linearpart], ...]. Specifically, your Table doesn't include x-coordinates, so Fit assumes they are 1, 2, 3, ... Instead try: ...


4

The form of LinearModelFit that you are trying to use is LinearModelFit[{m, v}] where m is a design matrix, and v is a response vector. But in your input, m, is {0, 1, 3, 5}, which is not a matrix. Try this instead: LinearModelFit[{ {{0}, {1}, {3}, {5}}, {1, 0, 2, 4} }, IncludeConstantBasis -> False ]


4

Since you have only one paramter, you can use Grid Search method. $\epsilon_t=y_t-\beta x_t$ and $error=\sum_{i=1}^4(y_i-\beta x_i)^2$. We see that $0\leq\beta\leq 1$ from ListPlot. data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}}; ListPlot[data, AspectRatio -> 1] ϵ[β_] := Total[(#2 - β #1)^2 & @@@ data] βval = Subdivide[0, 1., 100000]; Extract[βval, ...


3

As an alternative you could use the other structure for LinearModelFit: data = Transpose[{{0, 1, 3, 5}, {1, 0, 2, 4}}] lm = LinearModelFit[data, x, x, IncludeConstantBasis -> False]; lm["ParameterTable"]


3

This is one of those unique moments where immediate assignment (=) for functions comes in handy. Like I suggested in my comment, you can compute the limit symbolically, and then use Piecewise to bake the limit into the singularity of the function: FTCos[A_, \[Nu]0_, T_, n1_, \[Nu]_] :=Sqrt[((A^2 (\[Nu] Cos[\[Pi] T \[Nu]0] Sin[\[Pi] T \[Nu]]-\[Nu]0 Cos[\[Pi] ...


2

One possibility is to use GroupBy: assoc = GroupBy[{{0,4},{1,2},{1,3},{2,3}},First->Last,Mean] <|0 -> 4, 1 -> 5/2, 2 -> 3|> You can actually plot this association directly: ListPlot[assoc] But you might want to convert this to list of pairs: KeyValueMap[List] @ assoc {{0, 4}, {1, 5/2}, {2, 3}}


2

BezierCurve only is a Graphics3D-object. Use BezierFunction to describe a function. Examplary here I give the calculation of the curvature kappa of the BezierFunction pts = Table[{2 Cos[t], 2 Sin[t], 3*t}, {t, 0, 6, 0.01}]; x = BezierFunction[pts] kappa = Sqrt[#.#] &[ D[x'[u]/Sqrt[x'[u].x'[u]], u]/Sqrt[x'[u].x'[u]]]; Plot[kappa, {u, 0, 1}, PlotRange -&...


1

This is how you can generate an expression with constraints in the appropriate form: gmodel[n_Integer] := Module[{forms, cons}, {forms, cons} = Transpose@Table[g[x, Sequence @@ kvar[i]], {i, 1, n}]; {Total[forms], Sequence @@ cons} ] gmodel[3] This assumes that we're using the definition of g given in your question, and all the other definitions ...


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