Support Forums
Linear regression?

Can anyone tell me how to do a linear regression (Y=mX+b) for two channels on a DT85? !

Can anyone tell me how to do a linear regression (Y=mX+b) for two channels on a DT85? !

Good morning smason,

I think you are talking about scaling you input with a spans or polynomials.
The DT80 supports up to 50 spans or polynomials.
With spans you specify the starts and end points in the form
Sn=Lower physical,Upper Physical,lower Signal,Upper signal"Units"

E.g This will span a 4 to 20 mA current loop pressure transducer of 100 bar full scale.

BEGIN
S1=0,100,4,20"Bar"
RA1S
1#I(S1)
END

You could do the same thing with a polynomial. The first two terms is your linear regression with the terms the other way around. The standard form of a polynomial used is Y=a+bx+cx^2+dx^3+ex^4+fx^5. DT80 measures the X so we need to supply the other terms.

For the example above this becomes:

BEGIN
Y2=-25,6.25"Bar"
RA1S
1#I(Y1)
END

For more details please refer to page 56 of the DT80 manual. (Note: page number form the manual release this week Verion number A6)

Cheers,
Roger

Good morning smason, I think you are talking about scaling you input with a spans or polynomials. The DT80 supports up to 50 spans or polynomials. With spans you specify the starts and end points in the form Sn=Lower physical,Upper Physical,lower Signal,Upper signal"Units" E.g This will span a 4 to 20 mA current loop pressure transducer of 100 bar full scale. ```` BEGIN S1=0,100,4,20"Bar" RA1S 1#I(S1) END ```` You could do the same thing with a polynomial. The first two terms is your linear regression with the terms the other way around. The standard form of a polynomial used is Y=a+bx+cx^2+dx^3+ex^4+fx^5. DT80 measures the X so we need to supply the other terms. For the example above this becomes: ```` BEGIN Y2=-25,6.25"Bar" RA1S 1#I(Y1) END ```` For more details please refer to page 56 of the DT80 manual. (Note: page number form the manual release this week Verion number A6) Cheers, Roger

Hi Roger,

What I actually want to do is calculate the m and b values from the formula Y=mX+b where Y and X are both measured channels on the logger.

i.e. Every day, take the last days data for two channels X and Y and calculate the slope, m, and axis intercept, b.

I hope that explanation is a little clearer than the first one.

Thanks,
Simon

Hi Roger, What I actually want to do is calculate the m and b values from the formula Y=mX+b where Y and X are both measured channels on the logger. i.e. Every day, take the last days data for two channels X and Y and calculate the slope, m, and axis intercept, b. I hope that explanation is a little clearer than the first one. Thanks, Simon

Good morning Simon,

Ok, that's a little bit harder but still not impossible.

Point 1: Understand the math.
This is a good link that describes the maths required: http://phoenix.phys.clemson.edu/tutorials/regression/index.html

Point 2:
The main point to remember is the dataTaker can not access historical data so you need to break it down into bits that can be calculated on the fly then calculate the final numbers when required and reset the accumulated values.

You can see from the maths we need to calculate the m value first because we need to slope to calculate the intercept.

To calculate m we need:

  • The number of samples N.
  • Sum of the X values.
  • Sum of the Y values.
  • Sum of X*Y
  • Sum of (X^2)
  • And (Sum X)^2

NOTE: The last two are not the same. Sum of (X^2) means take the value of X and square it. Then add it to the previous values. (Sum X)^2 means take the value of X and add it to the previous vales then, right at the end, square the lot.

To calculate the intercept (B) we need:

  • The number of samples N.
  • Sum of the X values.
  • Sum of the Y values.
  • And the M value.

So in dataTaker speak this becomes:

RA1S
1V("X",=1CV) 
2V("Y",=2CV) 
3CV("n")=3CV+1 'Used in M and B
4CV("Sum X")=4CV+1CV 'Used in M and B
5CV("Sum Y")=5CV+2CV 'Used in M and B
6CV("Sum X*Y")=6CV+(1CV*2CV) 'Used in M
7CV("Sum(X^2)")=7CV+1CV^2 'Used in M

RB1M
8CV("M")=(6CV-(4CV*5CV))/((3CV*4CV)-4CV^2)
9CV("B")=(5CV-(8CV*4CV))/3CV

END

Cheers,
Roger

Good morning Simon, Ok, that's a little bit harder but still not impossible. Point 1: Understand the math. This is a good link that describes the maths required: http://phoenix.phys.clemson.edu/tutorials/regression/index.html Point 2: The main point to remember is the dataTaker can not access historical data so you need to break it down into bits that can be calculated on the fly then calculate the final numbers when required and reset the accumulated values. You can see from the maths we need to calculate the m value first because we need to slope to calculate the intercept. To calculate m we need: - The number of samples N. - Sum of the X values. - Sum of the Y values. - Sum of X*Y - Sum of (X^2) - And (Sum X)^2 NOTE: The last two are not the same. Sum of (X^2) means take the value of X and square it. Then add it to the previous values. (Sum X)^2 means take the value of X and add it to the previous vales then, right at the end, square the lot. To calculate the intercept (B) we need: - The number of samples N. - Sum of the X values. - Sum of the Y values. - And the M value. So in dataTaker speak this becomes: ```` RA1S 1V("X",=1CV) 2V("Y",=2CV) 3CV("n")=3CV+1 'Used in M and B 4CV("Sum X")=4CV+1CV 'Used in M and B 5CV("Sum Y")=5CV+2CV 'Used in M and B 6CV("Sum X*Y")=6CV+(1CV*2CV) 'Used in M 7CV("Sum(X^2)")=7CV+1CV^2 'Used in M RB1M 8CV("M")=(6CV-(4CV*5CV))/((3CV*4CV)-4CV^2) 9CV("B")=(5CV-(8CV*4CV))/3CV END ```` Cheers, Roger
20
3
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft