缺失数据的移动平均线我正在尝试计算一些存在漏洞的数据的移动平均值。 我似乎无法弄清楚如何计算仅包含非缺失数据的移动平均值,并且仅计算包含非缺失数据的行的结果。 任何建议,将不胜感激。
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() < :Moving Avg Window,
.,
Sum( :data[Index( Row() - (:Moving Avg Window - 1), Row() )] ) / :Moving Avg Window
)
)
)
);回复:缺失数据的移动平均线我没有仔细看这个案例。 但我还想提一下:
Col 移动平均线(名称,选项,<按变量,...>)
这似乎有很大的灵活性。
回复:缺失数据的移动平均线感谢大家对这个问题的参与。 MS 的建议对我来说无疑是最干净、最容易实现的,因为它让我定义和指定向后和向前移动的窗口大小。 我当然从提供的所有示例中学到了很多东西。 谢谢!
回复:缺失数据的移动平均线在下面的链接中,我们讨论了这一点,并为其添加了一些更快的算法。
https://community.jmp.com/t5/Discussions/Efficient-moving-average-algorithm/td-p/8553
回复:缺失数据的移动平均线Mean() 函数忽略任何缺失值。 下面的公式坚持时间窗口,但在计算平均值时不包括缺失值。
If(Row() < :Moving Avg Window,
Mean(:data[Index(1, Row())]),
Mean(:data[Index(Row() - (:Moving Avg Window - 1), Row())])
);
回复:缺失数据的移动平均线如果您无法创建排除空值的子集,我认为下面的公式有效 - 尽管我确信有更好的方法。 这会为没有数据的行提供空值,但您可以通过删除 if 语句来让它重复平均值。
If(Is Missing(:data), ., rsum = 0; rcount = 0; temprow = 0; (While(rcount < :移动平均窗口, While(Is Missing(:data[Row() - temprow]) & Row) () - temprow >= 1, temprow += 1); rsum += :data[Row() - temprow]; temprow += 1; rcount += 1); rsum / :移动平均窗口))
回复:缺失数据的移动平均线这是一个我相信会给你你想要的脚本
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 << get rows where( Is Missing( :data ) == 0 )
);
If( Loc( As List( NonMissingRows ), Row() ) < :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;
);
)
)
);