R machine learning application that performs forecasting on pharmaceutical medicine sales data using information obtained form NHS (UK) General Practitioner (GP) datasets.
This Shiny dashboard application provides time series forecasting capabilities for NHS prescription data. It allows users to analyze and forecast prescription quantities and sales revenue using various forecasting models.
- Interactive product selection
- Multiple forecasting models:
- Auto (ETS)
- Holt-Winters
- TBATS
- Auto ARIMA
- Markov Chain Monte-Carlo (Prophet)
- Metrics analysis:
- Visualization components:
- Top 5 related products comparison
- Time series decomposition
- Forecast plots with confidence intervals
- Detailed data tables for both historical and forecast data
The following R packages are required:
required_packages <- c(
"devtools",
"shinyWidgets",
"data.table",
"DT",
"forecast",
"ggplot2",
"shinyjs",
"plotly",
"xts",
"prophet",
"tidyverse",
"shinydashboard"
)
- Clone the repository:
git clone https://github.com/Sabareh/Forecasting-ML-App
cd Forecasting-ML-App
- Install required packages:
for(pkg in required_packages){
if(!require(pkg, character.only = TRUE)){
install.packages(pkg)
}
}
- Ensure you have the data file:
productdb.rds
should be in the root directory
- Start the application:
shiny::runApp()
- Using the dashboard:
- Select a product from the dropdown menu
- Choose a forecasting model
- Select the metric (Sales Revenue or Quantity)
- Toggle the ETS decomposition if needed
- View the results in the various plots and tables
The application expects a productdb.rds file with the following columns:
- BNFNAME: Product name
- CHEMSUB: Chemical substance
- QUANTITY: Prescription quantity
- ACTCOST: Actual cost
- month: Date in YYYY-MM format
- Dropdown menu with autocomplete functionality
- Shows all available products in the NHS database
-
Auto (ETS)
- Automatic exponential smoothing
- Best for general forecasting
-
Holt-Winters
- Triple exponential smoothing
- Handles trend and seasonality
-
TBATS
- Handles complex seasonality
- Good for multiple seasonal patterns
-
Auto ARIMA
- Automatic ARIMA model selection
- Best for stationary time series
-
MCMC (Prophet)
- Facebook's Prophet algorithm
- Handles missing data and outliers
-
Top 5 Plot
- Shows related products
- Interactive plotly visualization
-
Forecast Plot
- Shows predictions with confidence intervals
- Highlights trends and patterns
-
Time Series Plot
- Historical data visualization
- Optional ETS decomposition
-
Forecast Data
- Shows predicted values
- Includes confidence intervals
- Currency formatting for revenue
-
Historical Data
- Shows raw data
- Sortable and searchable
- Custom CSS in
www/packt.css
- Uses Google Fonts:
- Fanwood Text
- Varela
- Validates input data
- Handles missing data gracefully
- Provides user feedback for errors
- Uses reactive programming
- Efficient data.table operations
- Optimized plotting with plotly
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- NHS Digital for the prescription data
- R Shiny community
- Contributors to the various R packages used
For support, please open an issue in the repository or contact [maintainer email].
- 1.0.0: Initial release
- Basic forecasting functionality
- Five forecasting models
- Interactive visualizations