I often use trend layers for calibration curves... but then I need to use the equation to determine an X value for an experimentally determined Y value in the software.
For linear regression that is a trivial calculation... but not so for all other regression types.
I can not find a function in the TrendLayer such as:
Function TrendLayer.getXvalue(Yvalue as Double) As Double
is there something like that?
A way I have been able that with other software past (with regression types it works for) is to just reverse the X and Y data valued and do the regression on that. Then i just plugged the experimental Y value into the equation spit out to the X value.
When I have dome that, of course I did not want to actually draw/display/print such a chart anywhere.
In ChartDirector is the only way to do that is to create a New chart, add a trend layer with the X and y data switched,
write a function that gets the coefficents from that and does the calculation? Seems like there should be a better way!
Re: Calculating X values from a trend layer regression
The trend layer computed parameters are accessible from the ChartDirector API. For linear regression, the parameters are the slope m and intercept c (y = mx + c). As you have mentioned, it is trivial to obtain x given y (x = (y - c) / m).
Note that it may not be mathematically possible to obtain x given y. I have attached an image from one of the ChartDirector sample code. If y = 2.5, what is x in the red curve? (There are two possible values.) If y = 3.3 (above the maximum point of the red curve), what is x? There is no x value, despite there is a data point at y = 3.3.
In a regression, the curve normally does not through every data point. So it is perfectly possible for a data point to be above the maximum point of the curve, and you cannot obtain an x value from a y value.
In regression, reverse the x and y coordinates may not rotate the curve. In some cases, it may produce a completely different curve. The curve must be single value in y (that is, given x, it is always possible to obtain y), but not the reverse (given y, it may not be possible to obtain x). We call x the "independent variable" and y the "dependent variable".
For your case, there are two approaches:
(a) In some type of regression (like the linear, exponential and logarithmic regression), it is possible to obtain x given y, in which case it is also quite easy to compute the x given y by using the regression parameters obtained from the ChartDirector API. If you need further help, please let me know which type of regression you are using.
(b) If the "y" you mentioned is actually the independent variable, but you want it to be plotted with the vertical axis, you can swap the x and y to plot the trend layer, then add the code (in C#/Java):
The above code will swap the x and y axes, so that the x-axis becomes vertical and the y-axis horizontal. In other words, you do not need to create two charts. You just need to create one chart and swap the axes for display.