Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created February 21, 2022 14:00
Show Gist options
  • Select an option

  • Save MJacobs1985/8d00942dd02f71ef394773561040dc35 to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/8d00942dd02f71ef394773561040dc35 to your computer and use it in GitHub Desktop.
tsdat<-day%>%
filter(location_identification==1)%>%
mutate(egg_count = zoo::na.aggregate(egg_count))%>%
dplyr::select(egg_count, date_interval)
tsdat<-xts(tsdat$egg_count, order.by=as.Date(tsdat$date_interval))
soliq_arimax = auto.arima(tsdat,
seasonal= TRUE,
stepwise=FALSE,
approximation=FALSE,
allowdrift = TRUE,
allowmean = TRUE,
parallel=TRUE,
num.cores=8)
ggfortify::ggtsdiag(soliq_arimax , gof.lag = 14)+theme_bw()
myforecasts <- forecast::forecast(soliq_arimax,
bootstrap=TRUE,
npaths=1000,
h=100)
autoplot(myforecasts) +
theme_bw()
forecasteggs<-fortify(myforecasts,
is.Date=TRUE,
ts.connect=TRUE)
ggplot(forecasteggs,aes(x=Index)) +
geom_ribbon(aes(ymin=`Lo 80`, ymax=`Hi 80`, fill="80 CI"), alpha=0.8)+
geom_ribbon(aes(ymin=`Lo 95`, ymax=`Hi 95`, fill="95 CI"), alpha=0.5)+
geom_line(aes(y=Data , color="original"),size=0.5) +
geom_line(aes(y=Fitted , color="fitted"),size=0.5, lty=2) +
geom_line(aes(y=`Point Forecast` , color="forecast"),size=1, lty=2) +
scale_color_manual(values = c('original' = 'grey',
'fitted' = 'darkblue',
'forecast' = 'purple')) +
scale_fill_manual(values = c( '80 CI' = 'red',
'95 CI' = 'orange')) +
labs(x="Date", y="Eggs", color = 'Trend fit', fill="Confidence") +
ggtitle("ARIMA forecast for Eggs") +
theme_bw()
## UPLOAD to Blob
folder<-getwd()
name="/forecast.csv"
write.csv(forecasteggs,paste0(folder,name), row.names=FALSE)
bl_endp_key <- storage_endpoint("https://xxxxxx.blob.core.windows.net",
key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
list_storage_containers(bl_endp_key)
cont <- storage_container(bl_endp_key, "xxxx")
storage_multiupload(cont, src=paste0(folder,name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment