Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
MI MI is offline
external usenet poster
 
Posts: 2
Default deming excel function

I have Excel 2003. I have tried running the below function i found on
the internet as an addin, but it returns an error of #value. I have
20-30 each of x and y values in columns.
Is there anything that appears wrong, or do i need to run another
function prior to running this one. I am a novice.

Function Deming(XValues, Yvalues)
Dim MeanX(), MeanY()
'Get number of cells to use in calculation loop
Ncells = XValues.Count
ReDim MeanX(Ncells / 2), MeanY(Ncells / 2)

'Step thru pairs of cells, calculating sums for statistics calcs
For x = 2 To Ncells Step 2
MeanX(x / 2) = (XValues(x - 1) + XValues(x)) / 2
MeanY(x / 2) = (Yvalues(x - 1) + Yvalues(x)) / 2
SumX = SumX + MeanX(x / 2): SumY = SumY + MeanY(x / 2)
SumX2 = SumX2 + (MeanX(x / 2)) ^ 2
SumY2 = SumY2 + (MeanY(x / 2)) ^ 2
SumXY = SumXY + MeanX(x / 2) * MeanY(x2 / 2)
SumDeltaX2 = SumDeltaX2 + (XValues(x - 1) - XValues(x)) ^ 2
SumDeltaY2 = SumDeltaY2 + (Yvalues(x - 1) - Yvalues(x)) ^ 2
Next

'Calculate some intermediate statistical quantities
XBar = SumX / N: YBar = SumY / N
Sx2 = (N * SumX2 - SumX ^ 2) / (N * (N - 1))
Sy2 = (N * SumY2 - SumY ^ 2) / (N * (N - 1))
Sdx2 = SumDeltaX2 / (2 * N)
Sdy2 = SumDeltaY2 / (2 * N)
rPearson = (N * SumXY - SumX * SumY) / _
Sqr((N * SumX2 - SumX ^ 2) * (N * SumY2 - SumY ^ 2))

'Calculate quantitites that are specific to the Deming calculation
lambda = Sdx / Sdy2
U = (Sy2 - Sx2 / lambda) / (2 * rPearson * Sqr(Sx2) * Sqr(Sy2))
Slope = U + Sqr(U ^ 2 + 1 / lambda)
Intercept = YBar - Slope * XBar

Deming = Array(Slope, Intercept)



End Function
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default deming excel function

I will not vouch for the math, but the code was incorrent because N was never used and you were
dividing by zero - perhaps N should have been NCells? (and lambda was always zero since it divided
an non -used variable (0) by another term. That is why you should always use option explicit to
force dimensioning of your variables - to catch typos, etc..

Anyway, try the version below to see if it returns the expected values for your data. You need to
array enter the formula (using Ctrl-Shift Enter) because the function returns an array. Select tow
cells side-by-side, type in =Deming(range1, range2), and press Ctrl-Shift-Enter.

HTH,
Bernie
MS Excel MVP


Function Deming(XValues, Yvalues)
Dim MeanX(), MeanY()
'Get number of cells to use in calculation loop
NCells = XValues.Count
ReDim MeanX(NCells / 2), MeanY(NCells / 2)

'Step thru pairs of cells, calculating sums for statistics calcs
For x = 2 To NCells Step 2
MeanX(x / 2) = (XValues(x - 1) + XValues(x)) / 2
MeanY(x / 2) = (Yvalues(x - 1) + Yvalues(x)) / 2
SumX = SumX + MeanX(x / 2): SumY = SumY + MeanY(x / 2)
SumX2 = SumX2 + (MeanX(x / 2)) ^ 2
SumY2 = SumY2 + (MeanY(x / 2)) ^ 2
SumXY = SumXY + MeanX(x / 2) * MeanY(x2 / 2)
SumDeltaX2 = SumDeltaX2 + (XValues(x - 1) - XValues(x)) ^ 2
SumDeltaY2 = SumDeltaY2 + (Yvalues(x - 1) - Yvalues(x)) ^ 2
Next

'Calculate some intermediate statistical quantities
XBar = SumX / NCells: YBar = SumY / NCells
Sx2 = (NCells * SumX2 - SumX ^ 2) / (NCells * (NCells - 1))
Sy2 = (NCells * SumY2 - SumY ^ 2) / (NCells * (NCells - 1))
Sdx2 = SumDeltaX2 / (2 * NCells)
Sdy2 = SumDeltaY2 / (2 * NCells)
rPearson = (NCells * SumXY - SumX * SumY) / _
Sqr((NCells * SumX2 - SumX ^ 2) * (NCells * SumY2 - SumY ^ 2))

'Calculate quantitites that are specific to the Deming calculation
lambda = Sdx2 / Sdy2
U = (Sy2 - Sx2 / lambda) / (2 * rPearson * Sqr(Sx2) * Sqr(Sy2))
Slope = U + Sqr(U ^ 2 + 1 / lambda)
Intercept = YBar - Slope * XBar

Deming = Array(Slope, Intercept)



End Function


"MI" wrote in message
...
I have Excel 2003. I have tried running the below function i found on
the internet as an addin, but it returns an error of #value. I have
20-30 each of x and y values in columns.
Is there anything that appears wrong, or do i need to run another
function prior to running this one. I am a novice.

Function Deming(XValues, Yvalues)
Dim MeanX(), MeanY()
'Get number of cells to use in calculation loop
Ncells = XValues.Count
ReDim MeanX(Ncells / 2), MeanY(Ncells / 2)

'Step thru pairs of cells, calculating sums for statistics calcs
For x = 2 To Ncells Step 2
MeanX(x / 2) = (XValues(x - 1) + XValues(x)) / 2
MeanY(x / 2) = (Yvalues(x - 1) + Yvalues(x)) / 2
SumX = SumX + MeanX(x / 2): SumY = SumY + MeanY(x / 2)
SumX2 = SumX2 + (MeanX(x / 2)) ^ 2
SumY2 = SumY2 + (MeanY(x / 2)) ^ 2
SumXY = SumXY + MeanX(x / 2) * MeanY(x2 / 2)
SumDeltaX2 = SumDeltaX2 + (XValues(x - 1) - XValues(x)) ^ 2
SumDeltaY2 = SumDeltaY2 + (Yvalues(x - 1) - Yvalues(x)) ^ 2
Next

'Calculate some intermediate statistical quantities
XBar = SumX / N: YBar = SumY / N
Sx2 = (N * SumX2 - SumX ^ 2) / (N * (N - 1))
Sy2 = (N * SumY2 - SumY ^ 2) / (N * (N - 1))
Sdx2 = SumDeltaX2 / (2 * N)
Sdy2 = SumDeltaY2 / (2 * N)
rPearson = (N * SumXY - SumX * SumY) / _
Sqr((N * SumX2 - SumX ^ 2) * (N * SumY2 - SumY ^ 2))

'Calculate quantitites that are specific to the Deming calculation
lambda = Sdx / Sdy2
U = (Sy2 - Sx2 / lambda) / (2 * rPearson * Sqr(Sx2) * Sqr(Sy2))
Slope = U + Sqr(U ^ 2 + 1 / lambda)
Intercept = YBar - Slope * XBar

Deming = Array(Slope, Intercept)



End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deming Regression for labs MI Charts and Charting in Excel 3 October 6th 09 02:56 AM
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
Help to build a Look Up Function or What Ever Function Excel 2002 Carlo Excel Worksheet Functions 6 April 3rd 08 07:39 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
challenge! javascript function into excel function Kamila Excel Worksheet Functions 2 February 19th 07 06:35 AM


All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"