Y correction in a correlation plot

Hi all, I have plotted a Y vs X and then fitted the plot with a straight line. Now, ideally, there shouldn’t be any correlation b/w Y and X but I can see a slope (let’s say m1) in the fitted line so wanted to make a small correction in the Y ONLY. (something like Y_new = Y */+ some factor)

that means, after correcting the Y, the newly fitted line in the Y_new vs X will have a slope zero. Now I understand that I have to rotate the fitted line by some angle about a point (x0,𝑦0) in the +/- direction to get the Y_new. (seems like choosing the point can also be tricky but for the moment let’s take any point on either end of the boundary) But not sure how can I achieve this mathematically and in the code as well. Sorry if it seems trivial, I am kind of confused about it. A part of the plotting routine and fitting of the plot is given below

 ch1->Draw("(Y1-Y2): 1/TMath::Sqrt(X)>>hist1","","colz");
	cout << "slope1"<<"\t"<< fit1->GetParameter(1)<< endl;
	double slope1 = fit1->GetParameter(1);

and the fitted line looks like the image attached:

Do let me know if you have any suggestions! Thanks!!


ch1->Draw(TString::Format("(Y1 - Y2) - (%g / TMath::Sqrt(X)) : 1. / TMath::Sqrt(X)", slope1), "", "colz");

thanks for your note. unfortunately, it didn’t work. Also, I have tried similar corrections before; mostly meaningful hits and trials method; adding or multiplying constants. Needless to say, didn’t work either. However, I was looking for a more generalized way to rotate the fitted line regardless of the initial positive or negative slope. kind of Euler rotations that will correct the Y. I hope it makes some sort of sense.

If you want a horizontal line from that fit, the first problem is where do you want that horizontal line; if the fit is y = a*x + b, do you want y=b? or at what point of the original line? Or just fit a horizontal line to the data in the first place.

where do you want that horizontal line;

the point on either end would do and rotate the line accordingly. Like if there is a negative slope to the correlation and we choose left most point OR right most point of the original fit then the rotation would be counter-clockwise to make it Y_new = b.
Similarly, if the original fit has a positive slope, the rotation would be clockwise w.r.t both endpoints of the fit to make it Y_new = b. Makes sense?

@Wile_E_Coyote I already said above, I tried this.

It’s doing a bit of overcorrection; initially, I started with a negative slope after this correction now the correlation is positively sloped.

My assumption was that the “slope1” came from the original fit (in the first post). If this value is not “right”, you need to play with it.

Your assumption is right. ‘Slope1’ is from the original fit and I was trying to correct the new_Y based on Y_old - slope1/sqrt(x); Isn’t that what this suggestion of yours means?

or am I missing something here?