Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "SETUP";
- linear[A_, b_] := A + b*x;
- exponential[A_, k_] := A*Exp[k*x];
- logistic[A_, k_, s_] := A*k*Exp[k*x]/(A*s + k - A*s*Exp[k*x]);
- gaussian[A_, k_, z_] := A*Exp[k*x + z/2*x^2];
- FunctionFit[d_, f_, p_, x_] :=
- NonlinearModelFit[d, f @@ Transpose[p][[1]], p, x];
- LinearFit[d_, p_, x_] := FunctionFit[d, linear, p, x];
- ExponentialFit[d_, p_, x_] := FunctionFit[d, exponential, p, x];
- LogisticFit[d_, p_, x_] := FunctionFit[d, logistic, p, x];
- GaussianFit[d_, p_, x_] := FunctionFit[d, gaussian, p, x];
- Sigma[n_] :=
- Probability[-n < x < n, x \[Distributed] NormalDistribution[0, 1]];
- Confidence[x_] := Sigma[Sqrt[2] InverseErf[x/100]];
- FitStandardErrors[m_] := Diagonal[Sqrt[m["CovarianceMatrix"]]];
- FitDegreesOfFreedom[m_] := m["ANOVATableDegreesOfFreedom"][[2]];
- FitTFactor[m_, c_] :=
- InverseCDF[StudentTDistribution[FitDegreesOfFreedom[m]], (1 + c)/2];
- FitConfidenceLimit[m_, c_] := FitStandardErrors[m]*FitTFactor[m, c];
- FitCIs[m_, p_, c_] :=
- Transpose[{p - FitConfidenceLimit[m, c], p,
- p + FitConfidenceLimit[m, c]} /. m["BestFitParameters"]];
- cross = Graphics[{Line[{{-1, 0}, {1, 0}}], Line[{{0, -1}, {0, 1}}]}];
- FitPlots[f_, c_, u_, v_] :=
- Plot[{f @@ Transpose[c][[2]], f @@ Transpose[c][[1]],
- f @@ Transpose[c][[3]]}, {x, u, v}, PlotRange -> All,
- AxesOrigin -> {0, 0}, Filling -> {3 -> {2}},
- FillingStyle -> Directive[Opacity[0.5], Gray]];
- FitComparePlot[p_, f_, c_, u_, v_] :=
- Show[FitPlots[f, c, u, v],
- ListPlot[p["Data"], PlotStyle -> Black,
- PlotMarkers -> {cross, 1/20}]];
- "PROFIT BEFORE TAX";
- profitBeforeTaxData = {{0, 367357}, {1, 908188}, {2, 856965}, {3,
- 1120118}, {4, 1458694}};
- profitBeforeTaxFit["Linear"] =
- LinearFit[profitBeforeTaxData, {{A, 500000}, {b, 500000}}, x];
- profitBeforeTaxFit["Exponential"] =
- ExponentialFit[profitBeforeTaxData, {{A, 500000}, {k, 1/4}}, x];
- profitBeforeTaxCI["Linear", c_] :=
- FitCIs[profitBeforeTaxFit["Linear"], {A, b}, Confidence[c]];
- profitBeforeTaxCI["Exponential", c_] :=
- FitCIs[profitBeforeTaxFit["Exponential"], {A, k}, Confidence[c]];
- (*FitComparePlot[profitBeforeTaxFit["Linear"],linear,\
- profitBeforeTaxCI["Linear"],0,7];*)
- (*FitComparePlot[profitBeforeTaxFit["Exponential"],exponential,\
- profitBeforeTaxCI["Exponential"],0,7];*)
- "TURNOVER";
- turnoverData = {{0, 4344966}, {1, 5166722}, {2, 5630153}, {3,
- 6012395}, {4, 6500607}, {5, 7079930}, {6, 7823504}, {7,
- 8672722}, {8, 9923293}, {9, 10572549}, {10, 11121068}};
- turnoverFit["Linear"] =
- LinearFit[turnoverData, {{A, 500000}, {b, 500000}}, x];
- turnoverFit["Exponential"] =
- ExponentialFit[turnoverData, {{A, 500000}, {k, 1/4}}, x];
- turnoverCI["Linear", c_] :=
- FitCIs[turnoverFit["Linear"], {A, b}, Confidence[c]];
- turnoverCI["Exponential", c_] :=
- FitCIs[turnoverFit["Exponential"], {A, k}, Confidence[c]];
- (*FitComparePlot[turnoverFit["Linear"],linear,turnoverCI["Linear"],0,\
- 13];*)
- (*FitComparePlot[turnoverFit["Exponential"],exponential,turnoverCI[\
- "Exponential"],0,13];*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement