<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Moving Average with Missing Data in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29460#M19442</link>
    <description>&lt;P&gt;The Mean() function neglects any missing values. The below formula stick&amp;nbsp;to the time window but do not include missing values when calculating the mean.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() &amp;lt; :Moving Avg Window,
    Mean(:data[Index(1, Row())]),
    Mean(:data[Index(Row() - (:Moving Avg Window - 1), Row())])
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Nov 2016 22:01:14 GMT</pubDate>
    <dc:creator>ms</dc:creator>
    <dc:date>2016-11-21T22:01:14Z</dc:date>
    <item>
      <title>Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29450#M19438</link>
      <description>&lt;P&gt;I'm trying to calculate a moving average of some data that has some holes in it. &amp;nbsp;I can't seem to figure out how to caculate a moving average that only includes non missing data and that only calculates the result for rows with non missing data. &amp;nbsp;Any suggestions would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Untitled 5",
	Add Rows( 30 ),
	Compress File When Saved( 1 ),
	New Table Variable( "Moving Avg Window", 5 ),
	New Column( "DateTime",
		Numeric,
		"Continuous",
		Format( "m/d/y h:m", 19 ),
		Input Format( "m/d/y h:m" ),
		Set Values(
			[3225888000, 3225888900, 3225889800, 3225890700, 3225891600, 3225892500, 3225893400, 3225894300,
			3225895200, 3225896100, 3225897000, 3225897900, 3225898800, 3225899700, 3225900600, 3225901500,
			3225902400, 3225903300, 3225904200, 3225905100, 3225906000, 3225906900, 3225907800, 3225908700,
			3225909600, 3225910500, 3225911400, 3225912300, 3225913200, 3225914100]
		)
	),
	New Column( "data",
		Numeric,
		"Continuous",
		Format( "Best", Use thousands separator( 0 ), 15 ),
		Set Values( [5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, ., ., 5, 5, 5, 5, 5, 5] )
	),
	New Column( "expected run avg",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., ., ., ., 5, ., 5, 5, 5, 5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, ., ., 5, 5, 5, 5, 5, 5] )
	),
	New Column( "run avg",
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 12, 1 ),
		Formula(
			If( Row() &amp;lt; :Moving Avg Window,
				.,
				Sum( :data[Index( Row() - (:Moving Avg Window - 1), Row() )] ) / :Moving Avg Window
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Nov 2016 21:51:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29450#M19438</guid>
      <dc:creator>terapin</dc:creator>
      <dc:date>2016-11-21T21:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29456#M19439</link>
      <description>&lt;P&gt;Here is a script that I believe will give you what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "Untitled 5",
	Add Rows( 30 ),
	Compress File When Saved( 1 ),
	New Table Variable( "Moving Avg Window", 5 ),
	New Column( "DateTime",
		Numeric,
		"Continuous",
		Format( "m/d/y h:m", 19 ),
		Input Format( "m/d/y h:m" ),
		Set Values(
			[3225888000, 3225888900, 3225889800, 3225890700, 3225891600, 3225892500, 3225893400,
			3225894300, 3225895200, 3225896100, 3225897000, 3225897900, 3225898800, 3225899700,
			3225900600, 3225901500, 3225902400, 3225903300, 3225904200, 3225905100, 3225906000,
			3225906900, 3225907800, 3225908700, 3225909600, 3225910500, 3225911400, 3225912300,
			3225913200, 3225914100]
		)
	),
	New Column( "data",
		Numeric,
		"Continuous",
		Format( "Best", Use thousands separator( 0 ), 15 ),
		Set Values(
			[5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, ., ., 5, 5, 5, 5,
			5, 5]
		)
	),
	New Column( "expected run avg",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[., ., ., ., 5, ., 5, 5, 5, 5, 5, 5, 5, 5, ., 5, 5, 5, 5, 5, 5, 5, ., ., 5, 5, 5, 5,
			5, 5]
		)
	),
	New Column( "run avg",
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 12, 1 ),
		Formula(
			If( Row() == 1,
				NonMissingRows = dt &amp;lt;&amp;lt; get rows where( Is Missing( :data ) == 0 )
			);
			If( Loc( As List( NonMissingRows ), Row() ) &amp;lt; :Moving Avg Window,
				.,
				TargetPosition = Loc( As List( NonMissingRows ), Row() );
				MatrixofMAW = NonMissingRows[Index(
					TargetPosition - (Moving Avg Window - 1),
					TargetPosition
				)];
				Show( Row(), MatrixofMAW );
				Sum( :data[MatrixofMAW] ) / :Moving Avg Window;
			);
		)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Nov 2016 21:44:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29456#M19439</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2016-11-21T21:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29459#M19441</link>
      <description>&lt;P&gt;If you can't create a subset excluding the null values I think the formula below works--though I'm sure there is a better way. This&amp;nbsp;gives a null value for rows without data but you can have it repeat the average by getting rid of the if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If(Is Missing(:data), ., rsum = 0; rcount = 0; temprow = 0; (While(rcount &amp;lt; :Moving Avg Window, While(Is Missing(:data[Row() - temprow]) &amp;amp; Row() - temprow &amp;gt;= 1, temprow += 1); rsum += :data[Row() - temprow]; temprow += 1; rcount += 1); rsum / :Moving Avg Window))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 21:50:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29459#M19441</guid>
      <dc:creator>mpl34</dc:creator>
      <dc:date>2016-11-21T21:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29460#M19442</link>
      <description>&lt;P&gt;The Mean() function neglects any missing values. The below formula stick&amp;nbsp;to the time window but do not include missing values when calculating the mean.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If(Row() &amp;lt; :Moving Avg Window,
    Mean(:data[Index(1, Row())]),
    Mean(:data[Index(Row() - (:Moving Avg Window - 1), Row())])
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 22:01:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29460#M19442</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2016-11-21T22:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29461#M19443</link>
      <description>&lt;P&gt;In the below link we talked about this and put a couple of faster algorithms for it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Efficient-moving-average-algorithm/td-p/8553" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Efficient-moving-average-algorithm/td-p/8553&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 22:26:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/29461#M19443</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2016-11-21T22:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/30806#M19543</link>
      <description>&lt;P&gt;Thanks everyone for weighing in on this question. &amp;nbsp;MS' suggestion is certainly the cleanest and easiest for me to implement since it let's me define and specify backward and forward moving window size. &amp;nbsp;I certainly learned a lot from all the examples provided. &amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 18:59:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/30806#M19543</guid>
      <dc:creator>terapin</dc:creator>
      <dc:date>2016-11-28T18:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Average with Missing Data</title>
      <link>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/31087#M19678</link>
      <description>&lt;P&gt;I didn't look at this case in detail. But I just wanted to also mention:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Col Moving Average(name, options, &amp;lt;By var, ...&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which seems to have a lot of flexibility.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 10:41:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Moving-Average-with-Missing-Data/m-p/31087#M19678</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2016-12-02T10:41:28Z</dc:date>
    </item>
  </channel>
</rss>

