简体   繁体   中英

Time Series Forecast using Arima in R

I'm looking for a helper to help with my R programming assignment,

I try to forecast student behaviour by year. But I can't make it, maybe because my data is too small. However, I still need to proceed with this assignment. Can anyone help me to forecast? I'm using Arima however the trend line keeps showing a straight line which I'm not sure is the right answer for it. Might be this because ARIMA shows ARIMA(0,0,0) with non-zero mean.

Image Data Year - General Students - Numeric

Please help me with this. Thank you in advance.

To forecast a student's behaviour by year

Small data set, but this is one way to go about it. Modelling each student separately (with student as a key), and using the tidyverts approach:

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

Data set

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")

Tidy data

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

Visualise

df |> autoplot()

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

Fit ARIMA

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

Check fit

glance(Stu_fit)
Stu_fit$search

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

Forecast

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

Hope this is helps: :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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