<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: LOESS Smoothing in Excel</title>
	<atom:link href="http://peltiertech.com/WordPress/loess-smoothing-in-excel/feed/" rel="self" type="application/rss+xml" />
	<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/</link>
	<description>PTS Excel Charts and Tutorials Blog</description>
	<lastBuildDate>Sat, 21 Nov 2009 04:01:08 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Don</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-20229</link>
		<dc:creator>Don</dc:creator>
		<pubDate>Tue, 06 Oct 2009 23:01:55 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-20229</guid>
		<description>In MathCAD 14, you create a 2-column matrix of the data and set the first column = X and the second column = Y.  I named my matrix NIST.  Then enter the following:

NIST(x):=interp(loess(X,Y,.5),X,Y,x)  

where x was set as a range variable x:=0,0.1,..20

This creates a function NIST(x) that you can plot versus the range variable x

Here is the MathCAD explanation for the two built-in functions &#039;interp&#039; &amp; &#039;loess&#039;:

loess(vx, vy, span)  Returns a vector which interp uses to find a set of second-order polynomials that best fit the neighborhood of x and y data values in vx and vy in the least-squares sense. The size of the neighborhood is controlled by span. 

interp(vs, vx, vy, x)  Returns the interpolated y-value corresponding to x using the output vector vs from loess.</description>
		<content:encoded><![CDATA[<p>In MathCAD 14, you create a 2-column matrix of the data and set the first column = X and the second column = Y.  I named my matrix NIST.  Then enter the following:</p>
<p>NIST(x):=interp(loess(X,Y,.5),X,Y,x)  </p>
<p>where x was set as a range variable x:=0,0.1,..20</p>
<p>This creates a function NIST(x) that you can plot versus the range variable x</p>
<p>Here is the MathCAD explanation for the two built-in functions &#8216;interp&#8217; &amp; &#8216;loess&#8217;:</p>
<p>loess(vx, vy, span)  Returns a vector which interp uses to find a set of second-order polynomials that best fit the neighborhood of x and y data values in vx and vy in the least-squares sense. The size of the neighborhood is controlled by span. </p>
<p>interp(vs, vx, vy, x)  Returns the interpolated y-value corresponding to x using the output vector vs from loess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tian</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-19726</link>
		<dc:creator>Tian</dc:creator>
		<pubDate>Fri, 25 Sep 2009 13:40:40 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-19726</guid>
		<description>Now I understand what you mean. Thank you for clarifying.</description>
		<content:encoded><![CDATA[<p>Now I understand what you mean. Thank you for clarifying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-19677</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Thu, 24 Sep 2009 22:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-19677</guid>
		<description>Your original output is the result of LOESS calculation using a 7 point moving regression, using X and Y input as inputs and X output as the X output.

Your new output is the result of LOESS calculation using a 7 point moving regression, using X and Y input as inputs and X &lt;strong&gt;input&lt;/strong&gt; as the X output.</description>
		<content:encoded><![CDATA[<p>Your original output is the result of LOESS calculation using a 7 point moving regression, using X and Y input as inputs and X output as the X output.</p>
<p>Your new output is the result of LOESS calculation using a 7 point moving regression, using X and Y input as inputs and X <strong>input</strong> as the X output.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tian</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-19666</link>
		<dc:creator>Tian</dc:creator>
		<pubDate>Thu, 24 Sep 2009 17:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-19666</guid>
		<description>Jon,

Please see the difference of the output:

X input	Y input 		X output	original output	new output
0.55782	18.63654		0	-13.07212037	20.59304051
2.021727	103.4965		1	47.06914445	107.1603064
2.577325	150.3539		2	105.8974689	139.7673806
3.414029	190.5103		3	159.6924955	174.2630716
4.301408	208.7012		4	196.8626739	207.2333938
4.744839	213.7114		5	219.0115635	216.6616039
5.107378	228.4935		6	227.6417493	220.5444981
6.541166	233.5539		7	230.2534309	229.8606994
6.721618	234.5505		8	227.0376643	229.8347242
7.260058	223.8923		9	221.246659	229.4301269
8.133587	227.6834		10	202.9876659	226.6044626
9.122438	223.9198		11	187.8518139	220.3904231
11.92967	168.02		12	170.6711911	172.3479193
12.37977	164.9575		13	162.210816	163.8416617
13.27286	152.6111		14	160.7756941	161.8489846
14.27675	160.7874		15	159.7155843	160.3350921
15.3731	168.5557		16	161.0838629	160.1920102
15.64766	152.4266		17	194.5740586	161.0555463
18.56054	221.707		18	215.4190384	227.3399984
18.58664	222.6904		19	236.7904956	227.8985782
18.75728	243.1883</description>
		<content:encoded><![CDATA[<p>Jon,</p>
<p>Please see the difference of the output:</p>
<p>X input	Y input 		X output	original output	new output<br />
0.55782	18.63654		0	-13.07212037	20.59304051<br />
2.021727	103.4965		1	47.06914445	107.1603064<br />
2.577325	150.3539		2	105.8974689	139.7673806<br />
3.414029	190.5103		3	159.6924955	174.2630716<br />
4.301408	208.7012		4	196.8626739	207.2333938<br />
4.744839	213.7114		5	219.0115635	216.6616039<br />
5.107378	228.4935		6	227.6417493	220.5444981<br />
6.541166	233.5539		7	230.2534309	229.8606994<br />
6.721618	234.5505		8	227.0376643	229.8347242<br />
7.260058	223.8923		9	221.246659	229.4301269<br />
8.133587	227.6834		10	202.9876659	226.6044626<br />
9.122438	223.9198		11	187.8518139	220.3904231<br />
11.92967	168.02		12	170.6711911	172.3479193<br />
12.37977	164.9575		13	162.210816	163.8416617<br />
13.27286	152.6111		14	160.7756941	161.8489846<br />
14.27675	160.7874		15	159.7155843	160.3350921<br />
15.3731	168.5557		16	161.0838629	160.1920102<br />
15.64766	152.4266		17	194.5740586	161.0555463<br />
18.56054	221.707		18	215.4190384	227.3399984<br />
18.58664	222.6904		19	236.7904956	227.8985782<br />
18.75728	243.1883</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-19663</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Thu, 24 Sep 2009 16:58:41 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-19663</guid>
		<description>Tian -

The line of code works fine in VBA, which assigns the values in a range to a 1-based array. You have to adjust the syntax to use the code in C++.</description>
		<content:encoded><![CDATA[<p>Tian -</p>
<p>The line of code works fine in VBA, which assigns the values in a range to a 1-based array. You have to adjust the syntax to use the code in C++.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tian</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-19661</link>
		<dc:creator>Tian</dc:creator>
		<pubDate>Thu, 24 Sep 2009 16:38:23 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-19661</guid>
		<description>Hi Jon,

Thank you for the nice code. It helped me easily added a function to a C++ App. There is a small bug you might not notice. The assignment for xNow should be:

xNow = X(xDomain(iPoint, 1) + 1, 1)

instead of:

xNow = xDomain(iPoint, 1) 

Thank you,</description>
		<content:encoded><![CDATA[<p>Hi Jon,</p>
<p>Thank you for the nice code. It helped me easily added a function to a C++ App. There is a small bug you might not notice. The assignment for xNow should be:</p>
<p>xNow = X(xDomain(iPoint, 1) + 1, 1)</p>
<p>instead of:</p>
<p>xNow = xDomain(iPoint, 1) </p>
<p>Thank you,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-14894</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Fri, 05 Jun 2009 22:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-14894</guid>
		<description>Thanks Brian. Maybe one of the smart people who read this blog will check it out for us.</description>
		<content:encoded><![CDATA[<p>Thanks Brian. Maybe one of the smart people who read this blog will check it out for us.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-14890</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 05 Jun 2009 21:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-14890</guid>
		<description>This is something I&#039;ve been looking all over for. Thanks. I added a weighting capability, so that each case can be weighted with a third input range. I know next to nothing about VBA, but I think I did it right.

&lt;pre class=&quot;vbasmall&quot;&gt;Public Function LOESSW(X As Variant, Y As Variant, PtWt As Variant, xDomain As Variant, nPts As Long) As Double()
  Dim i As Long
  Dim iMin As Long
  Dim iMax As Long
  Dim iPoint As Long
  Dim iMx As Long
  Dim mx As Variant
  Dim maxDist As Double
  Dim SumWts As Double, SumWtX As Double, SumWtX2 As Double, SumWtY As Double, SumWtXY As Double
  Dim Denom As Double, WLRSlope As Double, WLRIntercept As Double
  Dim xNow As Double
  Dim distance() As Double
  Dim Weight() As Double
  Dim yLoess() As Double
  Dim totalWeight As Double

  If TypeName(X) = &quot;Range&quot; Then
    X = X.Value
  End If

  If TypeName(Y) = &quot;Range&quot; Then
    Y = Y.Value
  End If
  
  If TypeName(PtWt) = &quot;Range&quot; Then
    PtWt = PtWt.Value
  End If

  If TypeName(xDomain) = &quot;Range&quot; Then
    xDomain = xDomain.Value
  End If

  ReDim yLoess(LBound(xDomain, 1) To UBound(xDomain, 1), 1 To 1)

  For iPoint = LBound(xDomain, 1) To UBound(xDomain, 1)

    iMin = LBound(X, 1)
    iMax = UBound(X, 1)

    xNow = xDomain(iPoint, 1)

    ReDim distance(iMin To iMax)
    ReDim Weight(iMin To iMax)

    For i = iMin To iMax
      &#039; populate x, y, distance
      distance(i) = Abs(X(i, 1) - xNow)
    Next

    Do
      &#039; find the nPts points closest to xNow
      If iMax + 1 - iMin  distance(iMax) Then
        &#039; remove first point
        iMin = iMin + 1
      ElseIf distance(iMin)  maxDist Then maxDist = distance(i)
      totalWeight = totalWeight + PtWt(i, 1)
    Next

    &#039; calculate weights using scaled distances
    For i = iMin To iMax
      Weight(i) = (PtWt(i, 1) / totalWeight) * (1 - (distance(i) / maxDist) ^ 3) ^ 3
    Next

    &#039; do the sums of squares
    SumWts = 0
    SumWtX = 0
    SumWtX2 = 0
    SumWtY = 0
    SumWtXY = 0
    For i = iMin To iMax
      SumWts = SumWts + Weight(i)
      SumWtX = SumWtX + X(i, 1) * Weight(i)
      SumWtX2 = SumWtX2 + (X(i, 1) ^ 2) * Weight(i)
      SumWtY = SumWtY + Y(i, 1) * Weight(i)
      SumWtXY = SumWtXY + X(i, 1) * Y(i, 1) * Weight(i)
    Next
    Denom = SumWts * SumWtX2 - SumWtX ^ 2

    &#039; calculate the regression coefficients, and finally the loess value
    WLRSlope = (SumWts * SumWtXY - SumWtX * SumWtY) / Denom
    WLRIntercept = (SumWtX2 * SumWtY - SumWtX * SumWtXY) / Denom
    yLoess(iPoint, 1) = WLRSlope * xNow + WLRIntercept

  Next

  LOESSW = yLoess

End Function&lt;br /&gt;
&#160;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This is something I&#8217;ve been looking all over for. Thanks. I added a weighting capability, so that each case can be weighted with a third input range. I know next to nothing about VBA, but I think I did it right.</p>
<pre class="vbasmall">Public Function LOESSW(X As Variant, Y As Variant, PtWt As Variant, xDomain As Variant, nPts As Long) As Double()
  Dim i As Long
  Dim iMin As Long
  Dim iMax As Long
  Dim iPoint As Long
  Dim iMx As Long
  Dim mx As Variant
  Dim maxDist As Double
  Dim SumWts As Double, SumWtX As Double, SumWtX2 As Double, SumWtY As Double, SumWtXY As Double
  Dim Denom As Double, WLRSlope As Double, WLRIntercept As Double
  Dim xNow As Double
  Dim distance() As Double
  Dim Weight() As Double
  Dim yLoess() As Double
  Dim totalWeight As Double

  If TypeName(X) = "Range" Then
    X = X.Value
  End If

  If TypeName(Y) = "Range" Then
    Y = Y.Value
  End If

  If TypeName(PtWt) = "Range" Then
    PtWt = PtWt.Value
  End If

  If TypeName(xDomain) = "Range" Then
    xDomain = xDomain.Value
  End If

  ReDim yLoess(LBound(xDomain, 1) To UBound(xDomain, 1), 1 To 1)

  For iPoint = LBound(xDomain, 1) To UBound(xDomain, 1)

    iMin = LBound(X, 1)
    iMax = UBound(X, 1)

    xNow = xDomain(iPoint, 1)

    ReDim distance(iMin To iMax)
    ReDim Weight(iMin To iMax)

    For i = iMin To iMax
      ' populate x, y, distance
      distance(i) = Abs(X(i, 1) - xNow)
    Next

    Do
      ' find the nPts points closest to xNow
      If iMax + 1 - iMin  distance(iMax) Then
        ' remove first point
        iMin = iMin + 1
      ElseIf distance(iMin)  maxDist Then maxDist = distance(i)
      totalWeight = totalWeight + PtWt(i, 1)
    Next

    ' calculate weights using scaled distances
    For i = iMin To iMax
      Weight(i) = (PtWt(i, 1) / totalWeight) * (1 - (distance(i) / maxDist) ^ 3) ^ 3
    Next

    ' do the sums of squares
    SumWts = 0
    SumWtX = 0
    SumWtX2 = 0
    SumWtY = 0
    SumWtXY = 0
    For i = iMin To iMax
      SumWts = SumWts + Weight(i)
      SumWtX = SumWtX + X(i, 1) * Weight(i)
      SumWtX2 = SumWtX2 + (X(i, 1) ^ 2) * Weight(i)
      SumWtY = SumWtY + Y(i, 1) * Weight(i)
      SumWtXY = SumWtXY + X(i, 1) * Y(i, 1) * Weight(i)
    Next
    Denom = SumWts * SumWtX2 - SumWtX ^ 2

    ' calculate the regression coefficients, and finally the loess value
    WLRSlope = (SumWts * SumWtXY - SumWtX * SumWtY) / Denom
    WLRIntercept = (SumWtX2 * SumWtY - SumWtX * SumWtXY) / Denom
    yLoess(iPoint, 1) = WLRSlope * xNow + WLRIntercept

  Next

  LOESSW = yLoess

End Function
&nbsp;</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-14457</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Sun, 24 May 2009 11:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-14457</guid>
		<description>Andrew -

I used 150 for the number of points in the analysis. Here is a comparison of three curves, for 100, 150, and 200 points in the moving regression:
&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;http://peltiertech.com/images/2009-02/playmate_loess3.png&quot; alt=&quot;Playmate BMI over time&quot;&gt;&lt;/p&gt;
The website data is from my own site&#039;s history several months ago. I&#039;m not sure I still have that particular data set.</description>
		<content:encoded><![CDATA[<p>Andrew -</p>
<p>I used 150 for the number of points in the analysis. Here is a comparison of three curves, for 100, 150, and 200 points in the moving regression:</p>
<p align="center"><img src="http://peltiertech.com/images/2009-02/playmate_loess3.png" alt="Playmate BMI over time"/></p>
<p>The website data is from my own site&#8217;s history several months ago. I&#8217;m not sure I still have that particular data set.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Bond</title>
		<link>http://peltiertech.com/WordPress/loess-smoothing-in-excel/comment-page-1/#comment-14455</link>
		<dc:creator>Andrew Bond</dc:creator>
		<pubDate>Sun, 24 May 2009 10:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=1659#comment-14455</guid>
		<description>Jon

Many thanks for the link - I missed it when I first visited the Wired website. What smoothing coefficient did you use for your loess fit? And is the website data as readily available as the Playmate data?

Again, thanks in anticipation.

Andrew</description>
		<content:encoded><![CDATA[<p>Jon</p>
<p>Many thanks for the link &#8211; I missed it when I first visited the Wired website. What smoothing coefficient did you use for your loess fit? And is the website data as readily available as the Playmate data?</p>
<p>Again, thanks in anticipation.</p>
<p>Andrew</p>
]]></content:encoded>
	</item>
</channel>
</rss>
