Hello, I have panel data for some kidney centers. now I need to do linear forecasting them. How can I not using the repetition of coding and be able to do them in 1 coding set up?
Data in panel format, 20 kidney center+6 periods.
See the code below:
KTV.raw<-read.csv(file="KTV_Reporting(1).csv")
library(stargazer)
library(fpp3)
library(ggplot2)
#Auburn kidney center
Auburn.data<-KTV.raw%>%filter(ClinicName=="Auburn Kidney Center")
ggplot(Auburn.data)+ geom_line(mapping = aes(y=Score, x= Month))+
labs(x="Month", y="Score")+
ggtitle("Auburn Kidney Center KTV Matrix")
Auburn.data1<-as_tsibble(Auburn.data, index=Month)
autoplot(Auburn.data1, Score)
#Auburn.data1|>filter(year(Month) >= 2022)
forecast_Auburn <- Auburn.data1 |>
model(TSLM(Score~trend()))
fc_Auburn <- forecast(forecast_Auburn,h=6)
fc_Auburn |>
autoplot(Auburn.data1,show_gap= FALSE) +
labs(
title = "Forecasts of KTV Matrix-Auburn Kidney Center",
y = "KTV Score")
#Bellevue Kidney center
Bellevue.data<-KTV.raw%>%filter(ClinicName=="Bellevue Kidney Center")
Bellevue.data1<-as_tsibble(Bellevue.data, index=Month)
forecast_Bellevue <- Bellevue.data1 |>
model(TSLM(Score~trend()))
fc_Bellevue <- forecast(forecast_Bellevue,h=6)
fc_Bellevue |>
autoplot(Bellevue.data1,show_gap= FALSE) +
labs(
title = "Forecasts of KTV Matrix-Bellevue Kidney Center",
y = "KTV Score")