2

I have some data that when plotted I get an inclined graph, as described:

data = Import["p02q.dat", "Table"];

xdata = data[[All, 1]]; ydata = data[[All, 2]];

dataplot = Transpose[{xdata, ydata}];

plot2q = ListLinePlot[ dataplot, AspectRatio -> 1/GoldenRatio, ImageSize -> 800, PlotRange -> All, GridLines -> Automatic, InterpolationOrder -> 2, PlotMarkers -> {Automatic, 2}]

enter image description here

My intention is to get a leveled graph out of this one, like the one bellow: enter image description here

Could anyone suggest how to solve this, please? Data file can be downloaded here.

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
Florin
  • 21
  • 3

2 Answers2

3

Removing linear trend, as suggested in comments, is almost a one-liner (check out, Fit, FindFit, LinearModelFit):

data=Import["https://pastebin.com/raw/aWYk1Jba"];
lm=LinearModelFit[data,x,x];
ListLinePlot[Transpose[{data[[All,1]],lm["FitResiduals"]}],
PlotLabel->lm["BestFit"],PlotTheme->"Detailed"]

enter image description here

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
1

I different version of the workflow from Vitaliy's answer using both Quantile Regression and Least Squares fits. Note that the de-trending results are slightly different.

Get the QRMon package:

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MonadicProgramming/MonadicQuantileRegression.m"]

Get data:

data = Import["https://pastebin.com/raw/aWYk1Jba"];

Construct a QRMon workflow with data summarization, Quantile Regression and Least Squares fitting, and error plots:

qrObj = 
   QRMonUnit[data]⟹
    QRMonEchoDataSummary⟹
    QRMonQuantileRegression[1, 0.5, InterpolationOrder -> 1, Method -> {LinearProgramming, Method -> "InteriorPoint"}]⟹
    QRMonFit[{1, x}]⟹
    QRMonPlot⟹
    QRMonErrorPlots["RelativeErrors" -> False, PlotRange -> {-0.06, 0.16}];

enter image description here

enter image description here

enter image description here

Get the regression functions:

aFuncs = qrObj⟹QRMonTakeRegressionFunctions;
Map[Simplify[#[x]] &, aFuncs]

enter image description here

Get the errors, i.e., the signal de-trendings:

aErrors = qrObj⟹QRMonErrors["RelativeErrors" -> False]⟹QRMonTakeValue;
ListLinePlot /@ aErrors

enter image description here

Anton Antonov
  • 37,787
  • 3
  • 100
  • 178