繁体   English   中英

在 R 中使用 Arima 进行时间序列预测

[英]Time Series Forecast using Arima in R

我正在寻找帮手来帮助我完成 R 编程作业,

我尝试按年预测学生的行为。 但是我做不到,可能是因为我的数据太少了。 但是,我仍然需要继续完成这项任务。 谁能帮我预测一下? 我正在使用 Arima,但趋势线一直显示一条直线,我不确定这是正确的答案。 可能是因为 ARIMA 显示 ARIMA(0,0,0) 具有非零均值。

图像数据年份-普通学生-数值

请帮我解决一下这个。 先感谢您。

按年份预测学生的行为

小数据集,但这是一种方式 go 一下吧。 分别为每个学生建模(以学生为键),并使用 tidyverts 方法:

library(lubridate)
library(dplyr)
library(tidyr)
library(tsibble)
library(feasts)
library(fable)

数据集

df <- structure(list(Year = structure(c(1995, 1996, 1997), class = "numeric"), 
                     Student1 = c(3, 1, 3), Student2 = c(2, 2, 2), Student3 = c(2, 
                                                                                3, 3), Student4 = c(2, 3, 2), Student5 = c(3, 3, 4)), row.names = c(NA, 
                                                                                                                                                3L), class = "data. Frame")

整理数据

df <- df |> pivot_longer(names_to = "Student", cols = starts_with("Student")) |>
  as_tsibble(index = Year, key = Student)

可视化

df |> autoplot()

df |>
  filter(Student == "Student1") |>
  gg_tsdisplay(value, plot_type = 'partial')

适合 ARIMA

Stu_fit <- df |>
  model(search = ARIMA(value, stepwise = FALSE))

检查适合度

glance(Stu_fit)
Stu_fit$search

Stu_fit |>
  filter(Student == "Student1") |>
  gg_tsresiduals()

预报

Stu_fit |>
  forecast(h = 5) |>
  filter(.model == 'search') |>
  autoplot()

希望这会有所帮助::-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM