Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tools for time series analysis and forecasting

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

RamiKrispin/TSstudio

Repository files navigation

CRAN_Status_BadgeTotal DownloadsDownloadsLifecycle:RetiredLicense: MIT

TheTSstudio package provides a set of tools descriptive and predictive analysis of time series data. That includes utility functions for preprocessing time series data, interactive visualization functions based on theplotly package engine, and set of tools for training and evaluating time series forecasting models from theforecast,forecastHybrid, andbsts packages.

More information available on the packagevignettes.

Installation

Install the stable version fromCRAN:

install.packages("TSstudio")

or install the development version fromGithub:

# install.packages("devtools")devtools::install_github("RamiKrispin/TSstudio")

Usage

Plotting time series data

library(TSstudio)data(USgas)# Ploting time series objectts_plot(USgas,title="US Monthly Natural Gas Consumption",Ytitle="Billion Cubic Feet")

Seasonality analysis

# Seasonal plotts_seasonal(USgas,type="all")

# Heatmap plotts_heatmap(USgas)

Correlation analysis

# ACF and PACF plotsts_cor(USgas,lag.max=60)

# Lags plotts_lags(USgas,lags=1:12)

# Seasonal lags plotts_lags(USgas,lags= c(12,24,36,48))

Training forecasting models

# Forecasting applications# Setting training and testing partitionsUSgas_s<- ts_split(ts.obj=USgas,sample.out=12)train<-USgas_s$traintest<-USgas_s$test# Forecasting with auto.arimalibrary(forecast)md<- auto.arima(train)fc<- forecast(md,h=12)# Plotting actual vs. fitted and forecastedtest_forecast(actual=USgas,forecast.obj=fc,test=test)

# Plotting the forecastplot_forecast(fc)

# Run horse race between multiple modelsmethods<-list(ets1=list(method="ets",method_arg=list(opt.crit="lik"),notes="ETS model with opt.crit = lik"),ets2=list(method="ets",method_arg=list(opt.crit="amse"),notes="ETS model with opt.crit = amse"),arima1=list(method="arima",method_arg=list(order= c(2,1,0)),notes="ARIMA(2,1,0)"),arima2=list(method="arima",method_arg=list(order= c(2,1,2),seasonal=list(order= c(1,1,1))),notes="SARIMA(2,1,2)(1,1,1)"),hw=list(method="HoltWinters",method_arg=NULL,notes="HoltWinters Model"),tslm=list(method="tslm",method_arg=list(formula=input~trend+season),notes="tslm model with trend and seasonal components"))# Training the models with backtestingmd<- train_model(input=USgas,methods=methods,train_method=list(partitions=6,sample.out=12,space=3),horizon=12,error="MAPE")# A tibble: 6 x 7model_idmodelnotesavg_mapeavg_rmse`avg_coverage_80%``avg_coverage_95%`<chr><chr><chr><dbl><dbl><dbl><dbl>1arima2arima       SARIMA(2,1,2)(1,1,1)0.0557167.0.5830.8062hwHoltWintersHoltWintersModel0.0563163.0.7360.8893ets1etsETSmodelwithopt.crit=lik0.0611172.0.6810.9034ets2etsETSmodelwithopt.crit=amse0.0666186.0.4580.8335tslmtslmtslmmodelwithtrendandseasonalcomponents0.0767220.0.4170.6676arima1arima       ARIMA(2,1,0)0.188598.0.8750.958
# Plot the performance of the different models on the testing partitionsplot_model(md)

# Holt-Winters tunning parameters with grid searchhw_grid<- ts_grid(USgas,model="HoltWinters",periods=6,window_space=6,window_test=12,hyper_params=list(alpha= seq(0,1,0.1),beta= seq(0,1,0.1),gamma= seq(0,1,0.1)))                                       plot_grid(hw_grid,type="3D")


[8]ページ先頭

©2009-2025 Movatter.jp