开始使用免费开始使用

扩展均值

扩展均值(expanding mean),也称为累计均值,可用于计算时间序列在每个时间点"截至目前"的平均值。这样,您就能观察时间序列的均值如何随时间变化。

本练习中,您将计算 card_price 时间序列的扩展均值。创建扩展均值后,您会将其绘制在已有的原始时间序列图之上。该图名为 card_price_plot,是一个已为您准备好的 ggplot 对象。

请记住,扩展窗口必须使用 right 对齐。

card_pricecard_price_plot,以及 zooggplot2 包均已可用。

本练习是课程的一部分

R 中的时间序列数据处理

查看课程

练习说明

  • card_price 创建一个窗口宽度向量,并赋值给 price_windows
  • 使用 price_windowscard_price 时间序列创建扩展均值;将结果赋值给 price_exp_mean
  • 通过补全语句,为 card_price_plot 添加一个 ggplot2 折线图;使用蓝色线条表示扩展窗口。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create the vector of window widths
___

# Create the expanding window
___

# Plot the expanding window over the original time series
card_price_plot + 
  geom_line(data = ___, ___)
编辑并运行代码