1
$\begingroup$

I would like to do something like the example I drawed manually:

data = MapAt[DateString[{#, {"Day", "/", "Month", "/", "Year"}}] &,
  Import["D:\\Analytics www.superinformati.com Panoramica del pubblico 20141201-20150303 - Sheet 1.tsv"][[3 ;;, {1, 2}]]
 , {All, 1}]

tsm = TimeSeriesModelFit[data]

DateListPlot[{tsm["TemporalData"]}]

enter image description here

The series of data is here

$\endgroup$
  • $\begingroup$ It's probably best to merge this question with your other one since they are very related. $\endgroup$ – bobthechemist May 8 '15 at 18:08
  • $\begingroup$ @bobthechemist: the set of data is the same, but you have already answered this pretty well. As you prefer.. $\endgroup$ – Revious May 8 '15 at 21:52
3
$\begingroup$

This may be useful..

 sampledata =
      {#, 
      Piecewise[ {{ 1 + # , # < 1}  , { 6 (# - 1) + 2 , # > 1} }]
      (1 + RandomVariate[NormalDistribution[0, .2]])} & 
         /@ RandomReal[{0, 2}, 50];


 Manipulate[
     fit = NonlinearModelFit[ sampledata , 
       Piecewise[ {{ a + b  x , x <= m }  ,
                 { c (x - m) + a + b m , x > m} }] , {a, b, c} , x];
     Show[{ListPlot[sampledata, Epilog -> Inset[Grid[{{
         "R^2=" <> ToString[fit["RSquared"]], "m=" <> ToString[m]},
          fit["BestFitParameters"]}], Scaled[{.4, .75}]]],
       Plot[fit@x, {x, 0, m}, PlotStyle -> Red],
       Plot[fit@x, {x, m, 2}, PlotStyle -> Blue]}], {{m, 1}, 0, 2}]

enter image description here

For this simple case it works well if you also make the transition point a fit parameter:

 Clear[m];
 fit = NonlinearModelFit[ sampledata , 
     Piecewise[ {{ a + b  x , x <= m }  , 
                { c (x - m) + a + b m , x > m} 
               }] ,  {a, b, c, m} , x];
 x0 = m /. fit["BestFitParameters"];
 Show[{ListPlot[sampledata],
     Plot[fit@x, {x, 0, x0}, PlotStyle -> Red],
     Plot[fit@x, {x, x0, 2}, PlotStyle -> Blue]}]

In general you are likely better off doing that by hand though

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.