├── .Rprofile ├── .github └── workflows │ └── dockerimage.yml ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── R ├── basel_weather_intro.R ├── causal_arima │ ├── intro_causal_arima_jo.Rmd │ └── intro_causal_arima_jo.html ├── gam_comparison_forecast.Rmd ├── gam_comparison_forecast.html ├── intro_forecasting │ ├── basel_stl_forecasting.rmd │ ├── intro_arima.rmd │ └── intro_exponential_smoothing.Rmd └── synthetic_control │ ├── rep_for_btsa.R │ └── rep_original.r ├── README.md ├── code_of_conduct.md ├── data ├── basel_weather.csv ├── basel_weather_daily.csv ├── beer.csv ├── intro_ets.csv ├── repgermany.dta ├── sample_data_1.csv ├── sample_data_1_complete.csv └── wave2vec_audio_samples │ ├── Pulp_fiction_clip.wav │ └── Taken_clip.wav ├── environment.yml ├── images └── sample_data_1_plot.png ├── meetup.md ├── presentations ├── 2020-06-02_btsa_kickoff_meetup_slides.pdf ├── Menchetti_Palmieri_CausalArima.pdf ├── eda_time_series │ ├── EDA for Time Series Data.pdf │ ├── eda_part_1_viz_and_missing_values.html │ ├── eda_part_2_correlations.html │ └── eda_part_3_decomposition.html ├── forecast_kaggle_tips │ └── Forecast practitioners What can we learn from Kaggle competitions.pdf ├── hierarchical_bvar │ ├── Tenuous Relations and Timeseries Analysis.pdf │ └── hierarchical_bvar.html ├── synthetic_control │ └── BTSA_synthetic_control.pdf ├── temporal_point_processes │ └── tpp_presentation.pdf └── wave2vec │ └── Wav2vec.pdf ├── python ├── CausalImpact │ ├── data │ │ ├── S&P500.csv │ │ ├── bitcoin_historical_price.csv │ │ └── vw.csv │ └── notebooks │ │ └── causal_impact_bitcoin.ipynb ├── deepAR │ ├── DeepAR GlueonTS PyTorchTS comparison.ipynb │ └── deepAR_gluonts_example.ipynb ├── fundamentals │ ├── images │ │ ├── basel_daily_cyclic.png │ │ ├── basel_daily_decomp0.png │ │ ├── basel_daily_decomp1.png │ │ ├── basel_daily_decomp_fourier.png │ │ ├── basel_daily_gf.png │ │ ├── basel_daily_gf_yearly.png │ │ ├── basel_daily_ma.png │ │ ├── basel_daily_p_acf_plots.png │ │ ├── basel_daily_ts.png │ │ ├── basel_daily_yearly.png │ │ ├── basel_hourly_ts.png │ │ ├── beer_ma.png │ │ ├── beer_production.png │ │ ├── beer_seasonal_decomposed.png │ │ └── day_of_year_fourier.png │ └── notebooks │ │ ├── basel_weather_intro.ipynb │ │ ├── eda_part_1_viz_and_missing_values.ipynb │ │ ├── eda_part_2_correlations.ipynb │ │ └── eda_part_3_decomposition.ipynb ├── intro_forecasting │ ├── basel_stl_forecasting.ipynb │ ├── images │ │ ├── statsmodels_docs_images │ │ │ ├── ssm_ar.png │ │ │ ├── ssm_es.png │ │ │ ├── ssm_structure.png │ │ │ ├── uc_intro.png │ │ │ ├── uc_other.png │ │ │ ├── uc_seasonal.png │ │ │ ├── uc_structure.png │ │ │ └── uc_types.png │ │ └── unobserved_components_predictions.png │ ├── intro_arima.ipynb │ ├── intro_exponential_smoothing.ipynb │ ├── mapping.py │ └── unobserved_components.ipynb ├── prophet │ ├── fbprophet_110820_solution_evamartinez.ipynb │ ├── generate_time_series.py │ ├── prophet_test.html │ ├── prophet_test.ipynb │ └── prophet_test.py ├── rocket_minirocket │ ├── data │ │ ├── ACSF1_TEST.txt │ │ └── ACSF1_TRAIN.txt │ ├── demo_default.ipynb │ ├── demo_sktime.ipynb │ ├── presentation_berlin.ipynb │ └── presentation_berlin_slides.pdf ├── sktime │ └── basel_forecastnig.ipynb └── wave2vec │ └── wav2vec_demo.ipynb ├── renv.lock ├── renv ├── .gitignore ├── activate.R └── settings.dcf └── resources.md /.Rprofile: -------------------------------------------------------------------------------- 1 | source("renv/activate.R") 2 | -------------------------------------------------------------------------------- /.github/workflows/dockerimage.yml: -------------------------------------------------------------------------------- 1 | name: Docker Build 2 | 3 | on: [push] 4 | 5 | jobs: 6 | 7 | build: 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Build Docker image 14 | run: docker build -t docker-btsa . -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Mac file 10 | .DS_Store 11 | 12 | # Distribution / packaging 13 | .Python 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | pip-wheel-metadata/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | 57 | # Translations 58 | *.mo 59 | *.pot 60 | 61 | # Django stuff: 62 | *.log 63 | local_settings.py 64 | db.sqlite3 65 | db.sqlite3-journal 66 | 67 | # Flask stuff: 68 | instance/ 69 | .webassets-cache 70 | 71 | # Scrapy stuff: 72 | .scrapy 73 | 74 | # Sphinx documentation 75 | docs/_build/ 76 | 77 | # PyBuilder 78 | target/ 79 | 80 | # Jupyter Notebook 81 | .ipynb_checkpoints 82 | 83 | # IPython 84 | profile_default/ 85 | ipython_config.py 86 | 87 | # pyenv 88 | .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | #DS_Store 135 | .DS_Store 136 | *.DS_Store 137 | 138 | #vscode 139 | .vscode 140 | 141 | # RStudio 142 | .Rproj.user 143 | .RData 144 | .Rhistory 145 | .Rapp.history 146 | .Renviron 147 | *.nb.html -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We highly encourage to contribute to this repository! 4 | 5 | - If you find and error or have a specific request you can create an [Issue](https://guides.github.com/features/issues/). 6 | - Add an analysis/experiment using a [Pull Request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests). Please add your code into the corresponding folder `R/experiments` or `python/experiments`. 7 | - If you want to add your code regarding a specific meet-up, please included in a folder with the corresponding date `-`. For example, if you want to add a python notebook `my_notebook.ipynb` (you can add your name, or any tag representing you into the file name) for the meetup of August 11th 2020 then just include it in `python/2020-08/my_notebook.ipynb`. Then create a [Pull Request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests). -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Choose your desired base image 2 | FROM jupyter/minimal-notebook:latest 3 | 4 | USER root 5 | 6 | # name your environment and choose python 3.x version 7 | ARG conda_env=btsa 8 | 9 | # use a YAML file present in the docker build context 10 | COPY environment.yml /home/$NB_USER/tmp/ 11 | RUN cd /home/$NB_USER/tmp/ && \ 12 | conda env create -p $CONDA_DIR/envs/$conda_env -f environment.yml && \ 13 | conda clean --all -f -y 14 | 15 | # create Python 3.x environment and link it to jupyter 16 | RUN $CONDA_DIR/envs/${conda_env}/bin/python -m ipykernel install --user --name=${conda_env} && \ 17 | fix-permissions $CONDA_DIR && \ 18 | fix-permissions /home/$NB_USER 19 | # prepend conda environment to path 20 | ENV PATH $CONDA_DIR/envs/${conda_env}/bin:$PATH 21 | 22 | # If you want this environment to be the default one, uncomment the following line: 23 | ENV CONDA_DEFAULT_ENV ${conda_env} 24 | 25 | COPY data /home/$NB_USER/work/data 26 | COPY python /home/$NB_USER/work/python 27 | 28 | RUN fix-permissions /home/$NB_USER 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Juan Orduz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/basel_weather_intro.R: -------------------------------------------------------------------------------- 1 | library("dplyr") 2 | library("lubridate") 3 | library("magrittr") 4 | library("janitor") 5 | library("ggplot2") 6 | library("here") 7 | 8 | #Set the working directory 9 | setwd(paste0(here(),"/R")) 10 | 11 | # Read the weather data 12 | weather = read.csv("../data/basel_weather.csv") 13 | 14 | # Clean the column names 15 | # This function removes special characters, spaces etc 16 | weather %<>% 17 | janitor::clean_names() 18 | 19 | colnames(weather)[2] = "temperature" 20 | 21 | # Create various date variables and add them to the dataframe 22 | weather %<>% 23 | mutate_at(vars(timestamp), as.character) %>% 24 | mutate(date = as.Date(substr(timestamp, 1 ,8 ), format="%Y%m%d")) %>% 25 | mutate(year = lubridate::year(date)) %>% 26 | mutate(month = lubridate::month(date)) %>% 27 | mutate(day = lubridate::day(date)) %>% 28 | mutate(day_of_year = lubridate::yday(date)) 29 | 30 | extract_hour = function(timestamp){ 31 | t = substr(timestamp, 10, 11) 32 | as.numeric(t) 33 | } 34 | 35 | weather %<>% 36 | mutate(hour = extract_hour(timestamp)) 37 | 38 | # Plot the hourly temperature over time 39 | ggplot(weather) + 40 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 41 | ggtitle("Basel Temperature (Hourly)") + 42 | xlab("Date") + 43 | ylab("Temperature (deg C)") 44 | 45 | # Plot the daily temperature over time 46 | daily_df = weather %>% 47 | group_by(date, day) %>% 48 | summarise(temperature = mean(temperature), 49 | day_of_year = unique(day_of_year)) 50 | 51 | ggplot(daily_df) + 52 | geom_line(mapping=aes(x=date, y=temperature), col="darkblue") + 53 | ggtitle("Basel Temperature (Daily)") + 54 | xlab("Date") + 55 | ylab("Temperature (deg C)") 56 | 57 | 58 | # Visualise the seasonality using a cyclical transformation and a spider plot. 59 | ggplot(daily_df) + 60 | geom_line(mapping=aes(x=day_of_year, y=temperature), col="blue") + 61 | coord_polar() + 62 | ggtitle("Yearly Seasonality") 63 | 64 | # Create a function for calculating the moving average 65 | moving_average = function(x, k = 14){ 66 | x_smooth = rep(NA, length(x)) 67 | for (i in (k+1):length(x)){ 68 | x_smooth[i] = mean(x[(i - k):i]) 69 | } 70 | return(x_smooth) 71 | } 72 | 73 | daily_df$temp_smooth_ma_7 = moving_average(daily_df$temperature, k=7) 74 | daily_df$temp_smooth_ma_14 = moving_average(daily_df$temperature, k=14) 75 | daily_df$temp_smooth_ma_365 = moving_average(daily_df$temperature, k=365) 76 | 77 | # Plot the Smoothed Moving Average variables 78 | ggplot(daily_df) + 79 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 80 | geom_line(mapping=aes(x=date, y=temp_smooth_ma_7), col="darkred") 81 | 82 | ggplot(daily_df) + 83 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 84 | geom_line(mapping=aes(x=date, y=temp_smooth_ma_14), col="darkred") 85 | 86 | ggplot(daily_df) + 87 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 88 | geom_line(mapping=aes(x=date, y=temp_smooth_ma_365), col="darkred") 89 | 90 | 91 | 92 | # Apply a gaussian filters as smoothers 93 | daily_df$temp_gf_30 = ksmooth(x=daily_df$date, y=daily_df$temperature, bandwidth = 60, kernel="normal")$y 94 | daily_df$temp_gf_90 = ksmooth(x=daily_df$date, y=daily_df$temperature, bandwidth = 180, kernel="normal")$y 95 | 96 | 97 | # Plot the smoothed functions 98 | ggplot(daily_df) + 99 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 100 | geom_line(mapping=aes(x=date, y=temp_gf_30), col="darkred") 101 | 102 | ggplot(daily_df) + 103 | geom_line(mapping=aes(x=date, y=temperature), col="blue") + 104 | geom_line(mapping=aes(x=date, y=temp_gf_90), col="darkred") 105 | -------------------------------------------------------------------------------- /R/causal_arima/intro_causal_arima_jo.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Causal Arima Intro" 3 | editor_options: 4 | markdown: 5 | wrap: 88 6 | --- 7 | 8 | ## Excercise 9 | 10 | On October 4, 2018 the Florence branch of an Italian supermarket chain introduced a 11 | price policy change on several store-brand products by permanently reducing their price. 12 | Your goal is to estimate the causal effect of the price policy change on the sales of 13 | one of the addressed products. 14 | 15 | - Data 16 | 17 | The data set includes the daily sales of one product from September 2017 to April 2019, 18 | its price and information on national holidays and already built-in day-of-the-week 19 | dummies. 20 | 21 | Dates : vector of dates Sales : time series of daily sales counts (number of units sold) 22 | TruePrice : the true unit price of the product Price : the new unit price series, set to 23 | a constant value in the post-intervention period hol : holiday dummy taking value 1 24 | before and after a national Italian holiday dec.sun : dummy taking value 1 on December 25 | Sundays sat--thr : day-of-the-week dummies 26 | 27 | - Questions 28 | 29 | 1. What is the total number of units sold due to the price reduction after 1-week, 30 | 1 month and 3 months from the intervention? 31 | 32 | 2. What is the total number of units sold at the end of the analysis period? 33 | 34 | 3. Plot the causal effect and residual diagnostics 35 | 36 | 4. Assume a multiplicative effect, how much more did the product sold due to the 37 | permanent price reduction? 38 | 39 | - R Package 40 | 41 | The suggested R package is `CausalArima`, you can install the development version from 42 | GitHub with 43 | 44 | ```{r} 45 | # install.packages("devtools") 46 | # devtools::install_github("FMenchetti/CausalArima") 47 | ``` 48 | 49 | ## Prepare Notebook 50 | 51 | ```{r} 52 | library("CausalArima") 53 | library("tidyverse") 54 | ``` 55 | 56 | ## Read Data 57 | 58 | ```{r} 59 | raw_data_df <- read_csv(file = "../../data/btsa-causalarima_2021-11-02_2033/dataset.csv") 60 | 61 | raw_data_df %>% head() 62 | ``` 63 | 64 | ## EDA 65 | 66 | ```{r} 67 | data_df <- raw_data_df %>% 68 | mutate( 69 | price_change = (TruePrice != Price), 70 | days_since_price_change = cumsum(as.numeric(price_change)) 71 | ) 72 | ``` 73 | 74 | ```{r} 75 | # date on which prices changed 76 | price_change_date <- data_df %>% 77 | filter(price_change) %>% 78 | pull(Dates) %>% 79 | min() 80 | ``` 81 | 82 | ```{r} 83 | ggplot(data=data_df) + 84 | geom_line(mapping = aes(x = Dates, y = Sales), color="black") + 85 | geom_vline(xintercept = price_change_date, color = "red", linetype="dashed") + 86 | ggtitle(label = "Daily Sales") 87 | ``` 88 | 89 | ```{r} 90 | ggplot(data=data_df) + 91 | geom_line(mapping = aes(x = Dates, y = TruePrice, color="TruePrice")) + 92 | geom_line(mapping = aes(x = Dates, y = Price, color="Price")) + 93 | geom_vline(xintercept = price_change_date, color = "black", linetype="dashed") + 94 | scale_color_brewer(palette="Set1") + 95 | labs(title="Price over time", color="price") 96 | ``` 97 | 98 | ## Answers 99 | 100 | 1. What is the total number of units sold due to the price 101 | reduction after 1-week, 1 month and 3 months from the 102 | intervention? 103 | 104 | ```{r} 105 | compute_sales_after_price_change <- function ( .df , day_window ) { 106 | 107 | .df_filtered <- .df %>% filter(price_change & days_since_price_change <= day_window) 108 | 109 | sales_day_window <- .df_filtered %>% 110 | summarise(Sales = sum(Sales, na.rm = TRUE)) %>% 111 | pull(Sales) 112 | 113 | return( sales_day_window ) 114 | } 115 | 116 | compute_sales_after_price_change(.df = data_df, day_window = 7) 117 | ``` 118 | 119 | ```{r} 120 | day_windows <- c(7, 30, 90, 120, 180) 121 | 122 | tibble( 123 | day_windows = day_windows, 124 | sales = day_windows %>% map_dbl(function (x) compute_sales_after_price_change(.df = data_df, day_window = x)) 125 | ) %>% 126 | ggplot() + 127 | geom_line(mapping = aes(x = day_windows, y = sales), color="blue") + 128 | geom_point(mapping = aes(x = day_windows, y = sales), color="blue") + 129 | labs(title="Sales since price change") 130 | 131 | ``` 132 | 133 | 2. What is the total number of units sold at the end of the 134 | analysis period? 135 | 136 | ```{r} 137 | total_number_sold_end <- compute_sales_after_price_change( 138 | .df = data_df, 139 | day_window = (data_df %>% filter(price_change) %>% nrow()) 140 | ) 141 | 142 | total_number_sold_end 143 | ``` 144 | 145 | 3. Plot the causal effect and residual diagnostics 146 | 147 | ```{r} 148 | ggplot(data=data_df) + 149 | geom_line(mapping = aes(x = Dates, y = log(Sales)), color="black") + 150 | geom_vline(xintercept = price_change_date, color = "red", linetype="dashed") + 151 | ggtitle(label = "Daily Sales - Log Scale") 152 | ``` 153 | 154 | 155 | ```{r} 156 | 157 | y <- ts(data =(data_df %>% pull(Sales)), frequency = 1) 158 | log_y <- log(y) 159 | dates <- data_df %>% pull(Dates) 160 | x_reg <- data_df %>% select(hol, dec.sun, sat, sun, mon, tue, wed, thr) 161 | 162 | ce <- CausalArima( 163 | y = log_y, 164 | auto = TRUE, 165 | dates = dates, 166 | int.date = price_change_date, 167 | xreg = x_reg 168 | ) 169 | ``` 170 | 171 | ```{r} 172 | forecasted <- plot(ce, type = "forecast") 173 | 174 | forecasted 175 | ``` 176 | 177 | ```{r} 178 | impact_p <- plot(ce, type ="impact") 179 | 180 | grid.arrange(impact_p$plot, impact_p$cumulative_plot) 181 | ``` 182 | ```{r} 183 | ce$model$coef 184 | ``` 185 | 186 | 4. Assume a multiplicative effect, how much more did the product sold due to the 187 | permanent price reduction? 188 | 189 | Let us denote by $y_{i}$ and $\hat{y}_{i}$ the observed and the forecasted time series of the arima model. Hence, the *causal effect* is given by: 190 | 191 | $$ 192 | ce_{i} = \log(y_{i}) - \log(\hat{y}_{i}) = \log\left(\frac{y_{i}}{\hat{y}_{i}}\right) 193 | $$ 194 | Therefore 195 | 196 | $$ 197 | \exp(ce_{i}) = \frac{y_{i}}{\hat{y}_{i}} \Longrightarrow \hat{y}_{i} = \frac{y_{i}}{\exp(ce_{i})} 198 | $$ 199 | 200 | 201 | ```{r} 202 | multiplicative_causal_effect <- ce$causal.effect %>% exp() 203 | 204 | price_changed_data_df <- data_df %>% 205 | filter(price_change) %>% 206 | mutate( 207 | multiplicative_causal_effect = multiplicative_causal_effect, 208 | sales_estimated_no_price_change = Sales / multiplicative_causal_effect, 209 | causal_effect = Sales - sales_estimated_no_price_change 210 | ) 211 | 212 | ggplot(data = price_changed_data_df) + 213 | geom_line(mapping = aes(x = Dates, y = multiplicative_causal_effect), color = "purple") + 214 | labs(title = "Multiplicative Causal Effect From C-ARIMA Model") 215 | ``` 216 | ```{r} 217 | causal_effect <- price_changed_data_df %>% 218 | summarise(causal_effect = sum(causal_effect, na.rm = TRUE)) %>% 219 | pull(causal_effect) 220 | ``` 221 | 222 | ```{r} 223 | print(glue::glue( 224 | "In the change of price period there were {total_number_sold_end} from where we estimate {round(causal_effect)} were caused by the price change. This accounts for {round( 100 * causal_effect / total_number_sold_end, digits=2)}% of the sales during this period." 225 | )) 226 | ``` 227 | 228 | --- 229 | 230 | ## Compare with CausalImpact 231 | 232 | ```{r} 233 | library("CausalImpact") 234 | 235 | ci_data <- data_df %>% 236 | mutate(Sales = log(Sales)) %>% 237 | dplyr::select(Sales, hol, dec.sun, sat, sun, mon, tue, wed, thr) %>% 238 | fill(Sales, .direction = "down") 239 | 240 | pre_period <- c(1, data_df %>% dplyr::filter(price_change) %>% pull(Index) %>% first() - 1) 241 | 242 | post_period <- c(pre_period[2] + 1, data_df %>% pull(Index) %>% last()) 243 | 244 | 245 | ci <- CausalImpact( 246 | data = zoo(ci_data), 247 | pre.period = pre_period, 248 | post.period = post_period 249 | ) 250 | 251 | summary(ci) 252 | ``` 253 | 254 | ```{r} 255 | plot(ci) 256 | ``` 257 | ```{r} 258 | plot(exp(ci$series$point.effect)) 259 | ``` 260 | 261 | -------------------------------------------------------------------------------- /R/gam_comparison_forecast.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "GAM Comparison" 3 | output: html_document 4 | --- 5 | 6 | ```{r setup, include=FALSE} 7 | # Load the libraries 8 | library("tidyverse") 9 | library("mgcv") 10 | library("here") 11 | 12 | 13 | setwd(here::here()) 14 | ``` 15 | 16 | ## Load the sample data and add additional variables 17 | ```{r} 18 | 19 | sample_data = read.csv("../data/sample_data_1.csv") 20 | 21 | plot(sample_data$sales, type="lines") 22 | 23 | ``` 24 | 25 | 26 | ```{r} 27 | # Add a day of the year variable 28 | sample_data = as_tibble(sample_data) 29 | sample_data$date = as.Date(sample_data$date) 30 | 31 | # Add day of the year and day of the week 32 | sample_data$day_of_year = lubridate::yday(sample_data$date) 33 | sample_data$day_of_week = lubridate::wday(sample_data$date) 34 | 35 | # Add an index variable to account for trend 36 | sample_data$index = c(1:nrow(sample_data)) 37 | 38 | # Add media lag variables 39 | sample_data$media_lag_1 = lag(sample_data$media, 1) 40 | sample_data$media_lag_2 = lag(sample_data$media, 2) 41 | sample_data$media_lag_3 = lag(sample_data$media, 3) 42 | # Add an autocorrelation variable from the previous month 43 | sample_data$sales_lag_31 = lag(sample_data$sales, 31) 44 | ``` 45 | 46 | ```{r} 47 | # Fill the lag NAs with the first genuine value 48 | sample_data$media_lag_1[is.na(sample_data$media_lag_1)] = 0 49 | sample_data$media_lag_2[is.na(sample_data$media_lag_2)] = 0 50 | sample_data$sales_lag_31[is.na(sample_data$sales_lag_31)] = 6.258472 51 | 52 | # Add the structural break 53 | sample_data$struct_break = ifelse(sample_data$date > as.Date("2020-01-31"), 1, 0) 54 | ``` 55 | 56 | ```{r} 57 | # Convert day of the week to a factor variable 58 | sample_data$day_of_week = as.factor(sample_data$day_of_week) 59 | ``` 60 | 61 | ```{r} 62 | # Add a dummy variable for the 7th of the 7th each year 63 | sample_data$july_seven = ifelse(as.character(sample_data$date) %in% c("2018-07-07","2019-07-07","2020-07-07","2021-07-07"), 1, 0) 64 | 65 | ``` 66 | 67 | ```{r} 68 | # Split into train and test sets 69 | train = sample_data[!(is.na(sample_data$sales)),] 70 | test = sample_data[(is.na(sample_data$sales)),] 71 | ``` 72 | 73 | 74 | ```{r} 75 | # Simple additive model 76 | gam_fit = mgcv::gam(sales ~ july_seven + media + media_lag_1 + media_lag_2 + media_lag_3 + s(day_of_year, k=12, bs="cc") + day_of_week + index + struct_break, data=train) 77 | 78 | ``` 79 | 80 | ## Additive Model (Fit) 81 | ```{r} 82 | plot(train$sales, type="lines") 83 | lines(predict(gam_fit), col="red") 84 | ``` 85 | 86 | ## Multiplicative Model 87 | ```{r} 88 | gam_fit = mgcv::gam(sales ~ media + media_lag_1 + media_lag_2 + july_seven + s(day_of_year, k=12, bs="cc") + s(day_of_year, by=index, k=12, bs="cc") + index + struct_break, data=train) 89 | 90 | forecast = predict(gam_fit) 91 | 92 | plot(train$sales, type="lines") 93 | lines(forecast, col="red") 94 | ``` 95 | 96 | ## Plot the forecast 97 | ```{r} 98 | test_forecast = predict(gam_fit, newdata = test) 99 | 100 | # Plot the test set 101 | full_forecast = c(forecast, test_forecast) 102 | 103 | plot(sample_data$sales, type="lines") 104 | lines(full_forecast, col="red") 105 | 106 | ``` 107 | 108 | ## Plot the components 109 | 110 | ```{r} 111 | summary(gam_fit) 112 | ``` 113 | - Seasonality Component 114 | ```{r} 115 | plot(gam_fit) 116 | ``` 117 | 118 | - Trend component 119 | ```{r} 120 | plot((1:nrow(sample_data))*coef(gam_fit)[6] + coef(gam_fit)[1], type="lines", ylab="Trend") 121 | ``` 122 | 123 | - Media lag effect (alpha = 0.7?) 124 | ```{r} 125 | plot(coef(gam_fit)[2:4], type="lines", ylab="Media Effect Size") 126 | ``` 127 | 128 | ## Plot the error 129 | ```{r} 130 | # Plot the test set 131 | full_forecast = c(forecast, test_forecast) 132 | 133 | error = sample_data$sales - full_forecast 134 | plot(error, type="lines") 135 | 136 | ``` 137 | 138 | ```{r} 139 | hist(error) 140 | ``` 141 | 142 | -------------------------------------------------------------------------------- /R/intro_forecasting/basel_stl_forecasting.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to STL Forecasting" 3 | output: html_notebook 4 | --- 5 | 6 | In this notebook we present a [decomposition model](https://fabletools.tidyverts.org/reference/decomposition_model.html) that combines STL (Seasonal and Trend decomposition using Loess) and ETS/ARIMA with [tidyverts](https://tidyverts.org/). From the documentation: 7 | 8 | > This function allows you to specify a decomposition combination model using any additive decomposition. It works by first decomposing the data using the decomposition method provided to dcmp_fn with the given formula. Secondary models are used to fit each of the components from the resulting decomposition. 9 | 10 | For more details see Forecasting: [Principles and Practice, Section 3.6 STL Decomposition](https://otexts.com/fpp3/stl.html). 11 | 12 | ```{r} 13 | library(readr) 14 | library(dplyr) 15 | library(lubridate) 16 | library(ggplot2) 17 | library(fable) 18 | library(feasts) 19 | library(stringr) 20 | options(dplyr.summarise.inform=F) 21 | ``` 22 | 23 | # Read Data 24 | 25 | We will use the Basel temperature data set. 26 | 27 | ```{r} 28 | raw_df <- read_csv('../../data/basel_weather.csv') 29 | ``` 30 | 31 | # EDA 32 | 33 | ```{r} 34 | data_df <- raw_df %>% 35 | rename(temperature = `Basel Temperature [2 m elevation corrected]`, 36 | precipitation = `Basel Precipitation Total`, 37 | wind_speed = `Basel Wind Speed [10 m]`, 38 | wind_direction = `Basel Wind Direction [10 m]`) %>% 39 | mutate(date = date(timestamp), 40 | year = year(timestamp), 41 | month = month(timestamp), 42 | day = day(timestamp), 43 | dayofyear = yday(timestamp), 44 | hour = hour(timestamp)) 45 | 46 | daily_data_df <- data_df %>% 47 | group_by(date, year, month, day, dayofyear) %>% 48 | summarise(temperature = mean(temperature)) %>% 49 | as_tsibble(index=date) 50 | 51 | daily_data_df %>% head() 52 | ``` 53 | 54 | ```{r} 55 | autoplot(daily_data_df, temperature) + 56 | labs(title='Basel Temperature (Daily)', y=expression(degree*C)) 57 | ``` 58 | The time series contains a strong seasonal component. 59 | 60 | ```{r} 61 | daily_data_df %>% gg_season(temperature) 62 | ``` 63 | We check the decomposition of the time series using STL. 64 | 65 | ```{r} 66 | daily_data_df %>% 67 | model(STL(temperature ~ season(period = 365, window = Inf))) %>% 68 | components() %>% 69 | autoplot() 70 | ``` 71 | 72 | # Train-Test Split 73 | 74 | ```{r} 75 | train_test_cut_date <- as_date('2019-01-01') 76 | 77 | df_train <- daily_data_df %>% filter(date < train_test_cut_date) 78 | df_test <- daily_data_df %>% filter(date >= train_test_cut_date) 79 | 80 | daily_data_df %>% 81 | mutate(data_set = if_else(date < train_test_cut_date, 'train', 'test')) %>% 82 | ggplot(aes(x=date, y=temperature, color=data_set)) + 83 | geom_line() + 84 | labs(title='Basel Temperature (Daily)', y=expression(degree*C)) + 85 | geom_vline(xintercept = train_test_cut_date, linetype = "longdash") 86 | ``` 87 | # Model Fit 88 | 89 | We fit an exponential smoothing and an ARIMA model to the seasonal adjusted time series. 90 | 91 | ```{r} 92 | fit <- df_train %>% 93 | model( 94 | stl_arima = decomposition_model( 95 | STL(temperature ~ season(period = 365, window = Inf)), 96 | ARIMA(season_adjust ~ 0 + pdq(2, 1, 1) + PDQ(0, 0, 0)) 97 | ), 98 | stl_ets = decomposition_model( 99 | STL(temperature ~ season(period = 365, window = Inf)), 100 | ETS(season_adjust ~ season("N")) 101 | ) 102 | ) 103 | ``` 104 | 105 | # Generate Forecast 106 | 107 | ```{r} 108 | fc <- fit %>% 109 | forecast(h = nrow(df_test)) 110 | ``` 111 | 112 | ```{r} 113 | error <- fc %>% accuracy(df_test) 114 | 115 | rmse_arima <- error %>% filter(.model=="stl_arima") %>% pull(RMSE) 116 | rmse_ets <- error %>% filter(.model=="stl_ets") %>% pull(RMSE) 117 | ``` 118 | 119 | ```{r} 120 | fc %>% autoplot(df_test, level=c()) + 121 | labs(title='Basel Temperature (Daily)', y=expression(degree*C)) + 122 | scale_color_discrete(labels = c(stl_arima = str_interp("STL+ARIMA rmse = $[.2f]{rmse_arima}"), 123 | stl_ets = str_interp("STL+ETS rmse = $[.2f]{rmse_ets}"))) 124 | ``` 125 | 126 | -------------------------------------------------------------------------------- /R/intro_forecasting/intro_arima.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Auto-regressive integrated moving average models" 3 | output: html_notebook 4 | --- 5 | 6 | ```{r} 7 | library(dplyr) 8 | library(lubridate) 9 | library(tidyr) 10 | library(climate) 11 | library(fable) 12 | library(feasts) 13 | library(tsibble) 14 | library(rsample) 15 | options(dplyr.summarise.inform=F) 16 | ``` 17 | 18 | 19 | # Introduction 20 | 21 | ARIMA stands for Auto-Regressive Integrated Moving Average. Let's go through each one of these concepts one by one. 22 | 23 | ## Auto-regressive 24 | 25 | $$y_t = c + \rho_1 y_{t-1} + \rho_2 y_{t-2} + e_t$$ 26 | 27 | The autoregressive part of the model assumes that the best way to explain the current value in a time series is using a set number of the past observations. In this case, we are looking at a AR(2) model, and $\rho_1$ and $\rho_2$ are the parameters of interest for the model. 28 | 29 | ## Moving average 30 | 31 | The moving average component assumes that the best explanation for a time series is the error term of the previous values in the series: 32 | 33 | $$y_t = c + \mu_1 e_{t-1} + \mu_1 e_{t-2} + e_t$$ 34 | 35 | This would be a MA(2) model, and $\mu_1$ and $\mu_2$ are the parameters of interest of the model. 36 | 37 | ## Integrated 38 | 39 | This value determines the amount of times we differentiate the series ($y_t-y_{t-1}$) for the AR and MA models above. 40 | 41 | The final equation depends on the integrated term. For more information on the functional form of the seasonal ARIMA, please check the fable documentation. 42 | 43 | The parameters we are going to use below are $p$ for the AR component, $d$ for the integrated component, and $q$ for the MA component. 44 | 45 | # Data processing 46 | 47 | For this tutorial we are going to use the CO2 data available in the climate package. 48 | 49 | ```{r} 50 | data <- climate::meteo_noaa_co2() %>% select(yy, mm, co2_avg) %>% filter(yy < 2003) 51 | data %>% head(25) 52 | ``` 53 | We would like to reorganize the data set in monthly data. 54 | 55 | ```{r} 56 | y <- data %>% 57 | group_by(year_month = yearmonth(ISOdate(yy, mm, 1))) %>% 58 | summarize(co2 = mean(co2_avg)) %>% 59 | as_tsibble() 60 | ``` 61 | There are no missing months, but if there were, we would fill them like this... 62 | 63 | ```{r} 64 | y <- y %>% 65 | fill_gaps() %>% 66 | fill(co2) 67 | ``` 68 | 69 | ```{r} 70 | autoplot(y) 71 | ``` 72 | ```{r} 73 | y %>% 74 | features(co2, unitroot_kpss) 75 | ``` 76 | ```{r} 77 | y %>% 78 | mutate(diff_co2 = difference(co2)) %>% 79 | features(diff_co2, unitroot_kpss) 80 | ``` 81 | ```{r} 82 | y %>% 83 | mutate(diff_co2 = difference(co2)) %>% 84 | autoplot(diff_co2) 85 | ``` 86 | # Grid search 87 | 88 | Since we have little information about the data generating process that generates the data we are going to study, we can use a grid search to determine the set of parameters that best explains the data using a simple metric: the Akaike Information Criteria. 89 | 90 | The AIC is a tool we use to measure the performance of a model. By itself it does not really provide much information, but it shines when it is used to compare two or more models. 91 | 92 | ```{r} 93 | y %>% 94 | model(ARIMA(co2 ~ 0 + pdq(0, 1, 1) + PDQ(0, 0, 0))) %>% 95 | report() 96 | ``` 97 | 98 | ```{r} 99 | y %>% 100 | mutate(diff_co2 = difference(co2)) %>% 101 | model(ARIMA(diff_co2 ~ 0 + pdq(0, 0, 1) + PDQ(0, 0, 0))) %>% 102 | report() 103 | ``` 104 | ```{r} 105 | y %>% 106 | model(ARIMA(co2 ~ 0 + pdq(0:2, 0:2, 0:2) + PDQ(0, 0, 0), ic="aic")) %>% 107 | report() 108 | ``` 109 | 110 | According to this calculation, ARIMA(2,1,1) is the best performing model in terms of AIC out of the set of possible parameters analyzed. 111 | 112 | ```{r} 113 | y %>% 114 | model(ARIMA(co2 ~ 0 + pdq(2, 1, 1) + PDQ(0, 0, 0))) %>% 115 | coef() 116 | ``` 117 | 118 | ```{r} 119 | split <- initial_time_split(y, 0.9) 120 | 121 | fit <- training(split) %>% 122 | model(ARIMA(co2 ~ 0 + pdq(2, 1, 1) + PDQ(0, 0, 0))) 123 | 124 | fc <- fit %>% 125 | forecast(h = nrow(testing(split))) 126 | ``` 127 | 128 | ```{r} 129 | fc %>% accuracy(testing(split)) 130 | ``` 131 | ```{r} 132 | fc %>% autoplot(testing(split)) 133 | ``` 134 | The forecast is not great, primarily because our model does not take into consideration the clearly seasonal model of the data. 135 | 136 | We can expand this experiment by allowing a seasonal component to be added to the modeling. With long and clearly seasonal data sets like this one, it might generate better results. 137 | 138 | # Seasonal ARIMA 139 | 140 | We can include a seasonal component to the estimation of the time series to incorporate the typical monthly behavior not included in traditional ARIMA analysis. 141 | 142 | 143 | ```{r} 144 | y %>% 145 | model(ARIMA(co2 ~ 0 + pdq(0:2, 0:2, 0:2) + PDQ(0:1, 0:1, 0:1), ic="aic")) %>% 146 | report() 147 | ``` 148 | ```{r} 149 | y %>% 150 | model(ARIMA(co2 ~ 0 + pdq(0, 1, 1) + PDQ(1, 1, 1))) %>% 151 | coef() 152 | ``` 153 | 154 | ```{r} 155 | fit <- training(split) %>% 156 | model(ARIMA(co2 ~ 0 + pdq(0, 1, 1) + PDQ(1, 1, 1))) 157 | 158 | fc <- fit %>% 159 | forecast(h = nrow(testing(split))) 160 | ``` 161 | 162 | ```{r} 163 | fc %>% accuracy(testing(split)) 164 | ``` 165 | 166 | ```{r} 167 | fc %>% autoplot(testing(split)) 168 | ``` 169 | # Some notes 170 | 171 | * This notebook tries to mimic the python version, however there are some differences. 172 | * in theory the data set is the same (CO2 Mauna Loa (NOAA)), but in practice it is a bit different 173 | * this notebook uses the KPSS test instead of the ADF test. 174 | * the optimal seasonal ARIMA in this notebook has a non-seasonal component that is not auto-regressive ($p=0$). 175 | * We determined the best model using the AIC. There are other target functions you can use to choose your $p$, $d$, and $q$ parameters. One possibility is the mean square error between the predicted values given a set of parameters, and the test set. 176 | * An alternative way to check whether we have the right set of parameters is to check the ACF of the errors. 177 | * We must not forget to check whether the chosen parameters to explain our model fit our understanding of the underlying data. -------------------------------------------------------------------------------- /R/intro_forecasting/intro_exponential_smoothing.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction To Exponential Smoothing" 3 | output: html_notebook 4 | --- 5 | 6 | Loading packages and set up the notebook. 7 | 8 | ```{r} 9 | library(readr) 10 | library(dplyr) 11 | library(tibble) 12 | library(ggplot2) 13 | library(fable) 14 | ``` 15 | 16 | Load sample data (prepared earlier). 17 | 18 | ```{r} 19 | df <- read_csv("../../data/intro_ets.csv") %>% 20 | rowid_to_column("id") %>% 21 | as_tsibble(index=id) 22 | df %>% head() 23 | ``` 24 | 25 | # Simple Exponential Smoothing 26 | 27 | Formula for simple exponential smoothing... 28 | 29 | \begin{align} 30 | s_t &= \alpha x_t + (1-\alpha) s_{t-1} \\ 31 | &= \alpha x_t + (1-\alpha)(\alpha x_{t-1} + (1-\alpha) s_{t-2}) \\ 32 | &= \alpha x_t + (1-\alpha) \alpha x_{t-1} + (1-\alpha)^2 s_{t-2} 33 | \end{align} 34 | 35 | Lets now try out simple exponential smoothing on a time series 36 | 37 | ```{r} 38 | df %>% autoplot(t1) 39 | ``` 40 | Train the model with arbitrary smoothing_level (alpha) parameter: 41 | 42 | ```{r} 43 | fit <- df %>% 44 | model( 45 | ETS(t1 ~ trend("N", alpha=0.2) + season("N")) 46 | ) 47 | ``` 48 | 49 | The plot below shows the original time series and the backfit exponential smoothing values. Adjusting the alpha parameter controls the smoothness. Values of alpha near 1 put larger weights on more recent values. Values of alpha near 0 put larger weights on older values and hence we get a smoother fit. 50 | 51 | ```{r} 52 | fit %>% 53 | augment() %>% 54 | pivot_longer(c(t1, .fitted)) %>% 55 | ggplot(aes(x=id, y=value, colour=name)) + 56 | geom_line() 57 | ``` 58 | Now lets look at the forecast: 59 | 60 | ```{r} 61 | fit %>% 62 | forecast(h=20) %>% 63 | autoplot(df) 64 | ``` 65 | What happens when we try it on a a series with a trend? 66 | 67 | ```{r} 68 | df %>% autoplot(t2) 69 | ``` 70 | ```{r} 71 | df %>% 72 | model( 73 | ETS(t2 ~ trend("N", alpha=0.2) + season("N")) 74 | ) %>% 75 | forecast(h=20) %>% 76 | autoplot(df) 77 | ``` 78 | # Double Exponential Smoothing 79 | 80 | \begin{align} 81 | s_t &= \alpha x_t + (1-\alpha)(s_{t-1} + b_{t-1}) \\ 82 | b_t &= \beta (s_t-s_{t-1}) + (1-\beta) b_{t-1} 83 | \end{align} 84 | 85 | ```{r} 86 | df %>% 87 | model( 88 | ETS(t2 ~ trend("A", alpha=0.5, beta=0.5) + season("N")) 89 | ) %>% 90 | forecast(h=20) %>% 91 | autoplot(df) 92 | ``` 93 | Ok, that works on simple series, but what if we want to exploit a known seasonal pattern? 94 | 95 | ```{r} 96 | df %>% autoplot(t3) 97 | ``` 98 | # Triple Exponential Smoothing 99 | 100 | Add in a another formula to account for periodic cycles! 101 | 102 | Triple Exponential Smoothing (Additive) 103 | 104 | \begin{align} 105 | s_0 &= x_0 \\ 106 | s_t &= \alpha(x_t - c_{t-L})+(1-\alpha)(s_{t-1}+b_{t-1}) \\ 107 | b_t &= \beta(s_t - s_{t-1}) + (1-\beta)b_{t-1} \\ 108 | c_t &= \gamma(x_t - s_{t-1} - b_{t-1}) + (1 - \gamma)c_{t-L} \\ 109 | F_{t+m} &= s_t + mb_t + c_{t-L+1+(m-1) \bmod L} \\ 110 | \end{align} 111 | 112 | ```{r} 113 | df %>% 114 | model( 115 | ETS(t3 ~ trend("A", alpha=0.4, beta=0.01) + season("A", period=20, gamma=0.2)) 116 | ) %>% 117 | forecast(h=20) %>% 118 | autoplot(df) 119 | ``` 120 | # Exponential Growth 121 | 122 | ```{r} 123 | df %>% autoplot(t4) 124 | ``` 125 | ```{r} 126 | df %>% 127 | model( 128 | ETS(t4 ~ trend("M", alpha=0.6, beta=0.5) + season("N")) 129 | ) %>% 130 | forecast(h=20, times=100) %>% 131 | autoplot(df) 132 | ``` 133 | # Choosing alpha, beta, gamma automatically 134 | 135 | The fable package can find the best parameters of alpha, beta and gamma via backfitting. Once you have chosen the appropriate model above, then this a great option to get a baseline. 136 | 137 | ```{r} 138 | fit <- df %>% 139 | model( 140 | ETS(t3 ~ trend("A") + season("A", period=20)) 141 | ) 142 | fit %>% coef() 143 | ``` 144 | 145 | ```{r} 146 | fit %>% 147 | forecast(h=20) %>% 148 | autoplot(df) 149 | ``` 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /R/synthetic_control/rep_for_btsa.R: -------------------------------------------------------------------------------- 1 | ## Replication Code for 2 | # A. Abadie, A. Diamond, and J. Hainmueller. 2014. 3 | # Comparative Politics and the Synthetic Control Method 4 | # American Journal of Political Science. 5 | # Original source for the code and the data: 6 | # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/24714 7 | # This version for the Berlin Time Series Analysis Meet-up 8 | 9 | library(foreign) 10 | library("Synth") 11 | library(xtable) 12 | library(ggplot2) 13 | library(scales) 14 | library(tidyverse) 15 | # Load Data 16 | d <- read.dta("repgermany.dta") 17 | 18 | 19 | # Data set-up 20 | countrytosynthetise <- 7 21 | dataprep.out <- 22 | dataprep( 23 | foo = d, 24 | predictors = c("gdp","trade","infrate"), 25 | dependent = "gdp", 26 | unit.variable = 1, 27 | time.variable = 3, 28 | special.predictors = list( 29 | list("industry", 1971:1980, c("mean")), 30 | list("schooling",c(1970,1975), c("mean")), 31 | list("invest70" ,1980, c("mean")) 32 | ), 33 | treatment.identifier = countrytosynthetise, 34 | controls.identifier = unique(d$index)[-which(unique(d$index) %in% countrytosynthetise)], 35 | time.predictors.prior = 1971:1989, 36 | time.optimize.ssr = 1971:1990, 37 | unit.names.variable = 2, 38 | time.plot = 1960:2003 39 | ) 40 | 41 | # fit training model 42 | synth.out <- 43 | synth( 44 | data.prep.obj=dataprep.out, 45 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 46 | ) 47 | 48 | # data prep for main model 49 | dataprep.out <- 50 | dataprep( 51 | foo = d, 52 | predictors = c("gdp","trade","infrate"), 53 | dependent = "gdp", 54 | unit.variable = 1, 55 | time.variable = 3, 56 | special.predictors = list( 57 | list("industry" ,1981:1990, c("mean")), 58 | list("schooling",c(1980,1985), c("mean")), 59 | list("invest80" ,1980, c("mean")) 60 | ), 61 | treatment.identifier = countrytosynthetise, 62 | controls.identifier = unique(d$index)[-which(unique(d$index) %in% countrytosynthetise)], 63 | time.predictors.prior = 1960:1989, 64 | time.optimize.ssr = 1960:1990, 65 | unit.names.variable = 2, 66 | time.plot = 1960:2003 67 | ) 68 | 69 | # fit main model with v from training model 70 | synth.out <- synth( 71 | data.prep.obj=dataprep.out, 72 | custom.v=as.numeric(synth.out$solution.v) 73 | ) 74 | 75 | #### Table 2 76 | synth.tables <- synth.tab( 77 | dataprep.res = dataprep.out, 78 | synth.res = synth.out 79 | ); synth.tables 80 | 81 | # Replace means for OECD sample (computed externally using proper pop weighting) 82 | synth.tables$tab.pred[,3] <- c(8021.1,31.9,7.4,34.2,44.1,25.9) 83 | colnames(synth.tables$tab.pred)[3] <- "Rest of OECD Sample" 84 | rownames(synth.tables$tab.pred) <- c("GDP per-capita","Trade openness", 85 | "Inflation rate","Industry share", 86 | "Schooling","Investment rate") 87 | 88 | xtable(round(synth.tables$tab.pred,1),digits=1) 89 | 90 | #### Table 1 91 | # synth weights 92 | tab1 <- data.frame(synth.tables$tab.w) 93 | tab1[,1] <- round(tab1[,1],2) 94 | # regression weights 95 | X0 <- cbind(1,t(dataprep.out$X0)) 96 | X1 <- as.matrix(c(1,dataprep.out$X1)) 97 | W <- X0%*%solve(t(X0)%*%X0)%*%X1 98 | Wdat <- data.frame(unit.numbers=as.numeric(rownames(X0)), 99 | regression.w=round(W,2)) 100 | tab1 <- merge(tab1,Wdat,by="unit.numbers") 101 | tab1 <- tab1[order(tab1[,3]),] 102 | 103 | 104 | # Table 1 105 | xtable(cbind(tab1[1:9,c(3,2,4)], 106 | tab1[10:18,c(3,2,4)] 107 | ) 108 | ) 109 | 110 | #### Figures 1, 2 and 3 111 | data.to.plot <- data.frame(year = rownames(dataprep.out$Y1plot), 112 | west.germany = dataprep.out$Y1plot[, 1]) 113 | 114 | data.to.plot <- as.data.frame(d[,c("gdp","country", "year" )]) 115 | data.to.plot$west.germany <- ifelse(data.to.plot$country == "West Germany", "West Germany", "Not West Germany") 116 | data.to.plot$west.germany.size <- ifelse(data.to.plot$west.germany == "West Germany", "1","2") 117 | graphcolors <- c("#999999", "#ef8a62") 118 | 119 | 120 | table(data.to.plot$country, data.to.plot$west.germany.size) 121 | 122 | 123 | ## PLOT WITH ONLY WEST GERMANY 124 | ggplot(data = data.to.plot[data.to.plot$west.germany == "West Germany",], aes(x = year, y = gdp, 125 | group = country, 126 | color = west.germany, 127 | linetype = west.germany.size)) + 128 | geom_line(size = 1.5) + 129 | labs(color = "West Germany?")+ 130 | guides(linetype = FALSE, color = FALSE) + 131 | theme_bw(base_size = 15) + 132 | theme(legend.position = "bottom") + 133 | geom_vline(xintercept = 1990, 134 | color = "#88419d") + 135 | annotate("text", x = 1985, 136 | label="\nReunification", y = 1000, 137 | colour = "#88419d", alpha = 0.8, angle = 0) + 138 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 139 | labels = comma_format(big.mark = ",", 140 | decimal.mark = ".")) + 141 | scale_color_manual(values = c("#ef8a62")) + 142 | coord_cartesian(ylim = c(0, 30000)) #+ 143 | #ggsave(paste0("figures/germany.pdf"), 144 | # width = 15, height = 10, units = 'cm') 145 | 146 | 147 | 148 | ## PLOT WITH WEST GERMANY AND ALL THE OTHER COUNTRIES 149 | ggplot(data = data.to.plot, aes(x = year, y = gdp, 150 | group = country, 151 | color = west.germany, 152 | linetype = west.germany.size)) + 153 | geom_line(size = 1.5) + 154 | labs(color = "West Germany?")+ 155 | guides(linetype = FALSE) + 156 | theme_bw(base_size = 10) + 157 | theme(legend.position = "bottom") + 158 | geom_vline(xintercept = 1990, 159 | color = "#88419d") + 160 | annotate("text", x = 1985, 161 | label="Reunification", y = 1000, 162 | colour = "#88419d", alpha = 0.8, angle = 0) + 163 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 164 | labels = comma_format(big.mark = ",", 165 | decimal.mark = ".")) + 166 | scale_color_manual(values = graphcolors) + 167 | coord_cartesian(ylim = c(0, 30000)) #+ 168 | #ggsave(paste0("figures/germanynotgermany.pdf"), 169 | # width = 15, height = 10, units = 'cm') 170 | 171 | 172 | ## PLOT WITH WEST GERMANY AND THE AVERAGE FROM OTHER COUNTRIES 173 | data.to.plot.average <- data.to.plot %>% 174 | group_by(west.germany, year, west.germany.size) %>% 175 | summarise(GDP = mean(gdp)) 176 | 177 | ggplot(data = data.to.plot.average, 178 | aes(x = year, y = GDP, 179 | group = west.germany, 180 | color = west.germany)) + 181 | geom_line(size = 1.5) + 182 | labs(color = "West Germany?")+ 183 | theme_bw(base_size = 10) + 184 | theme(legend.position = "bottom") + 185 | geom_vline(xintercept = 1990, 186 | color = "#88419d") + 187 | annotate("text", x = 1985, 188 | label="Reunification", y = 1000, 189 | colour = "#88419d", alpha = 0.8, angle = 0) + 190 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 191 | labels = comma_format(big.mark = ",", 192 | decimal.mark = ".")) + 193 | scale_color_manual(values = graphcolors) + 194 | coord_cartesian(ylim = c(0, 30000)) #+ 195 | #ggsave(paste0("figures/germanyaverage.pdf"), 196 | # width = 15, height = 10, units = 'cm') 197 | 198 | 199 | 200 | data.to.plot.average$west.germany[data.to.plot.average$west.germany == "Not West Germany"] <- "Average of Other OECD Countries" 201 | 202 | ggplot(data = data.to.plot.average, 203 | aes(x = year, y = GDP, 204 | group = west.germany, 205 | color = west.germany)) + 206 | geom_line(size = 1.5) + 207 | labs(color = "West Germany?")+ 208 | theme_bw(base_size = 10) + 209 | theme(legend.position = "bottom") + 210 | geom_vline(xintercept = 1990, 211 | color = "#88419d") + 212 | annotate("text", x = 1985, 213 | label="Reunification", y = 1000, 214 | colour = "#88419d", alpha = 0.8, angle = 0) + 215 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 216 | labels = comma_format(big.mark = ",", 217 | decimal.mark = ".")) + 218 | scale_color_manual(values = graphcolors) + 219 | coord_cartesian(ylim = c(0, 30000)) #+ 220 | #ggsave(paste0("figures/germanyaverage2.pdf"), 221 | # width = 15, height = 10, units = 'cm') 222 | 223 | 224 | 225 | 226 | # SYNTHETIC UNIT - Weights 227 | # Figure 4 228 | data.to.plot.synthetic <- data.to.plot.average 229 | 230 | synthY0 <- (dataprep.out$Y0%*%synth.out$solution.w) 231 | data.to.plot.synthetic$GDP[data.to.plot.synthetic$west.germany == "Average of Other OECD Countries"] <- (dataprep.out$Y0%*%synth.out$solution.w) 232 | data.to.plot.synthetic$west.germany[data.to.plot.synthetic$west.germany == "Average of Other OECD Countries"] <- "Synthetic West Germany" 233 | 234 | 235 | ggplot(data = data.to.plot.synthetic, 236 | aes(x = year, y = GDP, 237 | group = west.germany, 238 | color = west.germany)) + 239 | geom_line(size = 1.5) + 240 | labs(color = "West Germany?")+ 241 | theme_bw(base_size = 10) + 242 | theme(legend.position = "bottom") + 243 | geom_vline(xintercept = 1990, 244 | color = "#88419d") + 245 | annotate("text", x = 1985, 246 | label="Reunification", y = 1000, 247 | colour = "#88419d", alpha = 0.8, angle = 0) + 248 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 249 | labels = comma_format(big.mark = ",", 250 | decimal.mark = ".")) + 251 | scale_color_manual(values = graphcolors) + 252 | coord_cartesian(ylim = c(0, 30000)) #+ 253 | #ggsave(paste0("figures/germanysynth.pdf"), 254 | # width = 15, height = 10, units = 'cm') 255 | 256 | 257 | 258 | # SYNTHETIC UNIT - Regression 259 | # Figure 8 260 | data.to.plot.synth.reg <- data.to.plot.average 261 | 262 | synthY0.reg <- (dataprep.out$Y0%*%W) 263 | data.to.plot.synth.reg$GDP[data.to.plot.synth.reg$west.germany == "Average of Other OECD Countries"] <- (dataprep.out$Y0%*%W) 264 | data.to.plot.synth.reg$west.germany[data.to.plot.synth.reg$west.germany == "Average of Other OECD Countries"] <- "Synthetic West Germany" 265 | 266 | 267 | ggplot(data = data.to.plot.synth.reg, 268 | aes(x = year, y = GDP, 269 | group = west.germany, 270 | color = west.germany)) + 271 | geom_line(size = 1.5) + 272 | labs(color = "West Germany?")+ 273 | theme_bw(base_size = 10) + 274 | theme(legend.position = "bottom") + 275 | geom_vline(xintercept = 1990, 276 | color = "#88419d") + 277 | annotate("text", x = 1985, 278 | label="Reunification", y = 1000, 279 | colour = "#88419d", alpha = 0.8, angle = 0) + 280 | scale_y_continuous(name="per-capita GDP (PPP, 2002 USD)", 281 | labels = comma_format(big.mark = ",", 282 | decimal.mark = ".")) + 283 | scale_color_manual(values = graphcolors) + 284 | coord_cartesian(ylim = c(0, 30000)) #+ 285 | #ggsave(paste0("figures/germanysynthreg.pdf"), 286 | # width = 15, height = 10, units = 'cm') 287 | 288 | 289 | 290 | # Gap 291 | # Figure 5 292 | gap <- dataprep.out$Y1-(dataprep.out$Y0%*%synth.out$solution.w) 293 | 294 | data.to.plot.gap <- data.to.plot.synthetic 295 | data.to.plot.gap$GDP[data.to.plot.gap$west.germany == "West Germany"] <- dataprep.out$Y1-(dataprep.out$Y0%*%synth.out$solution.w) 296 | 297 | data.to.plot.gap$GDP[data.to.plot.gap$west.germany == "Synthetic West Germany"] <- 0 298 | 299 | 300 | ggplot(data = data.to.plot.gap, 301 | aes(x = year, y = GDP, 302 | group = west.germany, 303 | color = west.germany)) + 304 | geom_line(size = 1.5) + 305 | labs(color = "West Germany?")+ 306 | theme_bw(base_size = 10) + 307 | theme(legend.position = "bottom") + 308 | geom_vline(xintercept = 1990, 309 | color = "#88419d") + 310 | annotate("text", x = 1985, 311 | label="Reunification", y = 1000, 312 | colour = "#88419d", alpha = 0.8, angle = 0) + 313 | scale_y_continuous(name="Gap in per-capita GDP (PPP, 2002 USD)", 314 | labels = comma_format(big.mark = ",", 315 | decimal.mark = ".")) + 316 | scale_color_manual(values = graphcolors) + 317 | coord_cartesian(ylim = c(-5000, 5000)) #+ 318 | #ggsave(paste0("figures/germanygap.pdf"), 319 | # width = 15, height = 10, units = 'cm') 320 | 321 | 322 | 323 | 324 | # loop across control units 325 | storegaps <- 326 | matrix(NA, 327 | length(1960:2003), 328 | length(unique(d$index))-1 329 | ) 330 | rownames(storegaps) <- 1960:2003 331 | i <- 1 332 | co <- unique(d$index) 333 | 334 | for(k in unique(d$index)[-7]){ 335 | 336 | # data prep for training model 337 | dataprep.out <- 338 | dataprep( 339 | foo = d, 340 | predictors = c("gdp","trade","infrate"), 341 | dependent = "gdp", 342 | unit.variable = 1, 343 | time.variable = 3, 344 | special.predictors = list( 345 | list("industry",1971:1980, c("mean")), 346 | list("schooling" ,c(1970,1975), c("mean")), 347 | list("invest70" ,1980, c("mean")) 348 | ), 349 | treatment.identifier = k, 350 | controls.identifier = co[-which(co==k)], 351 | time.predictors.prior = 1971:1989, 352 | time.optimize.ssr = 1971:1990, 353 | unit.names.variable = 2, 354 | time.plot = 1960:2003 355 | ) 356 | 357 | # fit training model 358 | synth.out <- 359 | synth( 360 | data.prep.obj=dataprep.out, 361 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 362 | ) 363 | 364 | # data prep for main model 365 | dataprep.out <- 366 | dataprep( 367 | foo = d, 368 | predictors = c("gdp","trade","infrate"), 369 | dependent = "gdp", 370 | unit.variable = 1, 371 | time.variable = 3, 372 | special.predictors = list( 373 | list("industry" ,1981:1990, c("mean")), 374 | list("schooling",c(1980,1985), c("mean")), 375 | list("invest80" ,1980, c("mean")) 376 | ), 377 | treatment.identifier = k, 378 | controls.identifier = co[-which(co==k)], 379 | time.predictors.prior = 1960:1990, 380 | time.optimize.ssr = 1960:1989, 381 | unit.names.variable = 2, 382 | time.plot = 1960:2003 383 | ) 384 | 385 | # fit main model 386 | synth.out <- synth( 387 | data.prep.obj=dataprep.out, 388 | custom.v=as.numeric(synth.out$solution.v) 389 | ) 390 | 391 | storegaps[,i] <- 392 | dataprep.out$Y1- 393 | (dataprep.out$Y0%*%synth.out$solution.w) 394 | i <- i + 1 395 | } # close loop over control units 396 | d <- d[order(d$index,d$year),] 397 | colnames(storegaps) <- unique(d$country)[-7] 398 | storegaps <- cbind(gap,storegaps) 399 | colnames(storegaps)[1] <- c("West Germany") 400 | 401 | 402 | 403 | # Placebo gaps 404 | # Figure 6 405 | sgaps <- as.data.frame(storegaps) 406 | sgaps$year <- rownames(sgaps) 407 | sgaps <- reshape2::melt(sgaps,id.vars = "year") 408 | 409 | 410 | sgaps$west.germany <- ifelse(sgaps$variable == "West Germany", "West Germany", "Not West Germany") 411 | sgaps$west.germany.size <- ifelse(sgaps$west.germany == "West Germany", "1","2") 412 | 413 | sgaps$year <- as.numeric(sgaps$year) 414 | 415 | data.to.plot$west.germany <- ifelse(data.to.plot$country == "West Germany", "West Germany", "Not West Germany") 416 | ggplot(data = sgaps, aes(x = year, y = value, 417 | group = variable, 418 | color = west.germany, 419 | linetype = west.germany.size)) + 420 | geom_line() + 421 | labs(color = "West Germany?")+ 422 | guides(linetype = FALSE) + 423 | theme_bw(base_size = 10) + 424 | theme(legend.position = "bottom") + 425 | geom_vline(xintercept = 1990, 426 | color = "#88419d") + 427 | annotate("text", x = 1985, 428 | label="Reunification", y = 4000, 429 | colour = "#88419d", alpha = 0.8, angle = 0) + 430 | scale_y_continuous(name="Gap in per-capita GDP (PPP, 2002 USD)", 431 | labels = comma_format(big.mark = ",", 432 | decimal.mark = ".")) + 433 | scale_color_manual(values = graphcolors) + 434 | coord_cartesian(ylim = c(-5000, 5000)) #+ 435 | #ggsave(paste0("figures/allrmspe.pdf"), 436 | # width = 15, height = 10, units = 'cm') 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | # Figure 7 445 | # compute ratio of post-reunification RMSPE 446 | # to pre-reunification RMSPE 447 | rmse <- function(x){sqrt(mean(x^2))} 448 | preloss <- apply(storegaps[1:30,],2,rmse) 449 | postloss <- apply(storegaps[31:44,],2,rmse) 450 | prepost <- sort(postloss/preloss) 451 | prepost <- t(t(prepost)) 452 | 453 | prepost <- data.frame(Country = rownames(prepost), RMSPE = prepost) 454 | rownames(prepost) <- NULL 455 | prepost$Country <- factor(prepost$Country, 456 | levels = prepost$Country[order(prepost$RMSPE)]) 457 | 458 | 459 | prepost$west.germany <- ifelse(prepost$Country== "West Germany", "West Germany", "Not West Germany") 460 | 461 | ggplot(prepost, aes(x = Country, y = RMSPE)) + 462 | geom_point(stat = 'identity', size = 6, aes(color = west.germany)) + 463 | theme_bw(base_size = 10) + 464 | coord_flip() + 465 | ylab("Post-Period RMSE / Pre-Period RMSE") + 466 | scale_color_manual(values = graphcolors) + 467 | guides(color = FALSE) #+ 468 | #ggsave(paste0("figures/RMSPERatio.pdf"), 469 | # width = 15, height = 10, units = 'cm') 470 | 471 | 472 | 473 | 474 | 475 | -------------------------------------------------------------------------------- /R/synthetic_control/rep_original.r: -------------------------------------------------------------------------------- 1 | ## Replication Code for 2 | # A. Abadie, A. Diamond, and J. Hainmueller. 2014. 3 | # Comparative Politics and the Synthetic Control Method 4 | # American Journal of Political Science. 5 | 6 | rm(list=ls()) 7 | library(foreign) 8 | library("Synth") 9 | library(xtable) 10 | 11 | # Load Data 12 | d <- read.dta("repgermany.dta") 13 | 14 | ## Table 1 & 2, Figure 1, 2, & 3 15 | 16 | ## pick v by cross-validation 17 | # data setup for training model 18 | dataprep.out <- 19 | dataprep( 20 | foo = d, 21 | predictors = c("gdp","trade","infrate"), 22 | dependent = "gdp", 23 | unit.variable = 1, 24 | time.variable = 3, 25 | special.predictors = list( 26 | list("industry", 1971:1980, c("mean")), 27 | list("schooling",c(1970,1975), c("mean")), 28 | list("invest70" ,1980, c("mean")) 29 | ), 30 | treatment.identifier = 7, 31 | controls.identifier = unique(d$index)[-7], 32 | time.predictors.prior = 1971:1980, 33 | time.optimize.ssr = 1981:1990, 34 | unit.names.variable = 2, 35 | time.plot = 1960:2003 36 | ) 37 | 38 | # fit training model 39 | synth.out <- 40 | synth( 41 | data.prep.obj=dataprep.out, 42 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 43 | ) 44 | 45 | # data prep for main model 46 | dataprep.out <- 47 | dataprep( 48 | foo = d, 49 | predictors = c("gdp","trade","infrate"), 50 | dependent = "gdp", 51 | unit.variable = 1, 52 | time.variable = 3, 53 | special.predictors = list( 54 | list("industry" ,1981:1990, c("mean")), 55 | list("schooling",c(1980,1985), c("mean")), 56 | list("invest80" ,1980, c("mean")) 57 | ), 58 | treatment.identifier = 7, 59 | controls.identifier = unique(d$index)[-7], 60 | time.predictors.prior = 1981:1990, 61 | time.optimize.ssr = 1960:1989, 62 | unit.names.variable = 2, 63 | time.plot = 1960:2003 64 | ) 65 | 66 | # fit main model with v from training model 67 | synth.out <- synth( 68 | data.prep.obj=dataprep.out, 69 | custom.v=as.numeric(synth.out$solution.v) 70 | ) 71 | 72 | #### Table 2 73 | synth.tables <- synth.tab( 74 | dataprep.res = dataprep.out, 75 | synth.res = synth.out 76 | ); synth.tables 77 | 78 | # Replace means for OECD sample (computed externally using proper pop weighting) 79 | synth.tables$tab.pred[,3] <- c(8021.1,31.9,7.4,34.2,44.1,25.9) 80 | colnames(synth.tables$tab.pred)[3] <- "Rest of OECD Sample" 81 | rownames(synth.tables$tab.pred) <- c("GDP per-capita","Trade openness", 82 | "Inflation rate","Industry share", 83 | "Schooling","Investment rate") 84 | 85 | xtable(round(synth.tables$tab.pred,1),digits=1) 86 | 87 | #### Table 1 88 | # synth weights 89 | tab1 <- data.frame(synth.tables$tab.w) 90 | tab1[,1] <- round(tab1[,1],2) 91 | # regression weights 92 | X0 <- cbind(1,t(dataprep.out$X0)) 93 | X1 <- as.matrix(c(1,dataprep.out$X1)) 94 | W <- X0%*%solve(t(X0)%*%X0)%*%X1 95 | Wdat <- data.frame(unit.numbers=as.numeric(rownames(X0)), 96 | regression.w=round(W,2)) 97 | tab1 <- merge(tab1,Wdat,by="unit.numbers") 98 | tab1 <- tab1[order(tab1[,3]),] 99 | 100 | xtable(cbind(tab1[1:9,c(3,2,4)], 101 | tab1[10:18,c(3,2,4)] 102 | ) 103 | ) 104 | 105 | #### Figure 1: Trends in Per-Capita GDP: West Germany vs. Rest of the OECD Sample 106 | Text.height <- 23000 107 | Cex.set <- .8 108 | #pdf(file = "ger_vs_oecd.pdf", width = 5.5, height = 5.5, family = "Times",pointsize = 12) 109 | plot(1960:2003,dataprep.out$Y1plot, 110 | type="l",ylim=c(0,33000),col="black",lty="solid", 111 | ylab ="per-capita GDP (PPP, 2002 USD)", 112 | xlab ="year", 113 | xaxs = "i", yaxs = "i", 114 | lwd=2 115 | ) 116 | lines(1960:2003,aggregate(d[,c("gdp")],by=list(d$year),mean,na.rm=T)[,2] 117 | ,col="black",lty="dashed",lwd=2) # mean 2 118 | abline(v=1990,lty="dotted") 119 | legend(x="bottomright", 120 | legend=c("West Germany","rest of the OECD sample") 121 | ,lty=c("solid","dashed"),col=c("black","black") 122 | ,cex=.8,bg="white",lwd=c(2,2)) 123 | arrows(1987,Text.height,1989,Text.height,col="black",length=.1) 124 | text(1982.5,Text.height,"reunification",cex=Cex.set) 125 | #dev.off() 126 | 127 | #### Figure 2: Trends in Per-Capita GDP: West Germany vs. Synthetic West Germany 128 | #pdf(file = "ger_vs_synthger2.pdf", width = 5.5, height = 5.5, family = "Times",pointsize = 12) 129 | synthY0 <- (dataprep.out$Y0%*%synth.out$solution.w) 130 | plot(1960:2003,dataprep.out$Y1plot, 131 | type="l",ylim=c(0,33000),col="black",lty="solid", 132 | ylab ="per-capita GDP (PPP, 2002 USD)", 133 | xlab ="year", 134 | xaxs = "i", yaxs = "i", 135 | lwd=2 136 | ) 137 | lines(1960:2003,synthY0,col="black",lty="dashed",lwd=2) 138 | abline(v=1990,lty="dotted") 139 | legend(x="bottomright", 140 | legend=c("West Germany","synthetic West Germany") 141 | ,lty=c("solid","dashed"),col=c("black","black") 142 | ,cex=.8,bg="white",lwd=c(2,2)) 143 | arrows(1987,Text.height,1989,Text.height,col="black",length=.1) 144 | text(1982.5,Text.height,"reunification",cex=Cex.set) 145 | #dev.off() 146 | 147 | ### Figure 3: Per-Capita GDP Gap Between West Germany and Synthetic West Germany 148 | #pdf(file = "ger_vs_synthger_gaps2.pdf", width = 5.5, height = 5.5, family = "Times",pointsize = 12) 149 | gap <- dataprep.out$Y1-(dataprep.out$Y0%*%synth.out$solution.w) 150 | plot(1960:2003,gap, 151 | type="l",ylim=c(-4500,4500),col="black",lty="solid", 152 | ylab =c("gap in per-capita GDP (PPP, 2002 USD)"), 153 | xlab ="year", 154 | xaxs = "i", yaxs = "i", 155 | lwd=2 156 | ) 157 | abline(v=1990,lty="dotted") 158 | abline(h=0,lty="dotted") 159 | arrows(1987,1000,1989,1000,col="black",length=.1) 160 | text(1982.5,1000,"reunification",cex=Cex.set) 161 | #dev.off() 162 | 163 | ### Figure 4: Placebo Reunification 1975 - Trends in Per-Capita GDP: West Germany vs. Synthetic West Germany 164 | 165 | # data prep for training model 166 | dataprep.out <- 167 | dataprep( 168 | foo = d, 169 | predictors = c("gdp","trade","infrate"), 170 | dependent = "gdp", 171 | unit.variable = 1, 172 | time.variable = 3, 173 | special.predictors = list( 174 | list("industry",1971, c("mean")), 175 | list("schooling",c(1960,1965), c("mean")), 176 | list("invest60" ,1980, c("mean")) 177 | ), 178 | treatment.identifier = 7, 179 | controls.identifier = unique(d$index)[-7], 180 | time.predictors.prior = 1960:1964, 181 | time.optimize.ssr = 1965:1975, 182 | unit.names.variable = 2, 183 | time.plot = 1960:1990 184 | ) 185 | 186 | # fit training model 187 | synth.out <- synth( 188 | data.prep.obj=dataprep.out, 189 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 190 | ) 191 | 192 | 193 | # data prep for main model 194 | dataprep.out <- 195 | dataprep( 196 | foo = d, 197 | predictors = c("gdp","trade","infrate"), 198 | dependent = "gdp", 199 | unit.variable = 1, 200 | time.variable = 3, 201 | special.predictors = list( 202 | list("industry" ,1971:1975, c("mean")), 203 | list("schooling",c(1970,1975), c("mean")), 204 | list("invest70" ,1980, c("mean")) 205 | ), 206 | treatment.identifier = 7, 207 | controls.identifier = unique(d$index)[-7], 208 | time.predictors.prior = 1965:1975, 209 | time.optimize.ssr = 1960:1975, 210 | unit.names.variable = 2, 211 | time.plot = 1960:1990 212 | ) 213 | 214 | # fit main model 215 | synth.out <- synth( 216 | data.prep.obj=dataprep.out, 217 | custom.v=as.numeric(synth.out$solution.v) 218 | ) 219 | 220 | Cex.set <- 1 221 | #pdf(file = "2intimeplacebo1975.pdf", width = 5.5, height = 5.5, family = "Times",pointsize = 12) 222 | plot(1960:1990,dataprep.out$Y1plot, 223 | type="l",ylim=c(0,33000),col="black",lty="solid", 224 | ylab ="per-capita GDP (PPP, 2002 USD)", 225 | xlab ="year", 226 | xaxs = "i", yaxs = "i", 227 | lwd=2 228 | ) 229 | lines(1960:1990,(dataprep.out$Y0%*%synth.out$solution.w),col="black",lty="dashed",lwd=2) 230 | abline(v=1975,lty="dotted") 231 | legend(x="bottomright", 232 | legend=c("West Germany","synthetic West Germany") 233 | ,lty=c("solid","dashed"),col=c("black","black") 234 | ,cex=.8,bg="white",lwd=c(2,2)) 235 | arrows(1973,20000,1974.5,20000,col="black",length=.1) 236 | text(1967.5,20000,"placebo reunification",cex=Cex.set) 237 | #dev.off() 238 | 239 | 240 | ### Figure 5: Ratio of post-reunification RMSPE to pre-reunification RMSPE: West Germany and control countries. 241 | 242 | # loop across control units 243 | storegaps <- 244 | matrix(NA, 245 | length(1960:2003), 246 | length(unique(d$index))-1 247 | ) 248 | rownames(storegaps) <- 1960:2003 249 | i <- 1 250 | co <- unique(d$index) 251 | 252 | for(k in unique(d$index)[-7]){ 253 | 254 | # data prep for training model 255 | dataprep.out <- 256 | dataprep( 257 | foo = d, 258 | predictors = c("gdp","trade","infrate"), 259 | dependent = "gdp", 260 | unit.variable = 1, 261 | time.variable = 3, 262 | special.predictors = list( 263 | list("industry",1971:1980, c("mean")), 264 | list("schooling" ,c(1970,1975), c("mean")), 265 | list("invest70" ,1980, c("mean")) 266 | ), 267 | treatment.identifier = k, 268 | controls.identifier = co[-which(co==k)], 269 | time.predictors.prior = 1971:1980, 270 | time.optimize.ssr = 1981:1990, 271 | unit.names.variable = 2, 272 | time.plot = 1960:2003 273 | ) 274 | 275 | # fit training model 276 | synth.out <- 277 | synth( 278 | data.prep.obj=dataprep.out, 279 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 280 | ) 281 | 282 | # data prep for main model 283 | dataprep.out <- 284 | dataprep( 285 | foo = d, 286 | predictors = c("gdp","trade","infrate"), 287 | dependent = "gdp", 288 | unit.variable = 1, 289 | time.variable = 3, 290 | special.predictors = list( 291 | list("industry" ,1981:1990, c("mean")), 292 | list("schooling",c(1980,1985), c("mean")), 293 | list("invest80" ,1980, c("mean")) 294 | ), 295 | treatment.identifier = k, 296 | controls.identifier = co[-which(co==k)], 297 | time.predictors.prior = 1981:1990, 298 | time.optimize.ssr = 1960:1989, 299 | unit.names.variable = 2, 300 | time.plot = 1960:2003 301 | ) 302 | 303 | # fit main model 304 | synth.out <- synth( 305 | data.prep.obj=dataprep.out, 306 | custom.v=as.numeric(synth.out$solution.v) 307 | ) 308 | 309 | storegaps[,i] <- 310 | dataprep.out$Y1- 311 | (dataprep.out$Y0%*%synth.out$solution.w) 312 | i <- i + 1 313 | } # close loop over control units 314 | d <- d[order(d$index,d$year),] 315 | colnames(storegaps) <- unique(d$country)[-7] 316 | storegaps <- cbind(gap,storegaps) 317 | colnames(storegaps)[1] <- c("West Germany") 318 | 319 | # compute ratio of post-reunification RMSPE 320 | # to pre-reunification RMSPE 321 | rmse <- function(x){sqrt(mean(x^2))} 322 | preloss <- apply(storegaps[1:30,],2,rmse) 323 | postloss <- apply(storegaps[31:44,],2,rmse) 324 | 325 | #pdf("2ratio_post_to_preperiod_rmse2a.pdf") 326 | dotchart(sort(postloss/preloss), 327 | xlab="Post-Period RMSE / Pre-Period RMSE", 328 | pch=19) 329 | #dev.off() 330 | 331 | ### Figure 6: Leave-one-out distribution of the synthetic control for West Germany 332 | 333 | # loop over leave one outs 334 | storegaps <- 335 | matrix(NA, 336 | length(1960:2003), 337 | 5) 338 | colnames(storegaps) <- c(1,3,9,12,14) 339 | co <- unique(d$index)[-7] 340 | 341 | for(k in 1:5){ 342 | 343 | # data prep for training model 344 | omit <- c(1,3,9,12,14)[k] 345 | dataprep.out <- 346 | dataprep( 347 | foo = d, 348 | predictors = c("gdp","trade","infrate"), 349 | dependent = "gdp", 350 | unit.variable = 1, 351 | time.variable = 3, 352 | special.predictors = list( 353 | list("industry",1971:1980, c("mean")), 354 | list("schooling" ,c(1970,1975), c("mean")), 355 | list("invest70" ,1980, c("mean")) 356 | ), 357 | treatment.identifier = 7, 358 | controls.identifier = co[-which(co==omit)], 359 | time.predictors.prior = 1971:1980, 360 | time.optimize.ssr = 1981:1990, 361 | unit.names.variable = 2, 362 | time.plot = 1960:2003 363 | ) 364 | 365 | # fit training model 366 | synth.out <- synth( 367 | data.prep.obj=dataprep.out, 368 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 369 | ) 370 | 371 | # data prep for main model 372 | dataprep.out <- 373 | dataprep( 374 | foo = d, 375 | predictors = c("gdp","trade","infrate"), 376 | dependent = "gdp", 377 | unit.variable = 1, 378 | time.variable = 3, 379 | special.predictors = list( 380 | list("industry" ,1981:1990, c("mean")), 381 | list("schooling",c(1980,1985), c("mean")), 382 | list("invest80" ,1980, c("mean")) 383 | ), 384 | treatment.identifier = 7, 385 | controls.identifier = co[-which(co==omit)], 386 | time.predictors.prior = 1981:1990, 387 | time.optimize.ssr = 1960:1989, 388 | unit.names.variable = 2, 389 | time.plot = 1960:2003 390 | ) 391 | 392 | # fit main model 393 | synth.out <- synth( 394 | data.prep.obj=dataprep.out, 395 | custom.v=as.numeric(synth.out$solution.v) 396 | ) 397 | storegaps[,k] <- (dataprep.out$Y0%*%synth.out$solution.w) 398 | } # close loop over leave one outs 399 | 400 | Text.height <- 23000 401 | Cex.set <- .8 402 | #pdf(file = "1jackknife2.pdf", width = 5.5, height = 5.5, family = "Times",pointsize = 12) 403 | plot(1960:2003,dataprep.out$Y1plot, 404 | type="l",ylim=c(0,33000),col="black",lty="solid", 405 | ylab ="per-capita GDP (PPP, 2002 USD)", 406 | xlab ="year", 407 | xaxs = "i", yaxs = "i",lwd=2 408 | ) 409 | 410 | abline(v=1990,lty="dotted") 411 | arrows(1987,23000,1989,23000,col="black",length=.1) 412 | for(i in 1:5){ 413 | lines(1960:2003,storegaps[,i],col="darkgrey",lty="solid") 414 | } 415 | lines(1960:2003,synthY0,col="black",lty="dashed",lwd=2) 416 | lines(1960:2003,dataprep.out$Y1plot,col="black",lty="solid",lwd=2) 417 | text(1982.5,23000,"reunification",cex=.8) 418 | legend(x="bottomright", 419 | legend=c("West Germany", 420 | "synthetic West Germany", 421 | "synthetic West Germany (leave-one-out)") 422 | ,lty=c("solid","dashed","solid"), 423 | col=c("black","black","darkgrey") 424 | ,cex=.8,bg="white",lwdc(2,2,1)) 425 | #dev.off() 426 | 427 | 428 | ### Table 3: Synthetic Weights from Combinations of Control Countries 429 | rm(list=ls()) 430 | library(gtools) 431 | library(kernlab) 432 | 433 | # data prep for training model 434 | d <- read.dta("repgermany.dta") 435 | dataprep.out <- 436 | dataprep( 437 | foo = d, 438 | predictors = c("gdp","trade","infrate"), 439 | dependent = "gdp", 440 | unit.variable = 1, 441 | time.variable = 3, 442 | special.predictors = list( 443 | list("industry", 1971:1980, c("mean")), 444 | list("schooling",c(1970,1975), c("mean")), 445 | list("invest70" ,1980, c("mean")) 446 | ), 447 | treatment.identifier = 7, 448 | controls.identifier = unique(d$index)[-7], 449 | time.predictors.prior = 1971:1980, 450 | time.optimize.ssr = 1981:1990, 451 | unit.names.variable = 2, 452 | time.plot = 1960:2003 453 | ) 454 | 455 | # fit training model 456 | synth.out <- 457 | synth( 458 | data.prep.obj=dataprep.out, 459 | Margin.ipop=.005,Sigf.ipop=7,Bound.ipop=6 460 | ) 461 | 462 | # data prep for main model 463 | dataprep.out <- 464 | dataprep( 465 | foo = d, 466 | predictors = c("gdp","trade","infrate"), 467 | dependent = "gdp", 468 | unit.variable = 1, 469 | time.variable = 3, 470 | special.predictors = list( 471 | list("industry" ,1981:1990, c("mean")), 472 | list("schooling",c(1980,1985), c("mean")), 473 | list("invest80" ,1980, c("mean")) 474 | ), 475 | treatment.identifier = 7, 476 | controls.identifier = unique(d$index)[-7], 477 | time.predictors.prior = 1981:1990, 478 | time.optimize.ssr = 1960:1989, 479 | unit.names.variable = 2, 480 | time.plot = 1960:2003 481 | ) 482 | 483 | # fit main model with v from training model 484 | synth.out <- synth( 485 | data.prep.obj=dataprep.out, 486 | custom.v=as.numeric(synth.out$solution.v) 487 | ) 488 | 489 | synth.tables <- synth.tab( 490 | dataprep.res = dataprep.out, 491 | synth.res = synth.out 492 | ) 493 | 494 | table3 <- list() 495 | synth.tables$tab.w[,1] <- round(synth.tables$tab.w[,1],2) 496 | table3[[5]] <-synth.tables$tab.w[order(-1*synth.tables$tab.w[,1]),2:1][1:5,] 497 | 498 | # compute loss for all combinations 499 | # of 4, 3, 2, 1 sized donor pools 500 | 501 | # get W and v 502 | solution.w <- round(synth.out$solution.w,3) 503 | V <- diag(as.numeric(synth.out$solution.v)) 504 | 505 | # compute scaled Xs 506 | nvarsV <- dim(dataprep.out$X0)[1] 507 | big.dataframe <- cbind(dataprep.out$X0, dataprep.out$X1) 508 | divisor <- sqrt(apply(big.dataframe, 1, var)) 509 | scaled.matrix <- 510 | t(t(big.dataframe) %*% ( 1/(divisor) * 511 | diag(rep(dim(big.dataframe)[1], 1)) )) 512 | X0.scaled <- scaled.matrix[,c(1:(dim(dataprep.out$X0)[2]))] 513 | X1.scaled <- as.matrix(scaled.matrix[,dim(scaled.matrix)[2]]) 514 | 515 | dn <- d[d$year==1970,c("country","index")] 516 | dn <- dn[order(dn$index),] 517 | dn <- dn[-7,] 518 | 519 | table2store <- matrix(NA,nrow(dataprep.out$X1),4) 520 | fig7store <- matrix(NA,length(1960:2003),4) 521 | 522 | # loop through number of controls 523 | for(pp in 4:1){ 524 | store <- combinations(length(unique(d$index)[-7]), 525 | r=pp, v=unique(d$index)[-7]) 526 | store.loss <- matrix(NA,nrow=nrow(store),1) 527 | store.w <- matrix(NA,nrow=nrow(store),pp) 528 | store.c <- store.w 529 | 530 | # loop through combinations 531 | for(k in 1:nrow(store)){ 532 | # index positions of control units 533 | posvector <- c() 534 | for(i in 1:pp){ 535 | posvector <- c(posvector,which(dn$index==store[k,i])) 536 | } 537 | 538 | # run quad optimization 539 | X0temp <- X0.scaled[ , posvector ] 540 | H <- t(X0temp) %*% V %*% (X0temp) 541 | c <- -1*c(t(X1.scaled) %*% V %*% (X0temp) ) 542 | 543 | if(pp == 1){ 544 | solution.w <- matrix(1) 545 | } else { 546 | res <- ipop(c = c, H = H, A = t(rep(1, length(c))), 547 | b = 1, l = rep(0, length(c)), 548 | u = rep(1, length(c)), r = 0, 549 | margin = 0.005,sigf = 7, bound = 6) 550 | solution.w <- as.matrix(primal(res)) 551 | } 552 | loss.w <- t(X1.scaled - X0temp %*% solution.w) %*% V %*% (X1.scaled - X0temp %*% solution.w) 553 | 554 | store.loss[k] <- loss.w 555 | store.w[k,] <- t(solution.w) 556 | store.c[k,] <- dn$country[posvector] 557 | } # close loop over combinations 558 | 559 | # get best fitting combination 560 | dat <- data.frame(store.loss, 561 | store, 562 | store.c, 563 | store.w 564 | ) 565 | colnames(dat) <- c("loss", 566 | paste("CNo",1:pp,sep=""), 567 | paste("CNa",1:pp,sep=""), 568 | paste("W",1:pp,sep="") 569 | ) 570 | dat <- dat[order(dat$loss),] 571 | Countries <- dat[1,paste("CNo",1:pp,sep="")] 572 | Cweights <- as.numeric(dat[1,paste("W",1:pp,sep="")]) 573 | 574 | outdat <- data.frame(unit.names=as.vector( 575 | (t(as.vector(dat[1,paste("CNa",1:pp,sep="")])))), 576 | w.weights=round(Cweights,2)) 577 | 578 | table3[[pp]]<- outdat[order(-1*outdat$w.weights),] 579 | 580 | # get posvector for fitting 581 | posvector <- c() 582 | if(pp == 1 ){ 583 | posvector <- c(posvector,which(dn$index==Countries)) 584 | } else { 585 | for(i in 1:pp){ 586 | posvector <- c(posvector,which(dn$index==Countries[1,i])) 587 | } 588 | } 589 | 590 | X0t <- as.matrix(dataprep.out$X0[,posvector])%*% as.matrix(Cweights) 591 | table2store[,(4:1)[pp]] <- X0t 592 | 593 | fig7store[,(4:1)[pp]] <- 594 | dataprep.out$Y0[,posvector]%*%as.matrix(Cweights) 595 | 596 | } # close loop over number of countries 597 | 598 | # Table 3 599 | table3 600 | 601 | # Table 4 602 | synth.tables$tab.pred[,3] <- c(8021.1,31.9,7.4,34.2,44.1,25.9) 603 | table4 <- round( 604 | cbind(synth.tables$tab.pred[,1:2], 605 | table2store, 606 | synth.tables$tab.pred[,3]),1) 607 | rownames(table4) <- c("GDP per-capita","Trade openness", 608 | "Inflation rate","Industry share", 609 | "Schooling","Investment rate") 610 | colnames(table4)[2:7] <- c(5:1,"OECD Sample") 611 | table4 612 | 613 | ## Figure 7: Per-Capita GDP Gaps Between West Germany and Sparse Synthetic Controls 614 | Text.height <- 23000 615 | Cex.set <- .8 616 | 617 | par(mfrow=c(2,2)) 618 | for(pp in 4:1){ 619 | #pdf(file = paste("2ger_vs_synth","CValt",pp,".pdf",sep=""), width = 5.5, height = 5.5, family = "Times",pointsize = 12) 620 | plot(1960:2003,dataprep.out$Y1, 621 | type="l",ylim=c(0,33000),col="black",lty="solid", 622 | ylab ="per-capita GDP (PPP, 2002 USD)", 623 | xlab ="year", 624 | xaxs = "i", yaxs = "i", 625 | lwd=2, 626 | main=paste("No. of control countries: ",pp,sep="") 627 | ) 628 | lines(1960:2003,fig7store[,c(4:1)[pp]],col="black",lty="dashed",lwd=2) 629 | abline(v=1990,lty="dotted") 630 | legend(x="bottomright", 631 | legend=c("West Germany","synthetic West Germany") 632 | ,lty=c("solid","dashed"),col=c("black","black") 633 | ,cex=.8,bg="white",lwd=c(2,2)) 634 | arrows(1987,Text.height,1989,Text.height,col="black",length=.1) 635 | text(1982.5,Text.height,"reunification",cex=Cex.set) 636 | #dev.off() 637 | } 638 | 639 | 640 | 641 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Build](https://github.com/juanitorduz/btsa/workflows/Docker%20Build/badge.svg) 2 | 3 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/juanitorduz/btsa/master) 4 | [![Open in Visual Studio Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://open.vscode.dev/juanitorduz/btsa) 5 | 6 | [![GitHub stars](https://img.shields.io/github/stars/juanitorduz/btsa.svg)](https://github.com/juanitorduz/btsa/stargazers) 7 | [![GitHub forks](https://img.shields.io/github/forks/juanitorduz/btsa.svg?color=blue)](https://github.com/juanitorduz/btsa/network) 8 | 9 | [![Visits Badge](https://badges.pufler.dev/visits/juanitorduz/btsa)](https://badges.pufler.dev/visits/juanitorduz/btsa) 10 | [![Contributors](https://img.shields.io/github/contributors/juanitorduz/btsa)](https://img.shields.io/github/contributors/juanitorduz/btsa) 11 | 12 | # Berlin Time Series Analysis (BTSA) Repository 13 | 14 |

15 | code 16 |

17 | 18 | This repository contains resources of the *Berlin Time Series Analysis* [Meetup](https://www.meetup.com/Berlin-Time-Series-Analysis-Meetup/). We encourage everyone to [contribute to this repository](https://github.com/juanitorduz/btsa/blob/master/CONTRIBUTING.md)! [Here](https://github.com/juanitorduz/btsa/blob/master/meetup.md) you can find the schedule and details of the meetup. 19 | 20 | 21 | 22 | **contact:** [berlin.timeseries.analysis@gmail.com](berlin.timeseries.analysis@gmail.com) 23 | 24 | You can also visit us on [Medium](https://btsa.medium.com/). 25 | 26 | --- 27 | ## Code of Conduct 28 | **Important:** Make sure you read the [Code of Conduct](https://github.com/juanitorduz/btsa/blob/master/code_of_conduct.md). 29 | 30 | --- 31 | ## Resources 32 | 33 | You can find a list of references on the [resources](https://github.com/juanitorduz/btsa/blob/master/resources.md) section (which we will continuously update). 34 | 35 | --- 36 | ## Environment 37 | 38 | As we want to make the code reproducible, here are some options to manage dependencies (choose R or Python as preferred): 39 | 40 | ### Conda Environment (Python) 41 | 42 | - [Create conda environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) (you can also update the environment from as described [here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#updating-an-environment)): 43 | 44 | `conda env create -f environment.yml` 45 | 46 | - Activate conda environment: 47 | 48 | `conda activate btsa` 49 | 50 | - Run [Jupyter Lab](https://jupyterlab.readthedocs.io/en/stable/index.html#): 51 | 52 | `jupyter lab` 53 | 54 | --- 55 | ### Docker (see [jupyter-docker-stacks](https://jupyter-docker-stacks.readthedocs.io/en/latest/)) 56 | 57 | - Build Docker image: 58 | 59 | `docker build -t docker-btsa .` 60 | 61 | - Run container 62 | 63 | `docker run -p 10000:8888 docker-btsa` 64 | 65 | > Visiting `http://:10000/?token=` in a browser loads the Jupyter Notebook dashboard page, where `hostname` is the name of the computer running docker and `token` is the secret token printed in the console. 66 | 67 | You can find the `python` folder under the `work` directory. 68 | 69 | --- 70 | ### [R](https://www.r-project.org/) [Environment](https://rstudio.github.io/renv/articles/renv.html) 71 | 72 | - From the root (`btsa`) directory, with R installed, run the following command: `Rscript renv/activate.R`. 73 | 74 | This command will activate the environment and the [renv package manager](https://github.com/rstudio/renv/). From there you have two options depending on how you like to edit your projects. 75 | 76 | *Note: This configuration has been tested on R version 3.6.3.* 77 | 78 | #### Option 1. Command Line: 79 | From the root directory type R and hit enter. Then type `renv::restore()` and respond with 'y' when prompted to install the packages. Your environment is now set up. You can continue writing commands or quit the console, your folder is now set up with the required packages. 80 | 81 | #### Option 2: From [RStudio](https://rstudio.com/) 82 | Open an Rstudio session. Go to `RStudio > 'Open Project in New Session'`. Navigate to the btsa folder and click open. 83 | In the console, type `renv::restore()` to install the necessary packages. Your RStudio session is now configured. 84 | -------------------------------------------------------------------------------- /code_of_conduct.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## What we Expect: 4 | 5 | - Active participation. We are all here to learn and share knowledge. 6 | - A safe space to ask questions without being judged. 7 | - Avoid "I-know-it-all" attitude. 8 | - Exercise consideration and respect in your speech and actions. 9 | - Attempt collaboration before conflict. 10 | - Use inclusive language. 11 | - Refrain from demeaning, discriminatory, or harassing behavior and speech (see **Unacceptable Behavior** below). 12 | - Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this **Code of Conduct**, even if they seem inconsequential. 13 | 14 | ## Unacceptable Behavior: 15 | 16 | Unacceptable behaviors include, but is not limited to: 17 | 18 | - Abusive, racist, discriminatory, derogatory or demeaning speech or actions. 19 | - Sexual images in public spaces (or sharing it online). 20 | - Harassing, intimidation, stalking, or following. 21 | - Sustained disruption of talks or other events. 22 | - Inappropriate physical contact. 23 | - Invasion of personal space. 24 | - Unwelcome sexual attention. 25 | - Advocating for, or encouraging, any of the above behavior. 26 | 27 | ## Consequences of Unacceptable Behavior 28 | 29 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 30 | 31 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 32 | 33 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 34 | 35 | ## If You Witness or Are Subject to Unacceptable Behavior 36 | 37 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. 38 | 39 | You can make a personal report by contacting any member of the organizers. 40 | 41 | When taking a personal report, our staff will ensure you are safe and cannot be overheard. They may involve other event staff to ensure your report is managed properly. 42 | 43 | Once safe, we’ll ask you to tell us about what happened. This can be upsetting, but we’ll handle it as respectfully as possible, and you can bring someone to support you. You won’t be asked to confront anyone and we won’t tell anyone who you are. 44 | 45 | ## Addressing Grievances: 46 | 47 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify one of the event organizers with a concise description of your grievance. 48 | 49 | Your grievance will be handled in accordance with our existing governing policies. 50 | 51 | # Credits 52 | This Code of Conduct was taken from [PyBerlin](https://pyberlin.github.io/coc.html) (See also [https://berlincodeofconduct.org/](https://berlincodeofconduct.org/)) -------------------------------------------------------------------------------- /data/beer.csv: -------------------------------------------------------------------------------- 1 | Month,Monthly beer production 2 | 1956-01,93.2 3 | 1956-02,96 4 | 1956-03,95.2 5 | 1956-04,77.1 6 | 1956-05,70.9 7 | 1956-06,64.8 8 | 1956-07,70.1 9 | 1956-08,77.3 10 | 1956-09,79.5 11 | 1956-10,100.6 12 | 1956-11,100.7 13 | 1956-12,107.1 14 | 1957-01,95.9 15 | 1957-02,82.8 16 | 1957-03,83.3 17 | 1957-04,80 18 | 1957-05,80.4 19 | 1957-06,67.5 20 | 1957-07,75.7 21 | 1957-08,71.1 22 | 1957-09,89.3 23 | 1957-10,101.1 24 | 1957-11,105.2 25 | 1957-12,114.1 26 | 1958-01,96.3 27 | 1958-02,84.4 28 | 1958-03,91.2 29 | 1958-04,81.9 30 | 1958-05,80.5 31 | 1958-06,70.4 32 | 1958-07,74.8 33 | 1958-08,75.9 34 | 1958-09,86.3 35 | 1958-10,98.7 36 | 1958-11,100.9 37 | 1958-12,113.8 38 | 1959-01,89.8 39 | 1959-02,84.4 40 | 1959-03,87.2 41 | 1959-04,85.6 42 | 1959-05,72 43 | 1959-06,69.2 44 | 1959-07,77.5 45 | 1959-08,78.1 46 | 1959-09,94.3 47 | 1959-10,97.7 48 | 1959-11,100.2 49 | 1959-12,116.4 50 | 1960-01,97.1 51 | 1960-02,93 52 | 1960-03,96 53 | 1960-04,80.5 54 | 1960-05,76.1 55 | 1960-06,69.9 56 | 1960-07,73.6 57 | 1960-08,92.6 58 | 1960-09,94.2 59 | 1960-10,93.5 60 | 1960-11,108.5 61 | 1960-12,109.4 62 | 1961-01,105.1 63 | 1961-02,92.5 64 | 1961-03,97.1 65 | 1961-04,81.4 66 | 1961-05,79.1 67 | 1961-06,72.1 68 | 1961-07,78.7 69 | 1961-08,87.1 70 | 1961-09,91.4 71 | 1961-10,109.9 72 | 1961-11,116.3 73 | 1961-12,113 74 | 1962-01,100 75 | 1962-02,84.8 76 | 1962-03,94.3 77 | 1962-04,87.1 78 | 1962-05,90.3 79 | 1962-06,72.4 80 | 1962-07,84.9 81 | 1962-08,92.7 82 | 1962-09,92.2 83 | 1962-10,114.9 84 | 1962-11,112.5 85 | 1962-12,118.3 86 | 1963-01,106 87 | 1963-02,91.2 88 | 1963-03,96.6 89 | 1963-04,96.3 90 | 1963-05,88.2 91 | 1963-06,70.2 92 | 1963-07,86.5 93 | 1963-08,88.2 94 | 1963-09,102.8 95 | 1963-10,119.1 96 | 1963-11,119.2 97 | 1963-12,125.1 98 | 1964-01,106.1 99 | 1964-02,102.1 100 | 1964-03,105.2 101 | 1964-04,101 102 | 1964-05,84.3 103 | 1964-06,87.5 104 | 1964-07,92.7 105 | 1964-08,94.4 106 | 1964-09,113 107 | 1964-10,113.9 108 | 1964-11,122.9 109 | 1964-12,132.7 110 | 1965-01,106.9 111 | 1965-02,96.6 112 | 1965-03,127.3 113 | 1965-04,98.2 114 | 1965-05,100.2 115 | 1965-06,89.4 116 | 1965-07,95.3 117 | 1965-08,104.2 118 | 1965-09,106.4 119 | 1965-10,116.2 120 | 1965-11,135.9 121 | 1965-12,134 122 | 1966-01,104.6 123 | 1966-02,107.1 124 | 1966-03,123.5 125 | 1966-04,98.8 126 | 1966-05,98.6 127 | 1966-06,90.6 128 | 1966-07,89.1 129 | 1966-08,105.2 130 | 1966-09,114 131 | 1966-10,122.1 132 | 1966-11,138 133 | 1966-12,142.2 134 | 1967-01,116.4 135 | 1967-02,112.6 136 | 1967-03,123.8 137 | 1967-04,103.6 138 | 1967-05,113.9 139 | 1967-06,98.6 140 | 1967-07,95 141 | 1967-08,116 142 | 1967-09,113.9 143 | 1967-10,127.5 144 | 1967-11,131.4 145 | 1967-12,145.9 146 | 1968-01,131.5 147 | 1968-02,131 148 | 1968-03,130.5 149 | 1968-04,118.9 150 | 1968-05,114.3 151 | 1968-06,85.7 152 | 1968-07,104.6 153 | 1968-08,105.1 154 | 1968-09,117.3 155 | 1968-10,142.5 156 | 1968-11,140 157 | 1968-12,159.8 158 | 1969-01,131.2 159 | 1969-02,125.4 160 | 1969-03,126.5 161 | 1969-04,119.4 162 | 1969-05,113.5 163 | 1969-06,98.7 164 | 1969-07,114.5 165 | 1969-08,113.8 166 | 1969-09,133.1 167 | 1969-10,143.4 168 | 1969-11,137.3 169 | 1969-12,165.2 170 | 1970-01,126.9 171 | 1970-02,124 172 | 1970-03,135.7 173 | 1970-04,130 174 | 1970-05,109.4 175 | 1970-06,117.8 176 | 1970-07,120.3 177 | 1970-08,121 178 | 1970-09,132.3 179 | 1970-10,142.9 180 | 1970-11,147.4 181 | 1970-12,175.9 182 | 1971-01,132.6 183 | 1971-02,123.7 184 | 1971-03,153.3 185 | 1971-04,134 186 | 1971-05,119.6 187 | 1971-06,116.2 188 | 1971-07,118.6 189 | 1971-08,130.7 190 | 1971-09,129.3 191 | 1971-10,144.4 192 | 1971-11,163.2 193 | 1971-12,179.4 194 | 1972-01,128.1 195 | 1972-02,138.4 196 | 1972-03,152.7 197 | 1972-04,120 198 | 1972-05,140.5 199 | 1972-06,116.2 200 | 1972-07,121.4 201 | 1972-08,127.8 202 | 1972-09,143.6 203 | 1972-10,157.6 204 | 1972-11,166.2 205 | 1972-12,182.3 206 | 1973-01,153.1 207 | 1973-02,147.6 208 | 1973-03,157.7 209 | 1973-04,137.2 210 | 1973-05,151.5 211 | 1973-06,98.7 212 | 1973-07,145.8 213 | 1973-08,151.7 214 | 1973-09,129.4 215 | 1973-10,174.1 216 | 1973-11,197 217 | 1973-12,193.9 218 | 1974-01,164.1 219 | 1974-02,142.8 220 | 1974-03,157.9 221 | 1974-04,159.2 222 | 1974-05,162.2 223 | 1974-06,123.1 224 | 1974-07,130 225 | 1974-08,150.1 226 | 1974-09,169.4 227 | 1974-10,179.7 228 | 1974-11,182.1 229 | 1974-12,194.3 230 | 1975-01,161.4 231 | 1975-02,169.4 232 | 1975-03,168.8 233 | 1975-04,158.1 234 | 1975-05,158.5 235 | 1975-06,135.3 236 | 1975-07,149.3 237 | 1975-08,143.4 238 | 1975-09,142.2 239 | 1975-10,188.4 240 | 1975-11,166.2 241 | 1975-12,199.2 242 | 1976-01,182.7 243 | 1976-02,145.2 244 | 1976-03,182.1 245 | 1976-04,158.7 246 | 1976-05,141.6 247 | 1976-06,132.6 248 | 1976-07,139.6 249 | 1976-08,147 250 | 1976-09,166.6 251 | 1976-10,157 252 | 1976-11,180.4 253 | 1976-12,210.2 254 | 1977-01,159.8 255 | 1977-02,157.8 256 | 1977-03,168.2 257 | 1977-04,158.4 258 | 1977-05,152 259 | 1977-06,142.2 260 | 1977-07,137.2 261 | 1977-08,152.6 262 | 1977-09,166.8 263 | 1977-10,165.6 264 | 1977-11,198.6 265 | 1977-12,201.5 266 | 1978-01,170.7 267 | 1978-02,164.4 268 | 1978-03,179.7 269 | 1978-04,157 270 | 1978-05,168 271 | 1978-06,139.3 272 | 1978-07,138.6 273 | 1978-08,153.4 274 | 1978-09,138.9 275 | 1978-10,172.1 276 | 1978-11,198.4 277 | 1978-12,217.8 278 | 1979-01,173.7 279 | 1979-02,153.8 280 | 1979-03,175.6 281 | 1979-04,147.1 282 | 1979-05,160.3 283 | 1979-06,135.2 284 | 1979-07,148.8 285 | 1979-08,151 286 | 1979-09,148.2 287 | 1979-10,182.2 288 | 1979-11,189.2 289 | 1979-12,183.1 290 | 1980-01,170 291 | 1980-02,158.4 292 | 1980-03,176.1 293 | 1980-04,156.2 294 | 1980-05,153.2 295 | 1980-06,117.9 296 | 1980-07,149.8 297 | 1980-08,156.6 298 | 1980-09,166.7 299 | 1980-10,156.8 300 | 1980-11,158.6 301 | 1980-12,210.8 302 | 1981-01,203.6 303 | 1981-02,175.2 304 | 1981-03,168.7 305 | 1981-04,155.9 306 | 1981-05,147.3 307 | 1981-06,137 308 | 1981-07,141.1 309 | 1981-08,167.4 310 | 1981-09,160.2 311 | 1981-10,191.9 312 | 1981-11,174.4 313 | 1981-12,208.2 314 | 1982-01,159.4 315 | 1982-02,161.1 316 | 1982-03,172.1 317 | 1982-04,158.4 318 | 1982-05,114.6 319 | 1982-06,159.6 320 | 1982-07,159.7 321 | 1982-08,159.4 322 | 1982-09,160.7 323 | 1982-10,165.5 324 | 1982-11,205 325 | 1982-12,205.2 326 | 1983-01,141.6 327 | 1983-02,148.1 328 | 1983-03,184.9 329 | 1983-04,132.5 330 | 1983-05,137.3 331 | 1983-06,135.5 332 | 1983-07,121.7 333 | 1983-08,166.1 334 | 1983-09,146.8 335 | 1983-10,162.8 336 | 1983-11,186.8 337 | 1983-12,185.5 338 | 1984-01,151.5 339 | 1984-02,158.1 340 | 1984-03,143 341 | 1984-04,151.2 342 | 1984-05,147.6 343 | 1984-06,130.7 344 | 1984-07,137.5 345 | 1984-08,146.1 346 | 1984-09,133.6 347 | 1984-10,167.9 348 | 1984-11,181.9 349 | 1984-12,202 350 | 1985-01,166.5 351 | 1985-02,151.3 352 | 1985-03,146.2 353 | 1985-04,148.3 354 | 1985-05,144.7 355 | 1985-06,123.6 356 | 1985-07,151.6 357 | 1985-08,133.9 358 | 1985-09,137.4 359 | 1985-10,181.6 360 | 1985-11,182 361 | 1985-12,190 362 | 1986-01,161.2 363 | 1986-02,155.5 364 | 1986-03,141.9 365 | 1986-04,164.6 366 | 1986-05,136.2 367 | 1986-06,126.8 368 | 1986-07,152.5 369 | 1986-08,126.6 370 | 1986-09,150.1 371 | 1986-10,186.3 372 | 1986-11,147.5 373 | 1986-12,200.4 374 | 1987-01,177.2 375 | 1987-02,127.4 376 | 1987-03,177.1 377 | 1987-04,154.4 378 | 1987-05,135.2 379 | 1987-06,126.4 380 | 1987-07,147.3 381 | 1987-08,140.6 382 | 1987-09,152.3 383 | 1987-10,151.2 384 | 1987-11,172.2 385 | 1987-12,215.3 386 | 1988-01,154.1 387 | 1988-02,159.3 388 | 1988-03,160.4 389 | 1988-04,151.9 390 | 1988-05,148.4 391 | 1988-06,139.6 392 | 1988-07,148.2 393 | 1988-08,153.5 394 | 1988-09,145.1 395 | 1988-10,183.7 396 | 1988-11,210.5 397 | 1988-12,203.3 398 | 1989-01,153.3 399 | 1989-02,144.3 400 | 1989-03,169.6 401 | 1989-04,143.7 402 | 1989-05,160.1 403 | 1989-06,135.6 404 | 1989-07,141.8 405 | 1989-08,159.9 406 | 1989-09,145.7 407 | 1989-10,183.5 408 | 1989-11,198.2 409 | 1989-12,186.8 410 | 1990-01,172 411 | 1990-02,150.6 412 | 1990-03,163.3 413 | 1990-04,153.7 414 | 1990-05,152.9 415 | 1990-06,135.5 416 | 1990-07,148.5 417 | 1990-08,148.4 418 | 1990-09,133.6 419 | 1990-10,194.1 420 | 1990-11,208.6 421 | 1990-12,197.3 422 | 1991-01,164.4 423 | 1991-02,148.1 424 | 1991-03,152 425 | 1991-04,144.1 426 | 1991-05,155 427 | 1991-06,124.5 428 | 1991-07,153 429 | 1991-08,146 430 | 1991-09,138 431 | 1991-10,190 432 | 1991-11,192 433 | 1991-12,192 434 | 1992-01,147 435 | 1992-02,133 436 | 1992-03,163 437 | 1992-04,150 438 | 1992-05,129 439 | 1992-06,131 440 | 1992-07,145 441 | 1992-08,137 442 | 1992-09,138 443 | 1992-10,168 444 | 1992-11,176 445 | 1992-12,188 446 | 1993-01,139 447 | 1993-02,143 448 | 1993-03,150 449 | 1993-04,154 450 | 1993-05,137 451 | 1993-06,129 452 | 1993-07,128 453 | 1993-08,140 454 | 1993-09,143 455 | 1993-10,151 456 | 1993-11,177 457 | 1993-12,184 458 | 1994-01,151 459 | 1994-02,134 460 | 1994-03,164 461 | 1994-04,126 462 | 1994-05,131 463 | 1994-06,125 464 | 1994-07,127 465 | 1994-08,143 466 | 1994-09,143 467 | 1994-10,160 468 | 1994-11,190 469 | 1994-12,182 470 | 1995-01,138 471 | 1995-02,136 472 | 1995-03,152 473 | 1995-04,127 474 | 1995-05,151 475 | 1995-06,130 476 | 1995-07,119 477 | 1995-08,153 478 | -------------------------------------------------------------------------------- /data/intro_ets.csv: -------------------------------------------------------------------------------- 1 | t1,t2,t3,t4 2 | 1.1649265129642203,0.0,0.3152277408388273,1.1649265129642203 3 | 1.886935602798544,0.04,1.3394027610068524,1.1765757780938626 4 | 1.9969796393030448,0.08,1.2505888832010117,1.1883415358748013 5 | 1.3151150892685353,0.12,2.13270156090128,1.2002249512335492 6 | 1.8173578608814835,0.16,2.792829124245662,1.2122272007458847 7 | 1.0866756288197803,0.2,3.060580509334904,1.2243494727533435 8 | 1.008921250461824,0.24,3.289433575887004,1.2365929674808769 9 | -0.978920019599814,0.28,2.2148723553158485,1.2489588971556858 10 | -0.2348804804813299,0.32,3.5394900058696184,1.2614484861272426 11 | -0.8059811872433403,0.36,1.7881448567738238,1.274062970988515 12 | 1.6516519054043142,0.4,-0.2746785942386538,1.2868036006983998 13 | 1.1106020122724063,0.44,1.3602827756806073,1.2996716367053842 14 | 1.6636155172801734,0.48,-1.5360268863861264,1.312668353072438 15 | 1.2835966282443705,0.52,-2.4748123598228458,1.3257950366031623 16 | 1.5599214925798712,0.56,-1.1145253494510852,1.339052986969194 17 | 1.2140983424935643,0.6,-2.039754764517314,1.3524435168388858 18 | 1.0323534094046534,0.64,-2.6842548871332057,1.3659679520072747 19 | 1.6129654047056157,0.68,-1.2087462973306495,1.3796276315273477 20 | 1.9641949697148349,0.72,0.005337663279710525,1.393423907842621 21 | 1.3990749169557883,0.76,0.03578036801502442,1.4073581469210472 22 | -0.10990119510357332,0.8,2.219844775015233,1.4214317283902578 23 | -0.25915694806951506,0.84,0.6809183883570512,1.4356460456741604 24 | -0.8888922111890621,0.88,2.0305198522710675,1.4500025061309019 25 | -0.08335040900047452,0.92,2.2787073766603365,1.4645025311922109 26 | -0.023548290368510805,0.96,4.4775925760613084,1.4791475565041332 27 | -0.8128009679402796,1.0,2.7652659337161385,1.4939390320691746 28 | -0.1175132479087937,1.04,2.8034521204375955,1.5088784223898664 29 | -0.2589374638164481,1.08,4.183331782795244,1.5239672066137648 30 | -0.16151263471259825,1.12,1.957065332029689,1.5392068786799027 31 | -0.2396705910201422,1.16,4.316673120131197,1.5545989474667017 32 | -0.9720654015172908,1.2,0.07270584747728992,1.5701449369413687 33 | -0.29814566435576484,1.24,-0.18462389235429225,1.5858463863107823 34 | -0.5184474113558644,1.28,0.1298440182997036,1.6017048501738902 35 | -0.007237596995574358,1.32,-0.4055448059123543,1.6177218986756292 36 | -0.8413589672070856,1.36,0.5283533444033732,1.6338991176623854 37 | 1.0261711314996007,1.4,-1.5574378152145274,1.6502381088390092 38 | -0.4535613661732387,1.44,-1.0380776614731198,1.6667404899273994 39 | 1.4240272770097615,1.48,-0.10950934229131007,1.6834078948266735 40 | 1.984008033684519,1.52,0.531138118496589,1.7002419737749404 41 | 1.376496902663551,1.56,1.0859819954228085,1.7172443935126898 42 | 1.780794649490824,1.6,1.442593256852713,1.7344168374478166 43 | 1.8246987192150312,1.64,3.412148386013853,1.7517610058222948 44 | 1.4533294096949576,1.68,2.3385135459779423,1.7692786158805178 45 | -0.8862071895544011,1.72,4.456706428378206,1.7869714020393233 46 | -0.996465419660847,1.76,1.4180687783760022,1.804841116059716 47 | -0.0871000583266931,1.8,3.8676429208611776,1.8228895272203132 48 | 1.2469396183930672,1.84,2.3495256590939486,1.8411184224925168 49 | 1.95547747887927,1.88,3.3215986756959373,1.8595296067174416 50 | 1.0211792939297375,1.92,3.954200076501933,1.8781249027846163 51 | 1.9489927167336785,1.96,3.6806058729049935,1.8969061518124624 52 | 1.1517814298941471,2.0,2.9603223582222755,1.9158752133305867 53 | 1.6746094547921069,2.04,1.3222406979749397,1.9350339654638928 54 | 1.7883355155615752,2.08,1.6932568644160824,1.954384305118532 55 | 1.7991027274666056,2.12,0.10470848175855413,1.9739281481697168 56 | -0.6174224464456356,2.16,-0.31875204402768603,1.9936674296514143 57 | -0.4535842690084661,2.2,-0.3905537631012365,2.0136041039479284 58 | -0.5108753195966161,2.24,-1.265978612930074,2.033740144987408 59 | 1.3871089623715065,2.28,-0.6960355493302135,2.054077546437282 60 | 1.183699040163784,2.32,1.60088514761442,2.0746183219016547 61 | 1.2524900814944742,2.36,3.0482356894805034,2.0953645051206706 62 | 1.148413920256103,2.4,3.376639680944413,2.1163181501718777 63 | 1.4240306940340752,2.44,4.4070882254749035,2.1374813316735963 64 | -0.1356555711307147,2.48,5.0652674308976815,2.1588561449903323 65 | -0.09847452029409877,2.52,4.517487936823233,2.180444706440236 66 | -0.8102212141285373,2.56,4.748530507081234,2.202249153504638 67 | -0.34731082465230256,2.6,3.6878799750086815,2.224271645039684 68 | -0.6486830586118334,2.64,5.389697645778033,2.246514361490081 69 | -0.9327747419389748,2.68,3.246772111814682,2.2689795051049817 70 | -0.12021127259655172,2.72,5.258138727479598,2.2916693001560318 71 | -0.5987039511531936,2.76,3.3015425071784934,2.314585993157592 72 | -0.18247272243402013,2.8000000000000003,3.3657197559022136,2.337731853089168 73 | 1.293098362915139,2.84,1.993037856164722,2.3611091716200603 74 | 1.4766163793115241,2.88,2.593528486593528,2.3847202633362605 75 | 1.3886013570728188,2.92,1.5868813904332717,2.408567465969623 76 | -0.126716505670754,2.96,2.113545507471565,2.432653140629319 77 | -0.6642629165181978,3.0,1.8299339422569727,2.456979672035612 78 | -0.2257290687318291,3.04,2.175561684967368,2.481549468755968 79 | -0.9838058942788818,3.08,1.0616507579922672,2.506364963443528 80 | -0.9657155065954168,3.12,3.2514641463553704,2.531428613077963 81 | 1.5126020074489157,3.16,3.032914837372812,2.5567428992087433 82 | 1.5626782437432811,3.2,1.6717575799267492,2.58231032820083 83 | -0.7138646183658083,3.24,3.984215873105136,2.6081334314828384 84 | -0.6060443648312442,3.28,4.110406395170294,2.6342147657976667 85 | -0.36815819007413264,3.3200000000000003,3.3733279021302014,2.6605569134556437 86 | -0.4736925644065974,3.36,5.835939932178184,2.6871624825902 87 | -0.23941811088876466,3.4,5.409405499399095,2.7140341074161016 88 | -0.8589152482641706,3.44,6.565252782791443,2.7411744484902627 89 | -0.28957267843579404,3.48,4.0266055020006295,2.768586192975165 90 | -0.0960031113880374,3.52,2.7066162590393192,2.7962720549049167 91 | -0.023121597146798067,3.56,2.1137509457069474,2.824234775453966 92 | -0.06578700431896622,3.6,2.144538194538669,2.852477123208505 93 | -0.4018094590041536,3.64,2.7043799522429945,2.8810018944405904 94 | -0.8468544526140299,3.68,2.8353471405300916,2.9098119133849965 95 | 1.8579678591388789,3.72,3.9593867748031264,2.938910032518846 96 | 1.882625314938996,3.76,0.9030273743151104,2.9682991328440345 97 | 1.0964541996427668,3.8,0.2928022140243649,2.9979821241724753 98 | 1.193984909048147,3.84,0.9282136419835488,3.0279619454142 99 | 1.2430031280920122,3.88,1.5120123202193554,3.0582415648683416 100 | 1.5261277130889852,3.92,0.6191125199854381,3.088823980517025 101 | 1.925848439853888,3.96,5.7973038733588185,3.1197122203221954 102 | -------------------------------------------------------------------------------- /data/repgermany.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/data/repgermany.dta -------------------------------------------------------------------------------- /data/wave2vec_audio_samples/Pulp_fiction_clip.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/data/wave2vec_audio_samples/Pulp_fiction_clip.wav -------------------------------------------------------------------------------- /data/wave2vec_audio_samples/Taken_clip.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/data/wave2vec_audio_samples/Taken_clip.wav -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: btsa 2 | channels: 3 | - conda-forge 4 | - pytorch 5 | dependencies: 6 | - python=3.8 7 | - pip 8 | - pystan==2.19.1.1 9 | - prophet==1.0.1 10 | - jupyter=1.0.0 11 | - jupyterlab=3.1.4 12 | - matplotlib=3.4.2 13 | - nb_conda_kernels 14 | - numpy=1.21.1 15 | - pandas=1.3.1 16 | - plotly=5.1.0 17 | - pymc3=3.11.2 18 | - scikit-learn=0.24.2 19 | - scipy=1.7.1 20 | - seaborn=0.11.1 21 | - statsmodels=0.12.2 22 | - pip: 23 | - gluonts==0.8.0 24 | - mxnet==1.8.0.post0 25 | - numpyro==0.7.2 26 | - sktime==0.7.0 27 | - torch==1.9.0 28 | - pytorchts==0.5.1 29 | - ipywidgets==7.6.3 30 | - bambi==0.6.0 31 | - pycausalimpact==0.1.1 32 | -------------------------------------------------------------------------------- /images/sample_data_1_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/images/sample_data_1_plot.png -------------------------------------------------------------------------------- /meetup.md: -------------------------------------------------------------------------------- 1 | # Meet Up Schedule 2 | 3 | In this section we want to track the Meet Up contents and information. 4 | 5 | ## 02.06.2020 Kick-Off Meeting 6 | 7 | ## 07.07.2020 Synthetic control in time series 8 | 9 | **Speaker:** [Sebastian Martinez](https://smartinez.co/) 10 | 11 | **Abstract:** Synthetic control is a method for estimating *causal* effects (evaluate the effect of an intervention) in comparative case studies when there is only one treatment unit. The method chooses a set of weights for a group of corresponding units that produces an optimally estimated *counterfactual* to the unit that received the treatment. This unit is referred to as the “synthetic unit” and can be used to outline what would have happened to the treated unit had the treatment never occurred. 12 | 13 | ## 11.08.2020 Exploring [Facebook Prophet](https://facebook.github.io/prophet/) (Book Club) 14 | 15 | 16 | 17 | **Moderator:** [Aaron Pickering](https://www.linkedin.com/in/aaron-p-87a139175/) 18 | 19 | **Descripton:** We want to discuss the capabilities and limitations of Facebook’s forecasting package *Prophet*. We want to work a concrete example: On the file `data/sample_data_1.csv` you can find (dummy) `sales` data (`2018-01-01` to `2021-06-30`). In addition there is a feature `media` which could be used as an external predictor. The objective is to create a time series forecasting model using [Facebook Prophet](https://facebook.github.io/prophet/). The forecasting window is 30 days. Here are some hints/steps for the challenge: 20 | 21 | 1. Do an EDA on the sample data. 22 | 2. Is there any clear seasonality or trend? 23 | 3. Is the feature `media` useful for prediction? 24 | 4. How do you evaluate model performance? 25 | 5. Can you estimate model uncertainty (credible intervals)? 26 | 27 | Try to generate predictions for the whole month of *July 2021*. We will provide the "true" values during the meetup so that we can all test our models. Again, this is not a competition, but rather a concrete use case to apply what we learn about Prophet. 28 | 29 | Please bring questions and suggestions to make the best out of this session! 30 | 31 | ## 08.09.2020 Introduction to sktime : A Unified Interface for Machine Learning with Time Series 32 | 33 | **Speaker:** [Markus Löning](https://www.geog.ucl.ac.uk/people/research-students/markus-loning) (PhD Student @UCL) 34 | 35 | **Abstract:** We present sktime, a new unified toolbox for machine learning with time series in Python. We provide state-of-the-art time series algorithms and scikit-learn compatible tools for model composition. The goal of sktime is to make the time series analysis ecosystem more usable and interoperable. In this talk, you'll learn about different time series learning tasks, how algorithms for one task can be used to help solve another one, sktime's key design ideas and our plans for the future. 36 | 37 | **Resources:** 38 | - MeeUp Code [https://github.com/mloning/intro-to-sktime-berlin-tsa-meetup-2020](https://github.com/mloning/intro-to-sktime-berlin-tsa-meetup-2020) 39 | - GitHub [https://github.com/alan-turing-institute/sktime](https://github.com/alan-turing-institute/sktime) 40 | - Paper [sktime: A Unified Interface for Machine Learning 41 | with Time Series](http://learningsys.org/neurips19/assets/papers/sktime_ml_systems_neurips2019.pdf) 42 | 43 | ## 13.10.2020 Amazon DeepAR (Book Club) 44 | 45 | **Moderator:** [Korbinian Kuusisto](https://kkuusisto.github.io/) (Co-Founder @ Kineo.ai) 46 | 47 | **Abstract:** Probabilistic forecasting, i.e. estimating the probability distribution of a time series’ future given its past, is a key enabler for optimizing business processes. In retail businesses, for example, forecasting demand is crucial for having the right inventory available at the right time at the right place. 48 | 49 | The prevalent forecasting methods in use today have been developed in the setting of forecasting individual or small groups of time series. In this approach, model parameters for each given time series are independently estimated from past observations. The model is typically manually selected 50 | to account for different factors, such as autocorrelation structure, trend, seasonality, and other explanatory variables. 51 | 52 | However, especially in the demand forecasting domain, one is often faced with highly erratic, intermittent or bursty data which violate core assumptions of many classical techniques, such as Gaussian errors, stationarity, or homoscedasticity of the time series. 53 | 54 | Amazon's DeepAR is a forecasting method based on auto-regressive recurrent networks (LSTMs), which learns a global model from historical data of all time series in the data set. In their paper the authors demonstrate how by applying deep learning techniques to forecasting, one can overcome many of the challenges faced by widely-used classical approaches to the problem. 55 | 56 | **Resources:** 57 | - [DeepAR: Probabilistic forecasting with autoregressive recurrent networks](https://www.sciencedirect.com/science/article/pii/S0169207019301888) 58 | - [Understanding LSTM Networks](https://colah.github.io/posts/2015-08-Understanding-LSTMs/) 59 | - [Entity Embeddings of Categorical Variables](https://arxiv.org/abs/1604.06737) 60 | 61 | **Remarks/Questions:*** 62 | - *Do you have a guideline when DeepAR would NOT be useful/appropriate?* 63 | > One big assumption that holds for all deep learning models as well as deepAR is that the distribution of the data does not change in the future. If that happens then of course DeepAR is not appropriate. Another issue is that if your problem has covariates which are not available in the time slots you are doing prediction then this method will not work. Also this method is uni variate method so if your problem is multivariate it will also not be appropriate. Finally due to the LSTM the sequence length might be an issue i.e. if you want to predict daily for 2 years for example. LSTMs suffer from forgetting for long time sequences and then also its not appropriate. In addition, data points must be regular in time (Kashif Rasul). 64 | 65 | ## 03.11.2020 Multi-variate Probabilistic Time Series Forecasting via Conditioned Normalizing Flows 66 | 67 | **Speaker:** Dr. Kashif Rasul (Research Scientist @[Zalando SE](https://en.zalando.de/?_rfl=de)) 68 | 69 | **Abstract:** I will present an overview of deep learning based probabilistic forecasting methods and then show how we can extend it to do multivariate probabilistic forecasting in an efficient manner by using Normalizing Flows. I will cover all the background material needed to understand these concepts as well so don't worry if you are new to them. 70 | 71 | **Resources:** 72 | - ArXiv: [Multi-variate Probabilistic Time Series Forecasting via Conditioned 73 | Normalizing Flows](https://arxiv.org/pdf/2002.06103.pdf) 74 | 75 | ## 08.12.2020 Exploratory data analysis on time series data 76 | 77 | 78 | 79 | **Moderator:** BTSA Organizers 80 | 81 | **Descripton:** We will have a hands on session on exploratory data analysis (EDA) for time series data. EDA depends of course on the data and the objective of the study. We will give some hints on how to start with it. Again, it is not set in stone, but a guiding principle. 82 | - Missing values and data frequency ([notebook](https://github.com/juanitorduz/btsa/blob/master/python/fundamentals/notebooks/eda_part_1_viz_and_missing_values.ipynb)). 83 | - Stationarity and correlation analysis ([notebook](https://github.com/juanitorduz/btsa/blob/master/python/fundamentals/notebooks/eda_part_2_correlations.ipynb)). 84 | - Seasonality, decomposition, and outlier detection ([notebook](https://github.com/juanitorduz/btsa/blob/master/python/fundamentals/notebooks/eda_part_3_decomposition.ipynb)). 85 | 86 | ## 09.02.2021 Azure Automated Machine Learning for Time Series Forecasting 87 | 88 | **Speaker:** [Dr. Francesca Lazzeri](https://developer.microsoft.com/en-us/advocates/francesca-lazzeri) 89 | 90 | **Resources:** 91 | 92 | - GitHub repository: https://github.com/FrancescaLazzeri/AutoML-for-Timeseries-Forecasting-Berlin-MeetUp 93 | - [Article](https://www.oreilly.com/content/3-reasons-to-add-deep-learning-to-your-time-series-toolkit/ ) around classical methods vs deep learning methods for time series forecasting. 94 | 95 | 96 | ## 13.04.2021 Rocket and MiniRocket: Fast time series classification using convolutional kernels 97 | 98 | **Speaker:** Angus Dempster 99 | 100 | **Resources:** 101 | 102 | - Paper Links: 103 | - https://arxiv.org/abs/1910.13051 (ROCKET) 104 | - https://arxiv.org/abs/2012.08791 (MINIROCKET) 105 | - GitHub repositories: 106 | - https://github.com/angus924/rocket 107 | - https://github.com/angus924/minirocket 108 | 109 | ## 18.05.2021 Unsupervised Pre-Training of Audio with Wav2vec 110 | 111 | **Speaker:** [Ritwika Mukherjee](https://ritwika3.wixsite.com/mysite) 112 | 113 | **Abstract:** 114 | Self-supervised methods for learning embedded feature spaces have increased in popularity over the last couple of years. These techniques allow for efficient representation learning despite complex high dimensional input spaces. In this session, we will explore the 'wav2vec' model developed by Facebook research and its applications in audio signal processing. The model has implications in speech, vastly reducing the need for annotated labels, and can be transferred across other time-series data. 115 | 116 | **Resources:** 117 | - [MeetUp Slides](/presentations/wave2vec/Wav2vec.pdf) 118 | - [Demo Notebook](/python/wave2vec/wav2vec_demo.ipynb) 119 | 120 | ## 15.06.2021 Introduction [CausalImpact](https://google.github.io/CausalImpact/) 121 | 122 | **Speaker:** [Munji Choi](https://www.linkedin.com/in/munjichoi/) 123 | 124 | **Resources** 125 | - [Notebook & Data](/python/CausalImpact) 126 | 127 | ## 06.07.2021 Forecasting practitioners: What can we learn from Kaggle Competitions? 128 | 129 | **Speaker:** [Thomas Bierhance](https://www.linkedin.com/in/datenzauberai/) 130 | 131 | **Abstract:** Although Kaggle contests are not directly comparable to a real-life task for a forecasting practitioner, the contests are closer to reality than many of the standard data sets found in the scientific literature. They are therefore a goldmine of practice-relevant ideas. Thomas explains the lessons learned from various Kaggle competitions, what needs to be considered when using them in practice, and what loose ends he believes still exist. 132 | 133 | **Resources** 134 | - [Presentation](presentations/forecast_kaggle_tips/Forecast%20practitioners%20What%20can%20we%20learn%20from%20Kaggle%20competitions.pdf) 135 | 136 | ## 07.09.2021 Introduction to Time Series Forecasting: Classical Statistical Methods 137 | 138 | 139 | 140 | **Abstract:** In this session we will explore three classical time series forecasting methods: 141 | 142 | - Exponential Smoothing (Aaron Pickering) 143 | - ARIMA Models (Sebastian Martinez) 144 | - State Space Models (Juan Orduz) 145 | 146 | We will have 20 min session for each method focusing on explaining the main idea behind it through examples. No prior knowledge is required. 147 | 148 | Recommended reference: Forecasting: Principles and Practice 149 | by Rob J Hyndman and George Athanasopoulos: [https://otexts.com/fpp3/](https://otexts.com/fpp3/) Chapters 8 and 9. 150 | 151 | You can find the notebooks of the session [here](/python/intro_forecasting/). In addition, here is a summary article on [Introduction to Exponential Smoothing](https://btsa.medium.com/introduction-to-exponential-smoothing-9c2d5909a714). 152 | 153 | ## 12.10.2021 Temporal Point Processes for Modeling Continuous-time Event Data 154 | 155 | **Speaker**: [Oleksandr Shchur](https://shchur.github.io/) 156 | 157 | **References:** 158 | - [MeetUp Presentation](/presentations/temporal_point_processes/tpp_presentation.pdf) 159 | - [Neural Temporal Point Processes: A Review](https://arxiv.org/abs/2104.03528) 160 | - Blog post from [Oleksandr Shchur](https://shchur.github.io/): 161 | - [Temporal Point Processes 1: The Conditional Intensity Function](https://shchur.github.io/blog/2020/tpp1-conditional-intensity/) 162 | - [Temporal Point Processes 2: Neural TPP Models](https://shchur.github.io/blog/2021/tpp2-neural-tpps/) 163 | - Python packages related to TPP: 164 | - [tick](https://x-datainitiative.github.io/tick/) 165 | - [pyhawkes](https://github.com/slinderman/pyhawkes) 166 | 167 | ## 09.11.2021 Using ARIMA models to make causal statements 168 | 169 | **Speaker**: [Dr. Fiammetta Menchetti](https://scholar.google.com/citations?user=o1dMQ88AAAAJ&hl=it) and [Eugenio Palmieri](https://palmierieugenio.github.io/) 170 | 171 | **Abstract:** In this talk we will provide an overview of C-ARIMA, an approach based on ARIMA models that can be used to make causal statements under the potential outcomes framework. After a brief description of the methodology, we will have a practical session on a real data set where we will illustrate the use of the CausalArima R package, see [FMenchetti/CausalArima](https://github.com/FMenchetti/CausalArima). 172 | 173 | ## 15.02.2022 Time Series Bootstrapping 174 | 175 | **Speaker:** [Dr. Tom Kealy](https://github.com/TomKealy) 176 | 177 | **Speaker:** Dr. Tom Kealy, Senior Data Scientist at HelloFresh 178 | 179 | **Abstract:** Bootstrapping is a common non-parametric technique which uses resampling with replacement to estimate the distribution of a test statistic. Fatally, for time series methods, bootstrapping relies on the exchangeability of data points for statistical analysis consistency. This talk will introduce methods for bootstrapping time series data, with a particular focus on the Maximum Entropy Bootstrap family of algorithms to estimate distributions of test statistics for time series data. 180 | 181 | ## 15.03.2022 An Introduction to Temporal GNNs 182 | 183 | **Speaker:** [Flavio Morelli](https://flaviomorelli.com/) 184 | 185 | **Abstract:** Graph Neural Networks (GNNs) make it possible to apply deep learning methods to graph data. By taking into account the geometric structure of the graph, it is possible to improve model performance compared to more classical methods of graph analysis. Some examples of data that have a natural graph structure include knowledge graphs, chemical compounds, social and telecommunication networks. However, classical GNNs can only be applied to static graphs. This talk will introduce temporal GNNs, which can be applied to graphs changing through time. We will discuss the different flavors of temporal GNNs and the specific challenges that arise when dealing with dynamic graphs. 186 | 187 | **References:** 188 | 189 | - **Slides:** [Here](https://github.com/flaviomorelli/talks/blob/main/temporal_gnn_introduction/GNN_intro_plus_temporal.pdf) 190 | 191 | - [Rozemberczki et al. (2021)](https://arxiv.org/pdf/2104.07788.pdf) 192 | - [Rossi et al. (2020)](https://arxiv.org/pdf/2104.07788.pdf) 193 | 194 | 195 | ## 05.04.2022 Modern Time Series Analysis with [STUMPY](https://stumpy.readthedocs.io/en/latest/) 196 | 197 | **Speaker:** [Dr. Sean Law](https://seanlaw.github.io/) 198 | 199 | **Abstract:** [STUMPY](https://stumpy.readthedocs.io/en/latest/) is a powerful and scalable Python library that efficiently computes something called the matrix profile which can be used for a variety of time series data mining tasks. In this talk, we'll cover all of the background necessary for understanding how to leverage matrix profiles to automatically find patterns/anomalies in your time series data. 200 | 201 | ## 10.05.2022 Probabilistic energy forecasting: successes and challenges 202 | 203 | **Speaker:** [Dr. Jethro Browell](http://www.jethrobrowell.com/) 204 | 205 | **Abstract:** Energy systems are evolving rapidly as they decarbonize, consequences of which include an increasing dependence on weather and new consumer (and producer) behaviours. As a result, all actors in the energy sector are more reliant than ever on short-term forecasts, from the National Grid to me and (maybe) you. Furthermore, in operate as economically as possible and maintain high standards of reliability, forecast uncertainty must be quantified and managed. This seminar will introduce energy forecasting, highlight statistical challenges in this area, and present some recent solutions including forecasting extreme quantiles and modelling time-varying covariance structures. 206 | 207 | ## 14.06.2022 Open Source Time-Series Forecasting 208 | 209 | **Speaker:** Federico Garza (Co-founder: https://github.com/Nixtla/nixtla) 210 | 211 | **Abstract:** Open source time series forecasting with the Nixtla library. 212 | 213 | ## 07. 2022 - Taking a break for summer 214 | 215 | **Speaker:** Work Life Balance 216 | 217 | ## 13.09.2022 TBD **[POSTPONED]** 218 | 219 | **Speaker** Aaron Pickering (Co-founder http://seenly.io) 220 | 221 | **Abstract:** TBD 222 | 223 | ## 08.11.2022 Intro to QuestDB Time Series Database 224 | 225 | **Speaker** Javier Ramirez (https://es.linkedin.com/in/ramirez) 226 | 227 | **Abstract** Time Series forecasting and modelling is fun, but capturing time-series data and dealing with large volume datasets not so much. 228 | In this talk we will introduce QuestDB, an Apache 2.0 licensed database specialised in time-series. We will see how QuestDB can help ingesting, interactively querying, downsampling or augmenting your data. Since QuestDB is postgreSql-compatible, we can interact easily using python with or without Pandas. We will run a demo using QuestDB and skforecast to illustrate how QuestDB can be integrated to your data science workflows. 229 | 230 | ## 10.01.2023 Uncertainty Estimation in Time Series with Neural Processes 231 | 232 | **Speaker** Xuesong Wang (https://xuesongwang.github.io/) 233 | 234 | **Abstract** TBD 235 | 236 | ## 07.02.2023 Tenuous Relations and Time Series Analysis in PyMC 237 | 238 | **Speaker** Nathaniel Forde 239 | 240 | **Abstract** We'll discuss the nature of lagged impact between multiple time series and sketch some details about how we can implement and use VAR models and their hierarchical variants to quantify the nature of these relationships. 241 | -------------------------------------------------------------------------------- /presentations/2020-06-02_btsa_kickoff_meetup_slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/2020-06-02_btsa_kickoff_meetup_slides.pdf -------------------------------------------------------------------------------- /presentations/Menchetti_Palmieri_CausalArima.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/Menchetti_Palmieri_CausalArima.pdf -------------------------------------------------------------------------------- /presentations/eda_time_series/EDA for Time Series Data.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/eda_time_series/EDA for Time Series Data.pdf -------------------------------------------------------------------------------- /presentations/forecast_kaggle_tips/Forecast practitioners What can we learn from Kaggle competitions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/forecast_kaggle_tips/Forecast practitioners What can we learn from Kaggle competitions.pdf -------------------------------------------------------------------------------- /presentations/hierarchical_bvar/Tenuous Relations and Timeseries Analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/hierarchical_bvar/Tenuous Relations and Timeseries Analysis.pdf -------------------------------------------------------------------------------- /presentations/synthetic_control/BTSA_synthetic_control.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/synthetic_control/BTSA_synthetic_control.pdf -------------------------------------------------------------------------------- /presentations/temporal_point_processes/tpp_presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/temporal_point_processes/tpp_presentation.pdf -------------------------------------------------------------------------------- /presentations/wave2vec/Wav2vec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/presentations/wave2vec/Wav2vec.pdf -------------------------------------------------------------------------------- /python/CausalImpact/data/S&P500.csv: -------------------------------------------------------------------------------- 1 | Date,Open,High,Low,Close*,AdjClose 2 | 2021-06-11,4242.9,4248.38,4232.25,4247.44,4247.44 3 | 2021-06-10,4228.56,4249.74,4220.34,4239.18,4239.18 4 | 2021-06-09,4232.99,4237.09,4218.74,4219.55,4219.55 5 | 2021-06-08,4233.81,4236.74,4208.41,4227.26,4227.26 6 | 2021-06-07,4229.34,4232.34,4215.66,4226.52,4226.52 7 | 2021-06-04,4206.05,4233.45,4206.05,4229.89,4229.89 8 | 2021-06-03,4191.43,4204.39,4167.93,4192.85,4192.85 9 | 2021-06-02,4206.82,4217.37,4198.27,4208.12,4208.12 10 | 2021-06-01,4216.52,4234.12,4197.59,4202.04,4202.04 11 | 2021-05-28,4210.77,4218.36,4203.57,4204.11,4204.11 12 | 2021-05-27,4201.94,4213.38,4197.78,4200.88,4200.88 13 | 2021-05-26,4191.59,4202.61,4184.11,4195.99,4195.99 14 | 2021-05-25,4205.94,4213.42,4182.52,4188.13,4188.13 15 | 2021-05-24,4170.16,4209.52,4170.16,4197.05,4197.05 16 | 2021-05-21,4168.61,4188.72,4151.72,4155.86,4155.86 17 | 2021-05-20,4121.97,4172.8,4121.97,4159.12,4159.12 18 | 2021-05-19,4098.45,4116.93,4061.41,4115.68,4115.68 19 | 2021-05-18,4165.94,4169.15,4125.99,4127.83,4127.83 20 | 2021-05-17,4169.92,4171.92,4142.69,4163.29,4163.29 21 | 2021-05-14,4129.58,4183.13,4129.58,4173.85,4173.85 22 | 2021-05-13,4074.99,4131.58,4074.99,4112.5,4112.5 23 | 2021-05-12,4130.55,4134.73,4056.88,4063.04,4063.04 24 | 2021-05-11,4150.34,4162.04,4111.53,4152.1,4152.1 25 | 2021-05-10,4228.29,4236.39,4188.13,4188.43,4188.43 26 | 2021-05-07,4210.34,4238.04,4201.64,4232.6,4232.6 27 | 2021-05-06,4169.14,4202.7,4147.33,4201.62,4201.62 28 | 2021-05-05,4177.06,4187.72,4160.94,4167.59,4167.59 29 | 2021-05-04,4179.04,4179.04,4128.59,4164.66,4164.66 30 | 2021-05-03,4191.98,4209.39,4188.03,4192.66,4192.66 31 | 2021-04-30,4198.1,4198.1,4174.85,4181.17,4181.17 32 | 2021-04-29,4206.14,4218.78,4176.81,4211.47,4211.47 33 | 2021-04-28,4185.14,4201.53,4181.78,4183.18,4183.18 34 | 2021-04-27,4188.25,4193.35,4176.22,4186.72,4186.72 35 | 2021-04-26,4185.03,4194.19,4182.36,4187.62,4187.62 36 | 2021-04-23,4138.78,4194.17,4138.78,4180.17,4180.17 37 | 2021-04-22,4170.46,4179.57,4123.69,4134.98,4134.98 38 | 2021-04-21,4128.42,4175.02,4126.35,4173.42,4173.42 39 | 2021-04-20,4159.18,4159.18,4118.38,4134.94,4134.94 40 | 2021-04-19,4179.8,4180.81,4150.47,4163.26,4163.26 41 | 2021-04-16,4174.14,4191.31,4170.75,4185.47,4185.47 42 | 2021-04-15,4139.76,4173.49,4139.76,4170.42,4170.42 43 | 2021-04-14,4141.58,4151.69,4120.87,4124.66,4124.66 44 | 2021-04-13,4130.1,4148,4124.43,4141.59,4141.59 45 | 2021-04-12,4124.71,4131.76,4114.82,4127.99,4127.99 46 | 2021-04-09,4096.11,4129.48,4095.51,4128.8,4128.8 47 | 2021-04-08,4089.95,4098.19,4082.54,4097.17,4097.17 48 | 2021-04-07,4074.29,4083.13,4068.31,4079.95,4079.95 49 | 2021-04-06,4075.57,4086.23,4068.14,4073.94,4073.94 50 | 2021-04-05,4034.44,4083.42,4034.44,4077.91,4077.91 51 | 2021-04-01,3992.78,4020.63,3992.78,4019.87,4019.87 52 | 2021-03-31,3967.25,3994.41,3966.98,3972.89,3972.89 53 | 2021-03-30,3963.34,3968.01,3944.35,3958.55,3958.55 54 | 2021-03-29,3969.31,3981.83,3943.25,3971.09,3971.09 55 | 2021-03-26,3917.12,3978.19,3917.12,3974.54,3974.54 56 | 2021-03-25,3879.34,3919.54,3853.5,3909.52,3909.52 57 | 2021-03-24,3919.93,3942.08,3889.07,3889.14,3889.14 58 | 2021-03-23,3937.6,3949.13,3901.57,3910.52,3910.52 59 | 2021-03-22,3916.48,3955.31,3914.16,3940.59,3940.59 60 | 2021-03-19,3913.14,3930.12,3886.75,3913.1,3913.1 61 | 2021-03-18,3953.5,3969.62,3910.86,3915.46,3915.46 62 | 2021-03-17,3949.57,3983.87,3935.74,3974.12,3974.12 63 | 2021-03-16,3973.59,3981.04,3953.44,3962.71,3962.71 64 | 2021-03-15,3942.96,3970.08,3923.54,3968.94,3968.94 65 | 2021-03-12,3924.52,3944.99,3915.21,3943.34,3943.34 66 | 2021-03-11,3915.54,3960.27,3915.54,3939.34,3939.34 67 | 2021-03-10,3891.99,3917.35,3885.73,3898.81,3898.81 68 | 2021-03-09,3851.93,3903.76,3851.93,3875.44,3875.44 69 | 2021-03-08,3844.39,3881.06,3819.25,3821.35,3821.35 70 | 2021-03-05,3793.58,3851.69,3730.19,3841.94,3841.94 71 | 2021-03-04,3818.53,3843.67,3723.34,3768.47,3768.47 72 | 2021-03-03,3863.99,3874.47,3818.86,3819.72,3819.72 73 | 2021-03-02,3903.64,3906.41,3868.57,3870.29,3870.29 74 | 2021-03-01,3842.51,3914.5,3842.51,3901.82,3901.82 75 | 2021-02-26,3839.66,3861.08,3789.54,3811.15,3811.15 76 | 2021-02-25,3915.8,3925.02,3814.04,3829.34,3829.34 77 | 2021-02-24,3873.71,3928.65,3859.6,3925.43,3925.43 78 | 2021-02-23,3857.07,3895.98,3805.59,3881.37,3881.37 79 | 2021-02-22,3885.55,3902.92,3874.71,3876.5,3876.5 80 | 2021-02-19,3921.16,3930.41,3903.07,3906.71,3906.71 81 | 2021-02-18,3915.86,3921.98,3885.03,3913.97,3913.97 82 | 2021-02-17,3918.5,3933.61,3900.43,3931.33,3931.33 83 | 2021-02-16,3939.61,3950.43,3923.85,3932.59,3932.59 84 | 2021-02-12,3911.65,3937.23,3905.78,3934.83,3934.83 85 | 2021-02-11,3916.4,3925.99,3890.39,3916.38,3916.38 86 | 2021-02-10,3920.78,3931.5,3884.94,3909.88,3909.88 87 | 2021-02-09,3910.49,3918.35,3902.64,3911.23,3911.23 88 | 2021-02-08,3892.59,3915.77,3892.59,3915.59,3915.59 89 | 2021-02-05,3878.3,3894.56,3874.93,3886.83,3886.83 90 | 2021-02-04,3836.66,3872.42,3836.66,3871.74,3871.74 91 | 2021-02-03,3840.27,3847.51,3816.68,3830.17,3830.17 92 | 2021-02-02,3791.84,3843.09,3791.84,3826.31,3826.31 93 | 2021-02-01,3731.17,3784.32,3725.62,3773.86,3773.86 94 | 2021-01-29,3778.05,3778.05,3694.12,3714.24,3714.24 95 | 2021-01-28,3755.75,3830.5,3755.75,3787.38,3787.38 96 | 2021-01-27,3836.83,3836.83,3732.48,3750.77,3750.77 97 | 2021-01-26,3862.96,3870.9,3847.78,3849.62,3849.62 98 | 2021-01-25,3851.68,3859.23,3797.16,3855.36,3855.36 99 | 2021-01-22,3844.24,3852.31,3830.41,3841.47,3841.47 100 | 2021-01-21,3857.46,3861.45,3845.05,3853.07,3853.07 101 | 2021-01-20,3816.22,3859.75,3816.22,3851.85,3851.85 102 | 2021-01-19,3781.88,3804.53,3780.37,3798.91,3798.91 103 | 2021-01-15,3788.73,3788.73,3749.62,3768.25,3768.25 104 | 2021-01-14,3814.98,3823.6,3792.86,3795.54,3795.54 105 | 2021-01-13,3802.23,3820.96,3791.5,3809.84,3809.84 106 | 2021-01-12,3801.62,3810.78,3776.51,3801.19,3801.19 107 | 2021-01-11,3803.14,3817.86,3789.02,3799.61,3799.61 108 | 2021-01-08,3815.05,3826.69,3783.6,3824.68,3824.68 109 | 2021-01-07,3764.71,3811.55,3764.71,3803.79,3803.79 110 | 2021-01-06,3712.2,3783.04,3705.34,3748.14,3748.14 111 | 2021-01-05,3698.02,3737.83,3695.07,3726.86,3726.86 112 | 2021-01-04,3764.61,3769.99,3662.71,3700.65,3700.65 113 | 2020-12-31,3733.27,3760.2,3726.88,3756.07,3756.07 114 | 2020-12-30,3736.19,3744.63,3730.21,3732.04,3732.04 115 | 2020-12-29,3750.01,3756.12,3723.31,3727.04,3727.04 116 | 2020-12-28,3723.03,3740.51,3723.03,3735.36,3735.36 117 | 2020-12-24,3694.03,3703.82,3689.32,3703.06,3703.06 118 | 2020-12-23,3693.42,3711.24,3689.28,3690.01,3690.01 119 | 2020-12-22,3698.08,3698.26,3676.16,3687.26,3687.26 120 | 2020-12-21,3684.28,3702.9,3636.48,3694.92,3694.92 121 | 2020-12-18,3722.39,3726.7,3685.84,3709.41,3709.41 122 | 2020-12-17,3713.65,3725.12,3710.87,3722.48,3722.48 123 | 2020-12-16,3696.25,3711.27,3688.57,3701.17,3701.17 124 | 2020-12-15,3666.41,3695.29,3659.62,3694.62,3694.62 125 | 2020-12-14,3675.27,3697.61,3645.84,3647.49,3647.49 126 | 2020-12-11,3656.08,3665.91,3633.4,3663.46,3663.46 127 | 2020-12-10,3659.13,3678.49,3645.18,3668.1,3668.1 128 | 2020-12-09,3705.98,3712.39,3660.54,3672.82,3672.82 129 | 2020-12-08,3683.05,3708.45,3678.83,3702.25,3702.25 130 | 2020-12-07,3694.73,3697.41,3678.88,3691.96,3691.96 131 | 2020-12-04,3670.94,3699.2,3670.94,3699.12,3699.12 132 | 2020-12-03,3668.28,3682.73,3657.17,3666.72,3666.72 133 | 2020-12-02,3653.78,3670.96,3644.84,3669.01,3669.01 134 | 2020-12-01,3645.87,3678.45,3645.87,3662.45,3662.45 135 | 2020-11-30,3634.18,3634.18,3594.39,3621.63,3621.63 136 | 2020-11-27,3638.55,3644.31,3629.33,3638.35,3638.35 137 | 2020-11-25,3635.5,3635.5,3617.76,3629.65,3629.65 138 | 2020-11-24,3594.52,3642.31,3594.52,3635.41,3635.41 139 | 2020-11-23,3566.82,3589.81,3552.77,3577.59,3577.59 140 | 2020-11-20,3579.31,3581.23,3556.85,3557.54,3557.54 141 | 2020-11-19,3559.41,3585.22,3543.84,3581.87,3581.87 142 | 2020-11-18,3612.09,3619.09,3567.33,3567.79,3567.79 143 | 2020-11-17,3610.31,3623.11,3588.68,3609.53,3609.53 144 | 2020-11-16,3600.16,3628.51,3600.16,3626.91,3626.91 145 | 2020-11-13,3552.57,3593.66,3552.57,3585.15,3585.15 146 | 2020-11-12,3562.67,3569.02,3518.58,3537.01,3537.01 147 | 2020-11-11,3563.22,3581.16,3557,3572.66,3572.66 148 | 2020-11-10,3543.26,3557.22,3511.91,3545.53,3545.53 149 | 2020-11-09,3583.04,3645.99,3547.48,3550.5,3550.5 150 | 2020-11-06,3508.34,3521.58,3484.34,3509.44,3509.44 151 | 2020-11-05,3485.74,3529.05,3485.74,3510.45,3510.45 152 | 2020-11-04,3406.46,3486.25,3405.17,3443.44,3443.44 153 | 2020-11-03,3336.25,3389.49,3336.25,3369.16,3369.16 154 | 2020-11-02,3296.2,3330.14,3279.74,3310.24,3310.24 155 | 2020-10-30,3293.59,3304.93,3233.94,3269.96,3269.96 156 | 2020-10-29,3277.17,3341.05,3259.82,3310.11,3310.11 157 | 2020-10-28,3342.48,3342.48,3268.89,3271.03,3271.03 158 | 2020-10-27,3403.15,3409.51,3388.71,3390.68,3390.68 159 | 2020-10-26,3441.42,3441.42,3364.86,3400.97,3400.97 160 | 2020-10-23,3464.9,3466.46,3440.45,3465.39,3465.39 161 | 2020-10-22,3438.5,3460.53,3415.34,3453.49,3453.49 162 | 2020-10-21,3439.91,3464.86,3433.06,3435.56,3435.56 163 | 2020-10-20,3439.38,3476.93,3435.65,3443.12,3443.12 164 | 2020-10-19,3493.66,3502.42,3419.93,3426.92,3426.92 165 | 2020-10-16,3493.5,3515.76,3480.45,3483.81,3483.81 166 | 2020-10-15,3453.72,3489.08,3440.89,3483.34,3483.34 167 | 2020-10-14,3515.47,3527.94,3480.55,3488.67,3488.67 168 | 2020-10-13,3534.01,3534.01,3500.86,3511.93,3511.93 169 | 2020-10-12,3500.02,3549.85,3499.61,3534.22,3534.22 170 | 2020-10-09,3459.67,3482.34,3458.07,3477.14,3477.14 171 | 2020-10-08,3434.28,3447.28,3428.15,3446.83,3446.83 172 | 2020-10-07,3384.56,3426.26,3384.56,3419.44,3419.44 173 | 2020-10-06,3408.74,3431.56,3354.54,3360.97,3360.97 174 | 2020-10-05,3367.27,3409.57,3367.27,3408.6,3408.6 175 | 2020-10-02,3338.94,3369.1,3323.69,3348.42,3348.42 176 | 2020-10-01,3385.87,3397.18,3361.39,3380.8,3380.8 177 | 2020-09-30,3341.21,3393.56,3340.47,3363,3363 178 | 2020-09-29,3350.92,3357.92,3327.54,3335.47,3335.47 179 | 2020-09-28,3333.9,3360.74,3332.91,3351.6,3351.6 180 | 2020-09-25,3236.66,3306.88,3228.44,3298.46,3298.46 181 | 2020-09-24,3226.14,3278.7,3209.45,3246.59,3246.59 182 | 2020-09-23,3320.11,3323.35,3232.57,3236.92,3236.92 183 | 2020-09-22,3295.75,3320.31,3270.95,3315.57,3315.57 184 | 2020-09-21,3285.57,3285.57,3229.1,3281.06,3281.06 185 | 2020-09-18,3357.38,3362.27,3292.4,3319.47,3319.47 186 | 2020-09-17,3346.86,3375.17,3328.82,3357.01,3357.01 187 | 2020-09-16,3411.23,3428.92,3384.45,3385.49,3385.49 188 | 2020-09-15,3407.73,3419.48,3389.25,3401.2,3401.2 189 | 2020-09-14,3363.56,3402.93,3363.56,3383.54,3383.54 190 | 2020-09-11,3352.7,3368.95,3310.47,3340.97,3340.97 191 | 2020-09-10,3412.56,3425.55,3329.25,3339.19,3339.19 192 | 2020-09-09,3369.82,3424.77,3366.84,3398.96,3398.96 193 | 2020-09-08,3371.88,3379.97,3329.27,3331.84,3331.84 194 | 2020-09-04,3453.6,3479.15,3349.63,3426.96,3426.96 195 | 2020-09-03,3564.74,3564.85,3427.41,3455.06,3455.06 196 | 2020-09-02,3543.76,3588.11,3535.23,3580.84,3580.84 197 | 2020-09-01,3507.44,3528.03,3494.6,3526.65,3526.65 198 | 2020-08-31,3509.73,3514.77,3493.25,3500.31,3500.31 199 | 2020-08-28,3494.69,3509.23,3484.32,3508.01,3508.01 200 | 2020-08-27,3485.14,3501.38,3468.35,3484.55,3484.55 201 | 2020-08-26,3449.97,3481.07,3444.15,3478.73,3478.73 202 | 2020-08-25,3435.95,3444.21,3425.84,3443.62,3443.62 203 | 2020-08-24,3418.09,3432.09,3413.13,3431.28,3431.28 204 | 2020-08-21,3386.01,3399.96,3379.31,3397.16,3397.16 205 | 2020-08-20,3360.48,3390.8,3354.69,3385.51,3385.51 206 | 2020-08-19,3392.51,3399.54,3369.66,3374.85,3374.85 207 | 2020-08-18,3387.04,3395.06,3370.15,3389.78,3389.78 208 | 2020-08-17,3380.86,3387.59,3379.22,3381.99,3381.99 209 | 2020-08-14,3368.66,3378.51,3361.64,3372.85,3372.85 210 | 2020-08-13,3372.95,3387.24,3363.35,3373.43,3373.43 211 | 2020-08-12,3355.46,3387.89,3355.46,3380.35,3380.35 212 | 2020-08-11,3370.34,3381.01,3326.44,3333.69,3333.69 213 | 2020-08-10,3356.04,3363.29,3335.44,3360.47,3360.47 214 | 2020-08-07,3340.05,3352.54,3328.72,3351.28,3351.28 215 | 2020-08-06,3323.17,3351.03,3318.14,3349.16,3349.16 216 | 2020-08-05,3317.37,3330.77,3317.37,3327.77,3327.77 217 | 2020-08-04,3289.92,3306.84,3286.37,3306.51,3306.51 218 | 2020-08-03,3288.26,3302.73,3284.53,3294.61,3294.61 219 | 2020-07-31,3270.45,3272.17,3220.26,3271.12,3271.12 220 | 2020-07-30,3231.76,3250.92,3204.13,3246.22,3246.22 221 | 2020-07-29,3227.22,3264.74,3227.22,3258.44,3258.44 222 | 2020-07-28,3234.27,3243.72,3216.17,3218.44,3218.44 223 | 2020-07-27,3219.84,3241.43,3214.25,3239.41,3239.41 224 | 2020-07-24,3218.58,3227.26,3200.05,3215.63,3215.63 225 | 2020-07-23,3271.64,3279.99,3222.66,3235.66,3235.66 226 | 2020-07-22,3254.86,3279.32,3253.1,3276.02,3276.02 227 | 2020-07-21,3268.52,3277.29,3247.77,3257.3,3257.3 228 | 2020-07-20,3224.29,3258.61,3215.16,3251.84,3251.84 229 | 2020-07-17,3224.21,3233.52,3205.65,3224.73,3224.73 230 | 2020-07-16,3208.36,3220.39,3198.59,3215.57,3215.57 231 | 2020-07-15,3225.98,3238.28,3200.76,3226.56,3226.56 232 | 2020-07-14,3141.11,3200.95,3127.66,3197.52,3197.52 233 | 2020-07-13,3205.08,3235.32,3149.43,3155.22,3155.22 234 | 2020-07-10,3152.47,3186.82,3136.22,3185.04,3185.04 235 | 2020-07-09,3176.17,3179.78,3115.7,3152.05,3152.05 236 | 2020-07-08,3153.07,3171.8,3136.53,3169.94,3169.94 237 | 2020-07-07,3166.44,3184.15,3142.93,3145.32,3145.32 238 | 2020-07-06,3155.29,3182.59,3155.29,3179.72,3179.72 239 | 2020-07-02,3143.64,3165.81,3124.52,3130.01,3130.01 240 | 2020-07-01,3105.92,3128.44,3101.17,3115.86,3115.86 241 | 2020-06-30,3050.2,3111.51,3047.83,3100.29,3100.29 242 | 2020-06-29,3018.59,3053.89,2999.74,3053.24,3053.24 243 | 2020-06-26,3073.2,3073.73,3004.63,3009.05,3009.05 244 | 2020-06-25,3046.6,3086.25,3024.01,3083.76,3083.76 245 | 2020-06-24,3114.4,3115.01,3032.13,3050.33,3050.33 246 | 2020-06-23,3138.7,3154.9,3127.12,3131.29,3131.29 247 | 2020-06-22,3094.42,3120.92,3079.39,3117.86,3117.86 248 | 2020-06-19,3140.29,3155.53,3083.11,3097.74,3097.74 249 | 2020-06-18,3101.64,3120,3093.51,3115.34,3115.34 250 | 2020-06-17,3136.13,3141.16,3108.03,3113.49,3113.49 251 | 2020-06-16,3131,3153.45,3076.06,3124.74,3124.74 252 | 2020-06-15,2993.76,3079.76,2965.66,3066.59,3066.59 253 | 2020-06-12,3071.04,3088.42,2984.47,3041.31,3041.31 -------------------------------------------------------------------------------- /python/CausalImpact/data/bitcoin_historical_price.csv: -------------------------------------------------------------------------------- 1 | Date,Open,High,Low,Close,AdjClose 2 | 2021-06-12,37230.7,37358.46,34764.79,35841.09,35841.09 3 | 2021-06-11,36697.03,37608.7,36044.45,37334.4,37334.4 4 | 2021-06-10,37389.52,38334.32,35847.59,36702.6,36702.6 5 | 2021-06-09,33416.98,37537.37,32475.87,37345.12,37345.12 6 | 2021-06-08,33589.52,34017.39,31114.44,33472.63,33472.63 7 | 2021-06-07,35835.27,36790.57,33480.64,33560.71,33560.71 8 | 2021-06-06,35538.61,36436.42,35304.58,35862.38,35862.38 9 | 2021-06-05,36880.16,37917.71,34900.41,35551.96,35551.96 10 | 2021-06-04,39242.48,39242.48,35717.72,36894.41,36894.41 11 | 2021-06-03,37599.41,39478.95,37243.97,39208.77,39208.77 12 | 2021-06-02,36699.92,38231.34,35966.31,37575.18,37575.18 13 | 2021-06-01,37293.79,37896.73,35787.09,36684.93,36684.93 14 | 2021-05-31,35658.59,37468.25,34241.95,37332.86,37332.86 15 | 2021-05-30,34607.41,36400.67,33520.74,35678.13,35678.13 16 | 2021-05-29,35684.16,37234.5,33693.93,34616.07,34616.07 17 | 2021-05-28,38507.08,38856.97,34779.04,35697.61,35697.61 18 | 2021-05-27,39316.89,40379.62,37247.9,38436.97,38436.97 19 | 2021-05-26,38392.63,40782.08,37905.84,39294.2,39294.2 20 | 2021-05-25,38795.78,39776.35,36581.43,38402.22,38402.22 21 | 2021-05-24,34700.36,39835.14,34551.08,38705.98,38705.98 22 | 2021-05-23,37531.45,38289.22,31227.34,34770.58,34770.58 23 | 2021-05-22,37371.03,38831.05,35383.68,37536.63,37536.63 24 | 2021-05-21,40596.95,42172.17,33616.45,37304.69,37304.69 25 | 2021-05-20,36753.67,42462.98,35050.62,40782.74,40782.74 26 | 2021-05-19,42944.98,43546.12,30681.5,37002.44,37002.44 27 | 2021-05-18,43488.06,45812.46,42367.83,42909.4,42909.4 28 | 2021-05-17,46415.9,46623.56,42207.29,43537.51,43537.51 29 | 2021-05-16,46716.64,49720.04,43963.35,46456.06,46456.06 30 | 2021-05-15,49855.5,50639.66,46664.14,46760.19,46760.19 31 | 2021-05-14,49682.98,51438.12,48868.58,49880.54,49880.54 32 | 2021-05-13,49735.43,51330.84,46980.02,49716.19,49716.19 33 | 2021-05-12,56714.53,57939.36,49150.54,49150.54,49150.54 34 | 2021-05-11,55847.24,56872.54,54608.65,56704.57,56704.57 35 | 2021-05-10,58250.87,59519.36,54071.46,55859.8,55859.8 36 | 2021-05-09,58877.39,59210.88,56482,58232.32,58232.32 37 | 2021-05-08,57352.77,59464.61,56975.21,58803.78,58803.78 38 | 2021-05-07,56413.95,58606.63,55321.85,57356.4,57356.4 39 | 2021-05-06,57441.31,58363.32,55382.51,56396.52,56396.52 40 | 2021-05-05,53252.16,57911.36,52969.05,57424.01,57424.01 41 | 2021-05-04,57214.18,57214.18,53191.43,53333.54,53333.54 42 | 2021-05-03,56620.27,58973.31,56590.87,57200.29,57200.29 43 | 2021-05-02,57825.86,57902.59,56141.91,56631.08,56631.08 44 | 2021-05-01,57714.66,58448.34,57052.27,57828.05,57828.05 45 | 2021-04-30,53568.66,57900.72,53129.6,57750.18,57750.18 46 | 2021-04-29,54858.09,55115.84,52418.03,53555.11,53555.11 47 | 2021-04-28,55036.64,56227.21,53887.92,54824.7,54824.7 48 | 2021-04-27,54030.3,55416.96,53319.19,55033.12,55033.12 49 | 2021-04-26,49077.79,54288,48852.8,54021.75,54021.75 50 | 2021-04-25,50052.83,50506.02,47159.48,49004.25,49004.25 51 | 2021-04-24,51143.23,51167.56,48805.29,50050.87,50050.87 52 | 2021-04-23,51739.81,52120.79,47714.66,51093.65,51093.65 53 | 2021-04-22,53857.11,55410.23,50583.81,51762.27,51762.27 54 | 2021-04-21,56471.13,56757.97,53695.47,53906.09,53906.09 55 | 2021-04-20,55681.79,57062.15,53448.05,56473.03,56473.03 56 | 2021-04-19,56191.59,57520.05,54368.59,55724.27,55724.27 57 | 2021-04-18,60701.89,61057.46,52829.54,56216.18,56216.18 58 | 2021-04-17,61529.92,62572.18,60361.35,60683.82,60683.82 59 | 2021-04-16,63258.5,63594.72,60222.53,61572.79,61572.79 60 | 2021-04-15,63075.2,63821.67,62208.96,63314.01,63314.01 61 | 2021-04-14,63523.75,64863.1,61554.8,63109.7,63109.7 62 | 2021-04-13,59890.02,63742.29,59869.96,63503.46,63503.46 63 | 2021-04-12,60175.95,61253.04,59589.88,59893.45,59893.45 64 | 2021-04-11,59846.23,60790.55,59289.8,60204.96,60204.96 65 | 2021-04-10,58253.78,61276.66,58038.71,59793.23,59793.23 66 | 2021-04-09,58326.56,58937.05,57807.86,58245,58245 67 | 2021-04-08,56099.91,58338.74,55879.09,58323.95,58323.95 68 | 2021-04-07,58186.51,58731.14,55604.02,56048.94,56048.94 69 | 2021-04-06,59171.93,59479.58,57646.81,58192.36,58192.36 70 | 2021-04-05,58760.88,59891.3,57694.82,59057.88,59057.88 71 | 2021-04-04,57604.84,58913.75,57168.68,58758.55,58758.55 72 | 2021-04-03,59397.41,60110.27,57603.89,57603.89,57603.89 73 | 2021-04-02,59098.88,60267.19,58869.28,59384.31,59384.31 74 | 2021-04-01,58926.56,59586.07,58505.28,59095.81,59095.81 75 | 2021-03-31,58930.28,59930.03,57726.42,58918.83,58918.83 76 | 2021-03-30,57750.13,59447.22,57251.55,58917.69,58917.69 77 | 2021-03-29,55947.9,58342.1,55139.34,57750.2,57750.2 78 | 2021-03-28,55974.94,56610.31,55071.11,55950.75,55950.75 79 | 2021-03-27,55137.57,56568.21,54242.91,55973.51,55973.51 80 | 2021-03-26,51683.01,55137.31,51579.86,55137.31,55137.31 81 | 2021-03-25,52726.75,53392.39,50856.57,51704.16,51704.16 82 | 2021-03-24,54710.49,57262.38,52514.33,52774.27,52774.27 83 | 2021-03-23,54511.66,55985.44,53470.7,54738.95,54738.95 84 | 2021-03-22,57517.89,58471.48,54288.16,54529.14,54529.14 85 | 2021-03-21,58309.91,58767.9,56005.62,57523.42,57523.42 86 | 2021-03-20,58332.26,60031.29,58213.3,58313.64,58313.64 87 | 2021-03-19,57850.44,59498.38,56643.7,58346.65,58346.65 88 | 2021-03-18,58893.08,60116.25,54253.58,57858.92,57858.92 89 | 2021-03-17,56825.83,58969.82,54528.63,58870.89,58870.89 90 | 2021-03-16,55840.79,56833.18,53555.03,56804.9,56804.9 91 | 2021-03-15,59267.43,60540.99,55393.16,55907.2,55907.2 92 | 2021-03-14,61221.13,61597.92,59302.32,59302.32,59302.32 93 | 2021-03-13,57343.37,61683.86,56217.97,61243.09,61243.09 94 | 2021-03-12,57821.22,57996.62,55376.65,57332.09,57332.09 95 | 2021-03-11,55963.18,58091.06,54484.59,57805.12,57805.12 96 | 2021-03-10,54824.01,57258.25,53290.89,56008.55,56008.55 97 | 2021-03-09,52272.97,54824.12,51981.83,54824.12,54824.12 98 | 2021-03-08,51174.12,52314.07,49506.05,52246.52,52246.52 99 | 2021-03-07,48918.68,51384.37,48918.68,51206.69,51206.69 100 | 2021-03-06,48899.23,49147.22,47257.53,48912.38,48912.38 101 | 2021-03-05,48527.03,49396.43,46542.52,48927.3,48927.3 102 | 2021-03-04,50522.3,51735.09,47656.93,48561.17,48561.17 103 | 2021-03-03,48415.82,52535.14,48274.32,50538.24,50538.24 104 | 2021-03-02,49612.11,50127.51,47228.84,48378.99,48378.99 105 | 2021-03-01,45159.5,49784.02,45115.09,49631.24,49631.24 106 | 2021-02-28,46194.02,46716.43,43241.62,45137.77,45137.77 107 | 2021-02-27,46344.77,48253.27,45269.03,46188.45,46188.45 108 | 2021-02-26,47180.46,48370.79,44454.84,46339.76,46339.76 109 | 2021-02-25,49709.08,51948.97,47093.85,47093.85,47093.85 110 | 2021-02-24,48835.09,51290.14,47213.5,49705.33,49705.33 111 | 2021-02-23,54204.93,54204.93,45290.59,48824.43,48824.43 112 | 2021-02-22,57532.74,57533.39,48967.57,54207.32,54207.32 113 | 2021-02-21,56068.57,58330.57,55672.61,57539.95,57539.95 114 | 2021-02-20,55887.34,57505.23,54626.56,56099.52,56099.52 115 | 2021-02-19,51675.98,56113.65,50937.28,55888.13,55888.13 116 | 2021-02-18,52140.97,52474.11,51015.77,51679.8,51679.8 117 | 2021-02-17,49207.28,52533.91,49072.38,52149.01,52149.01 118 | 2021-02-16,47944.46,50341.1,47201.3,49199.87,49199.87 119 | 2021-02-15,48696.54,48875.57,46347.48,47945.06,47945.06 120 | 2021-02-14,47114.51,49487.64,47114.51,48717.29,48717.29 121 | 2021-02-13,47491.2,48047.75,46392.28,47105.52,47105.52 122 | 2021-02-12,47877.04,48745.73,46424.98,47504.85,47504.85 123 | 2021-02-11,44898.71,48463.47,44187.76,47909.33,47909.33 124 | 2021-02-10,46469.76,47145.57,43881.15,44918.18,44918.18 125 | 2021-02-09,46184.99,48003.72,45166.96,46481.11,46481.11 126 | 2021-02-08,38886.83,46203.93,38076.32,46196.46,46196.46 127 | 2021-02-07,39250.19,39621.84,37446.15,38903.44,38903.44 128 | 2021-02-06,38138.39,40846.55,38138.39,39266.01,39266.01 129 | 2021-02-05,36931.55,38225.91,36658.76,38144.31,38144.31 130 | 2021-02-04,37475.11,38592.18,36317.5,36926.07,36926.07 131 | 2021-02-03,35510.82,37480.19,35443.98,37472.09,37472.09 132 | 2021-02-02,33533.2,35896.88,33489.22,35510.29,35510.29 133 | 2021-02-01,33114.58,34638.21,32384.23,33537.18,33537.18 134 | 2021-01-31,34270.88,34288.33,32270.18,33114.36,33114.36 135 | 2021-01-30,34295.93,34834.71,32940.19,34269.52,34269.52 136 | 2021-01-29,34318.67,38406.26,32064.81,34316.39,34316.39 137 | 2021-01-28,30441.04,31891.3,30023.21,31649.61,31649.61 138 | 2021-01-27,32564.03,32564.03,29367.14,30432.55,30432.55 139 | 2021-01-26,32358.61,32794.55,31030.27,32569.85,32569.85 140 | 2021-01-25,32285.8,34802.74,32087.79,32366.39,32366.39 141 | 2021-01-24,32064.38,32944.01,31106.69,32289.38,32289.38 142 | 2021-01-23,32985.76,33360.98,31493.16,32067.64,32067.64 143 | 2021-01-22,30817.63,33811.85,28953.37,33005.76,33005.76 144 | 2021-01-21,35549.4,35552.68,30250.75,30825.7,30825.7 145 | 2021-01-20,36050.11,36378.33,33570.48,35547.75,35547.75 146 | 2021-01-19,36642.23,37755.89,36069.8,36069.8,36069.8 147 | 2021-01-18,35792.24,37299.29,34883.84,36630.07,36630.07 148 | 2021-01-17,36163.65,36722.35,34069.32,35791.28,35791.28 149 | 2021-01-16,36821.65,37864.37,35633.55,36178.14,36178.14 150 | 2021-01-15,39156.71,39577.71,34659.59,36825.37,36825.37 151 | 2021-01-14,37325.11,39966.41,36868.56,39187.33,39187.33 152 | 2021-01-13,33915.12,37599.96,32584.67,37316.36,37316.36 153 | 2021-01-12,35516.36,36568.53,32697.98,33922.96,33922.96 154 | 2021-01-11,38346.53,38346.53,30549.6,35566.66,35566.66 155 | 2021-01-10,40254.22,41420.19,35984.63,38356.44,38356.44 156 | 2021-01-09,40788.64,41436.35,38980.88,40254.55,40254.55 157 | 2021-01-08,39381.77,41946.74,36838.64,40797.61,40797.61 158 | 2021-01-07,36833.88,40180.37,36491.19,39371.04,39371.04 159 | 2021-01-06,34013.61,36879.7,33514.04,36824.36,36824.36 160 | 2021-01-05,31977.04,34437.59,30221.19,33992.43,33992.43 161 | 2021-01-04,32810.95,33440.22,28722.76,31971.91,31971.91 162 | 2021-01-03,32129.41,34608.56,32052.32,32782.02,32782.02 163 | 2021-01-02,29376.46,33155.12,29091.18,32127.27,32127.27 164 | 2021-01-01,28994.01,29600.63,28803.59,29374.15,29374.15 165 | 2020-12-31,28841.57,29244.88,28201.99,29001.72,29001.72 166 | 2020-12-30,27360.09,28937.74,27360.09,28840.95,28840.95 167 | 2020-12-29,27081.81,27370.72,25987.3,27362.44,27362.44 168 | 2020-12-28,26280.82,27389.11,26207.64,27084.81,27084.81 169 | 2020-12-27,26439.37,28288.84,25922.77,26272.29,26272.29 170 | 2020-12-26,24677.02,26718.07,24522.69,26437.04,26437.04 171 | 2020-12-25,23733.57,24710.1,23463.67,24664.79,24664.79 172 | 2020-12-24,23240.2,23768.34,22777.6,23735.95,23735.95 173 | 2020-12-23,23781.97,24024.49,22802.65,23241.35,23241.35 174 | 2020-12-22,22794.04,23789.9,22430.61,23783.03,23783.03 175 | 2020-12-21,23474.46,24059.98,22159.37,22803.08,22803.08 176 | 2020-12-20,23861.77,24209.66,23147.71,23477.29,23477.29 177 | 2020-12-19,23132.87,24085.86,22826.47,23869.83,23869.83 178 | 2020-12-18,22806.8,23238.6,22399.81,23137.96,23137.96 179 | 2020-12-17,21308.35,23642.66,21234.68,22805.16,22805.16 180 | 2020-12-16,19418.82,21458.91,19298.32,21310.6,21310.6 181 | 2020-12-15,19246.92,19525.01,19079.84,19417.08,19417.08 182 | 2020-12-14,19144.49,19305.1,19012.71,19246.64,19246.64 183 | 2020-12-13,18806.77,19381.54,18734.33,19142.38,19142.38 184 | 2020-12-12,18051.32,18919.55,18046.04,18803.66,18803.66 185 | 2020-12-11,18263.93,18268.45,17619.53,18058.9,18058.9 186 | 2020-12-10,18553.3,18553.3,17957.06,18264.99,18264.99 187 | 2020-12-09,18320.88,18626.29,17935.55,18553.92,18553.92 188 | 2020-12-08,19191.53,19283.48,18269.95,18321.14,18321.14 189 | 2020-12-07,19343.13,19411.83,18931.14,19191.63,19191.63 190 | 2020-12-06,19154.18,19390.5,18897.89,19345.12,19345.12 191 | 2020-12-05,18698.38,19160.45,18590.19,19154.23,19154.23 192 | 2020-12-04,19446.97,19511.4,18697.19,18699.77,18699.77 193 | 2020-12-03,19205.93,19566.19,18925.79,19445.4,19445.4 194 | 2020-12-02,18801.74,19308.33,18347.72,19201.09,19201.09 195 | 2020-12-01,19633.77,19845.97,18321.92,18803,18803 196 | 2020-11-30,18178.32,19749.26,18178.32,19625.84,19625.84 197 | 2020-11-29,17719.63,18283.63,17559.12,18177.48,18177.48 198 | 2020-11-28,17112.93,17853.94,16910.65,17717.41,17717.41 199 | 2020-11-27,17153.91,17445.02,16526.42,17108.4,17108.4 200 | 2020-11-26,18729.84,18866.29,16351.04,17150.62,17150.62 201 | 2020-11-25,19104.41,19390.96,18581.15,18732.12,18732.12 202 | 2020-11-24,18365.02,19348.27,18128.66,19107.46,19107.46 203 | 2020-11-23,18370.02,18711.43,18000.8,18364.12,18364.12 204 | 2020-11-22,18642.23,18688.97,17671.38,18370,18370 205 | 2020-11-21,18621.32,18936.62,18444.36,18642.23,18642.23 206 | 2020-11-20,17817.08,18773.23,17765.79,18621.31,18621.31 207 | 2020-11-19,17803.86,18119.55,17382.55,17817.09,17817.09 208 | 2020-11-18,17645.19,18393.95,17352.91,17804.01,17804.01 209 | 2020-11-17,16685.69,17782.92,16564.54,17645.41,17645.41 210 | 2020-11-16,15955.58,16816.18,15880.71,16716.11,16716.11 211 | 2020-11-15,16068.14,16123.11,15793.53,15955.59,15955.59 212 | 2020-11-14,16317.81,16317.81,15749.19,16068.14,16068.14 213 | 2020-11-13,16276.44,16463.18,15992.15,16317.81,16317.81 214 | 2020-11-12,15701.3,16305,15534.77,16276.34,16276.34 215 | 2020-11-11,15290.91,15916.26,15290.01,15701.34,15701.34 216 | 2020-11-10,15332.35,15450.33,15124.96,15290.9,15290.9 217 | 2020-11-09,15479.6,15785.14,14865.53,15332.32,15332.32 218 | 2020-11-08,14833.75,15637.32,14744.11,15479.57,15479.57 219 | 2020-11-07,15565.88,15737.1,14423.2,14833.75,14833.75 220 | 2020-11-06,15579.73,15903.44,15226.84,15565.88,15565.88 221 | 2020-11-05,14133.73,15706.4,14102.09,15579.85,15579.85 222 | 2020-11-04,13950.49,14218.77,13580.47,14133.71,14133.71 223 | 2020-11-03,13550.45,13984.98,13325.44,13950.3,13950.3 224 | 2020-11-02,13737.03,13808.32,13243.16,13550.49,13550.49 225 | 2020-11-01,13781,13862.03,13628.38,13737.11,13737.11 226 | 2020-10-31,13546.53,14028.21,13457.53,13781,13781 227 | 2020-10-30,13437.87,13651.52,13136.2,13546.52,13546.52 228 | 2020-10-29,13271.3,13612.05,12980.06,13437.88,13437.88 229 | 2020-10-28,13654.21,13837.7,12932.25,13271.29,13271.29 230 | 2020-10-27,13075.24,13759.67,13060.84,13654.22,13654.22 231 | 2020-10-26,13031.2,13225.3,12822.38,13075.25,13075.25 232 | 2020-10-25,13108.06,13329.18,12910.06,13031.17,13031.17 233 | 2020-10-24,12931.57,13145.07,12885.75,13108.06,13108.06 234 | 2020-10-23,12971.55,13015.96,12752.65,12931.54,12931.54 235 | 2020-10-22,12801.64,13161.59,12717.09,12965.89,12965.89 236 | 2020-10-21,11913.08,13184.57,11900.93,12823.69,12823.69 237 | 2020-10-20,11745.97,11999.92,11681.48,11916.33,11916.33 238 | 2020-10-19,11495.04,11799.09,11408.29,11742.04,11742.04 239 | 2020-10-18,11355.98,11483.36,11347.58,11483.36,11483.36 240 | 2020-10-17,11322.12,11386.26,11285.35,11358.1,11358.1 241 | 2020-10-16,11502.83,11540.06,11223.01,11322.12,11322.12 242 | 2020-10-15,11426.6,11569.91,11303.6,11495.35,11495.35 243 | 2020-10-14,11429.05,11539.98,11307.83,11429.51,11429.51 244 | 2020-10-13,11548.72,11548.98,11321.22,11425.9,11425.9 245 | 2020-10-12,11392.64,11698.47,11240.69,11555.36,11555.36 246 | 2020-10-11,11296.08,11428.81,11288.63,11384.18,11384.18 247 | 2020-10-10,11059.14,11442.21,11056.94,11296.36,11296.36 248 | 2020-10-09,10925.44,11105.85,10862.97,11079.47,11079.47 249 | 2020-10-08,10677.63,10939.8,10569.82,10923.63,10923.63 250 | 2020-10-07,10619.8,10687.27,10591.96,10679.14,10679.14 251 | 2020-10-06,10799.78,10803.46,10565.2,10621.66,10621.66 252 | 2020-10-05,10688.03,10804,10646.44,10804,10804 253 | 2020-10-04,10567.92,10700.79,10531.34,10684.43,10684.43 254 | 2020-10-03,10583.81,10614.09,10527.98,10565.49,10565.49 255 | 2020-10-02,10624.39,10662.81,10440.31,10585.16,10585.16 256 | 2020-10-01,10785.01,10915.84,10493.55,10623.33,10623.33 257 | 2020-09-30,10845.41,10856.53,10689.67,10787.62,10787.62 258 | 2020-09-29,10712.46,10858.94,10665.34,10848.83,10848.83 259 | 2020-09-28,10771.64,10949.12,10716.68,10721.33,10721.33 260 | 2020-09-27,10752.94,10804.73,10643.46,10774.43,10774.43 261 | 2020-09-26,10702.24,10778.5,10682.08,10754.44,10754.44 262 | 2020-09-25,10747.47,10757.55,10594.05,10702.29,10702.29 263 | 2020-09-24,10227.48,10765.79,10215.21,10745.55,10745.55 264 | 2020-09-23,10539.46,10637.85,10185.77,10225.86,10225.86 265 | 2020-09-22,10459.62,10568.08,10382.73,10538.46,10538.46 266 | 2020-09-21,10934.93,10988.3,10380.26,10462.26,10462.26 267 | 2020-09-20,11095.87,11095.87,10814.48,10938.27,10938.27 268 | 2020-09-19,10933.75,11134.09,10909.62,11094.35,11094.35 269 | 2020-09-18,10951.82,11034.91,10829.66,10944.59,10944.59 270 | 2020-09-17,10973.25,11037.42,10774.63,10948.99,10948.99 271 | 2020-09-16,10797.76,11100.12,10704.88,10974.91,10974.91 272 | 2020-09-15,10677.75,10938.63,10656.46,10796.95,10796.95 273 | 2020-09-14,10328.73,10800.01,10266.01,10680.84,10680.84 274 | 2020-09-13,10452.4,10577.21,10224.33,10323.76,10323.76 275 | 2020-09-12,10409.86,10578.84,10292.39,10442.17,10442.17 276 | 2020-09-11,10369.03,10434.92,10140.84,10400.92,10400.92 277 | 2020-09-10,10242.33,10503.91,10238.14,10363.14,10363.14 278 | 2020-09-09,10134.15,10350.54,10017.25,10242.35,10242.35 279 | 2020-09-08,10369.31,10414.78,9945.11,10131.52,10131.52 280 | 2020-09-07,10281,10399.15,9916.49,10369.56,10369.56 281 | 2020-09-06,10167.22,10353.93,10056.89,10280.35,10280.35 282 | 2020-09-05,10512.53,10581.57,9946.68,10169.57,10169.57 283 | 2020-09-04,10230.37,10663.92,10207.94,10511.81,10511.81 284 | 2020-09-03,11407.19,11443.02,10182.46,10245.3,10245.3 285 | 2020-09-02,11964.82,11964.82,11290.79,11414.03,11414.03 286 | 2020-09-01,11679.32,12067.08,11601.13,11970.48,11970.48 287 | 2020-08-31,11713.31,11768.88,11598.32,11680.82,11680.82 288 | 2020-08-30,11508.71,11715.26,11492.38,11711.51,11711.51 289 | 2020-08-29,11541.05,11585.64,11466.29,11506.87,11506.87 290 | 2020-08-28,11325.3,11545.62,11316.42,11542.5,11542.5 291 | 2020-08-27,11485.61,11570.79,11185.94,11323.4,11323.4 292 | 2020-08-26,11366.89,11530.05,11296.99,11488.36,11488.36 293 | 2020-08-25,11773.59,11778.3,11189.85,11366.13,11366.13 294 | 2020-08-24,11663.69,11807.63,11623.25,11774.6,11774.6 295 | 2020-08-23,11679.7,11713.43,11559.92,11664.85,11664.85 296 | 2020-08-22,11585.48,11689.41,11448.81,11681.83,11681.83 297 | 2020-08-21,11878.03,11899.26,11564.98,11592.49,11592.49 298 | 2020-08-20,11761.5,11900.41,11710.06,11878.37,11878.37 299 | 2020-08-19,11990.88,12028.92,11687.33,11758.28,11758.28 300 | 2020-08-18,12251.9,12335.71,11954.53,11991.23,11991.23 301 | 2020-08-17,11895.66,12359.06,11806.7,12254.4,12254.4 302 | 2020-08-16,11866.69,11934.9,11737.19,11892.8,11892.8 303 | 2020-08-15,11768.7,11963.2,11768.7,11865.7,11865.7 304 | 2020-08-14,11772.66,12150.99,11685.46,11768.87,11768.87 305 | 2020-08-13,11588.41,11796.4,11216.87,11784.14,11784.14 306 | 2020-08-12,11404.6,11748.4,11249.61,11584.93,11584.93 307 | 2020-08-11,11881.65,11932.71,11195.71,11410.53,11410.53 308 | 2020-08-10,11662.26,12045.14,11662.26,11878.11,11878.11 309 | 2020-08-09,11737.33,11806.06,11548.78,11675.74,11675.74 310 | 2020-08-08,11604.55,11800.06,11558.43,11754.05,11754.05 311 | 2020-08-07,11778.89,11898.04,11408.59,11601.47,11601.47 312 | 2020-08-06,11749.87,11902.34,11598.71,11779.77,11779.77 313 | 2020-08-05,11203.82,11786.62,11158.29,11747.02,11747.02 314 | 2020-08-04,11246.2,11385.38,11094.15,11205.89,11205.89 315 | 2020-08-03,11043.77,11453.08,11012.42,11246.35,11246.35 316 | 2020-08-02,11758.76,12034.14,11018.13,11053.61,11053.61 317 | 2020-08-01,11322.57,11794.78,11239.68,11759.59,11759.59 318 | 2020-07-31,11110.21,11415.86,10987.05,11323.47,11323.47 319 | 2020-07-30,11099.83,11169.36,10895.46,11111.21,11111.21 320 | 2020-07-29,10912.95,11304.4,10856.14,11100.47,11100.47 321 | 2020-07-28,11017.46,11204.33,10632.63,10912.82,10912.82 322 | 2020-07-27,9905.22,11298.22,9903.97,10990.87,10990.87 323 | 2020-07-26,9680.23,10023.81,9652.85,9905.17,9905.17 324 | 2020-07-25,9539.49,9704.56,9530.21,9677.11,9677.11 325 | 2020-07-24,9585.51,9623.34,9481.45,9536.89,9536.89 326 | 2020-07-23,9527.14,9610.25,9483,9581.07,9581.07 327 | 2020-07-22,9375.08,9530.52,9319.65,9525.36,9525.36 328 | 2020-07-21,9162.51,9407.26,9149.39,9374.89,9374.89 329 | 2020-07-20,9187.22,9214.27,9137.51,9164.23,9164.23 330 | 2020-07-19,9158.01,9201.4,9097.63,9185.82,9185.82 331 | 2020-07-18,9151.18,9230.98,9100.82,9159.04,9159.04 332 | 2020-07-17,9131.81,9182.25,9089.2,9151.39,9151.39 333 | 2020-07-16,9191.98,9214.31,9088.95,9132.23,9132.23 334 | 2020-07-15,9241.9,9275.33,9171.93,9192.84,9192.84 335 | 2020-07-14,9238.7,9283.84,9171.66,9243.21,9243.21 336 | 2020-07-13,9277.21,9306.41,9224.29,9243.61,9243.61 337 | 2020-07-12,9241.05,9319.42,9197.45,9276.5,9276.5 338 | 2020-07-11,9277.51,9293.53,9199.49,9240.35,9240.35 339 | 2020-07-10,9273.36,9287.47,9118,9278.81,9278.81 340 | 2020-07-09,9427.99,9431.38,9235,9277.97,9277.97 341 | 2020-07-08,9253.02,9450.34,9249.5,9428.33,9428.33 342 | 2020-07-07,9349.16,9360.62,9201.82,9252.28,9252.28 343 | 2020-07-06,9072.85,9375.47,9058.66,9375.47,9375.47 344 | 2020-07-05,9126.09,9162.18,8977.02,9073.94,9073.94 345 | 2020-07-04,9084.23,9183.3,9053.63,9132.49,9132.49 346 | 2020-07-03,9124.84,9202.34,9058.79,9087.3,9087.3 347 | 2020-07-02,9231.14,9274.96,9036.62,9123.41,9123.41 348 | 2020-07-01,9145.99,9309.75,9104.74,9228.33,9228.33 349 | 2020-06-30,9185.58,9217.84,9084.84,9137.99,9137.99 350 | 2020-06-29,9140.03,9237.57,9041.88,9190.85,9190.85 351 | 2020-06-28,9048.46,9197.55,8975.53,9143.58,9143.58 352 | 2020-06-27,9167.82,9207.81,8998.22,9045.39,9045.39 353 | 2020-06-26,9261,9310.52,9101.74,9162.92,9162.92 354 | 2020-06-25,9314.13,9340.16,9095.32,9264.81,9264.81 355 | 2020-06-24,9632.15,9680.37,9278.23,9313.61,9313.61 356 | 2020-06-23,9644.08,9670.54,9547.25,9629.66,9629.66 357 | 2020-06-22,9300.92,9655.07,9296.87,9648.72,9648.72 358 | 2020-06-21,9330.93,9401.11,9300.43,9303.63,9303.63 359 | 2020-06-20,9290.96,9394.97,9247.38,9332.34,9332.34 360 | 2020-06-19,9410.29,9440.88,9274.3,9288.02,9288.02 361 | 2020-06-18,9481.57,9482.78,9328.4,9411.84,9411.84 362 | 2020-06-17,9533.78,9540.42,9327.34,9480.25,9480.25 363 | 2020-06-16,9454.27,9579.43,9400.45,9538.02,9538.02 364 | 2020-06-15,9386.04,9504.86,8990.18,9450.7,9450.7 365 | 2020-06-14,9477.55,9482.27,9347.59,9386.79,9386.79 366 | 2020-06-13,9480.74,9493.21,9396.01,9475.28,9475.28 367 | 2020-06-12,9320.69,9540.47,9285.85,9480.84,9480.84 -------------------------------------------------------------------------------- /python/CausalImpact/data/vw.csv: -------------------------------------------------------------------------------- 1 | Date,VolksWagen,BMW,Allianz 2 | 2011-01-02,99.142822,45.039032,60.006882 3 | 2011-01-09,100.908623,44.75806,63.032661 4 | 2011-01-16,96.084999,42.297653,64.578583 5 | 2011-01-23,96.558739,43.360786,66.296272 6 | 2011-01-30,94.965218,43.170944,69.962891 7 | 2011-02-06,99.831917,47.947468,70.359276 8 | 2011-02-13,97.678513,45.988258,71.383286 9 | 2011-02-20,94.103867,44.575809,67.716675 10 | 2011-02-27,91.433624,43.877167,69.137062 11 | 2011-03-06,91.089073,42.753281,65.946129 12 | 2011-03-13,87.77285,41.9939,62.041691 13 | 2011-03-20,90.701469,43.634163,65.252441 14 | 2011-03-27,93.242485,46.489449,66.527496 15 | 2011-04-03,91.692032,44.454304,68.476425 16 | 2011-04-10,90.012383,44.135361,68.245209 17 | 2011-04-17,95.395897,46.322388,67.518471 18 | 2011-04-24,103.708038,48.349937,70.227142 19 | 2011-05-01,103.105087,47.704464,67.287254 20 | 2011-05-08,103.164993,46.975456,67.789459 21 | 2011-05-15,99.919174,47.279564,66.367401 22 | 2011-05-22,100.708694,47.062473,65.891068 23 | 2011-05-29,101.673668,46.744591,64.192894 24 | 2011-06-05,103.472038,48.334011,63.695862 25 | 2011-06-12,104.261574,49.760624,64.676117 26 | 2011-06-19,107.858315,52.04784,63.419735 27 | 2011-06-26,112.156845,52.544052,67.257912 28 | 2011-07-03,116.89402,53.117794,65.911789 29 | 2011-07-10,120.13987,56.343163,61.707737 30 | 2011-07-17,119.350334,55.498055,64.393089 31 | 2011-07-24,112.025261,54.133469,62.860573 32 | 2011-07-31,95.13813,46.891903,54.604343 33 | 2011-08-07,97.550583,46.008026,52.816418 34 | 2011-08-14,84.225113,40.549709,47.494049 35 | 2011-08-21,87.462158,41.906536,45.6647 36 | 2011-08-28,89.830742,42.038342,46.941788 37 | 2011-09-04,84.014549,40.076759,42.413284 38 | 2011-09-11,91.497543,44.333313,46.182434 39 | 2011-09-18,81.558258,40.456665,40.74271 40 | 2011-09-25,81.751266,38.739319,48.916103 41 | 2011-10-02,83.163628,39.456497,52.71286 42 | 2011-10-09,89.962341,43.759571,53.844982 43 | 2011-10-16,90.137794,44.341064,54.231571 44 | 2011-10-23,102.112312,47.923092,57.37252 45 | 2011-10-30,101.805267,44.860538,52.616215 46 | 2011-11-06,103.033409,45.535072,52.636929 47 | 2011-11-13,96.585602,41.518871,49.737591 48 | 2011-11-20,88.602592,39.014553,45.41618 49 | 2011-11-27,99.655998,43.116051,54.342022 50 | 2011-12-04,96.936501,41.712704,54.804535 51 | 2011-12-11,90.751862,38.758694,50.234612 52 | 2011-12-18,92.725693,40.704777,52.443638 53 | 2011-12-25,90.927322,40.131027,51.021591 54 | 2012-01-01,96.980377,43.06953,51.000874 55 | 2012-01-08,100.313934,45.317982,53.879513 56 | 2012-01-15,107.331955,49.303173,57.952396 57 | 2012-01-22,108.472389,50.086262,59.070721 58 | 2012-01-29,112.200722,54.257526,61.107155 59 | 2012-02-05,111.586639,54.172245,60.044075 60 | 2012-02-12,113.516602,55.808182,61.894123 61 | 2012-02-19,111.060287,54.521145,62.936508 62 | 2012-02-26,114.481583,54.745983,62.915806 63 | 2012-03-04,113.165703,54.660702,61.162388 64 | 2012-03-11,113.867508,56.614529,64.890106 65 | 2012-03-18,108.384674,52.644848,62.943413 66 | 2012-03-25,106.059944,52.280437,61.76297 67 | 2012-04-01,103.252731,51.77647,59.836967 68 | 2012-04-08,102.857971,52.334709,56.523426 69 | 2012-04-15,99.217369,54.148979,58.442539 70 | 2012-04-22,114.51725,55.924484,58.663429 71 | 2012-04-29,115.868217,53.489952,57.966206 72 | 2012-05-06,114.472221,52.412243,55.342983 73 | 2012-05-13,106.59156,47.535423,54.942265 74 | 2012-05-20,109.428589,49.711437,55.292458 75 | 2012-05-27,105.87104,47.1576,51.082954 76 | 2012-06-03,105.87104,47.237915,52.848465 77 | 2012-06-10,105.195557,44.941071,54.497242 78 | 2012-06-17,104.159813,45.350643,55.263275 79 | 2012-06-24,107.041885,45.720066,57.71455 80 | 2012-07-01,112.896088,45.310486,56.817204 81 | 2012-07-08,119.245644,46.394665,57.67807 82 | 2012-07-15,118.480103,46.804241,58.261711 83 | 2012-07-22,112.535828,47.502934,58.130394 84 | 2012-07-29,118.29998,46.675747,60.603569 85 | 2012-08-05,121.227089,48.105251,63.142399 86 | 2012-08-12,121.497261,49.358074,63.908409 87 | 2012-08-19,117.534416,48.225716,63.733322 88 | 2012-08-26,116.633781,46.306324,63.667656 89 | 2012-09-02,115.823189,46.603462,67.36647 90 | 2012-09-09,124.424362,49.791748,70.415985 91 | 2012-09-16,123.163467,48.016911,69.292488 92 | 2012-09-23,117.264229,45.704002,67.548866 93 | 2012-09-30,121.587334,48.980625,67.811493 94 | 2012-10-07,119.831078,48.506798,67.140312 95 | 2012-10-14,124.96476,49.799774,69.701027 96 | 2012-10-21,130.143478,48.964565,68.519165 97 | 2012-10-28,138.339355,52.201023,69.79586 98 | 2012-11-04,130.143478,51.582645,68.139801 99 | 2012-11-11,126.045532,49.783722,67.41024 100 | 2012-11-18,135.862579,52.827438,71.58326 101 | 2012-11-25,140.861176,54.76289,72.918327 102 | 2012-12-02,141.311508,55.445522,74.997551 103 | 2012-12-09,144.1035,57.605839,75.69062 104 | 2012-12-16,146.580292,58.38483,76.857887 105 | 2012-12-23,146.580292,58.569553,76.456635 106 | 2012-12-30,150.903397,60.874424,78.937103 107 | 2013-01-06,148.246475,58.802444,77.040276 108 | 2013-01-13,149.957718,58.890789,75.763565 109 | 2013-01-20,155.586746,60.914577,76.748459 110 | 2013-01-27,156.71257,59.814342,77.003807 111 | 2013-02-03,152.38945,59.027309,74.815163 112 | 2013-02-10,150.723267,57.541588,74.632774 113 | 2013-02-17,141.221451,55.244751,76.018921 114 | 2013-02-24,139.285034,55.574013,75.909477 115 | 2013-03-03,144.1035,58.344685,81.855301 116 | 2013-03-10,136.493042,56.216488,81.891777 117 | 2013-03-17,134.106323,55.887218,79.520744 118 | 2013-03-24,132.169952,54.056168,77.295616 119 | 2013-03-31,131.044128,53.253071,76.821426 120 | 2013-04-07,126.450806,54.128448,78.280518 121 | 2013-04-14,122.713142,52.072529,75.617661 122 | 2013-04-21,128.071991,55.108219,80.979828 123 | 2013-04-28,139.545349,57.919044,84.773491 124 | 2013-05-05,138.761124,57.694176,85.247704 125 | 2013-05-12,148.033401,57.766453,90.63298 126 | 2013-05-19,151.308685,58.932926,88.738472 127 | 2013-05-26,152.27742,61.269291,90.746658 128 | 2013-06-02,149.601837,60.030434,88.586922 129 | 2013-06-09,143.051285,58.226192,86.389297 130 | 2013-06-16,133.871262,53.511898,79.94799 131 | 2013-06-23,138.161423,55.856579,85.063148 132 | 2013-06-30,139.499222,55.041756,83.774879 133 | 2013-07-07,148.356323,58.633606,87.867012 134 | 2013-07-14,151.493195,60.055386,89.155266 135 | 2013-07-21,152.508087,61.660076,88.890045 136 | 2013-07-28,160.903885,60.263245,90.822433 137 | 2013-08-04,161.96489,60.113586,90.064629 138 | 2013-08-11,164.179153,62.799152,87.601784 139 | 2013-08-18,163.348801,62.691074,86.048294 140 | 2013-08-25,155.18367,59.273823,82.145615 141 | 2013-09-01,154.076523,64.603394,84.873703 142 | 2013-09-08,162.426193,66.432571,85.442047 143 | 2013-09-15,155.18367,66.906494,88.397469 144 | 2013-09-22,156.659851,66.598869,89.231049 145 | 2013-09-29,151.216415,66.249649,88.96582 146 | 2013-10-06,155.322052,67.130989,90.519318 147 | 2013-10-13,157.951477,68.203552,93.436852 148 | 2013-10-20,157.213394,69.558807,93.664185 149 | 2013-10-27,167.085388,68.744003,93.550514 150 | 2013-11-03,169.760941,67.987373,94.156761 151 | 2013-11-10,171.421661,67.804459,97.112175 152 | 2013-11-17,173.589798,69.650269,96.013367 153 | 2013-11-24,176.818954,70.315437,96.884834 154 | 2013-12-01,171.790695,68.295013,94.876671 155 | 2013-12-08,168.146393,66.34111,93.057945 156 | 2013-12-15,175.804077,69.833183,97.604752 157 | 2013-12-22,180.832336,71.022156,99.120346 158 | 2013-12-29,177.879974,69.824883,96.922729 159 | 2014-01-05,179.817444,69.134773,97.869972 160 | 2014-01-12,182.077866,71.678993,101.469521 161 | 2014-01-19,170.683578,68.153671,94.53566 162 | 2014-01-26,166.393433,67.197502,93.815758 163 | 2014-02-02,168.377045,68.012321,95.558685 164 | 2014-02-09,180.647797,71.504402,98.248871 165 | 2014-02-16,178.987106,70.855873,97.832092 166 | 2014-02-23,170.775848,70.00779,98.286766 167 | 2014-03-02,165.793716,68.06221,94.118858 168 | 2014-03-09,160.765472,65.900444,91.315002 169 | 2014-03-16,160.903885,73.49987,90.936111 170 | 2014-03-23,170.176132,76.684311,93.209511 171 | 2014-03-30,172.85173,78.03125,93.626297 172 | 2014-04-06,175.481155,75.004791,90.557205 173 | 2014-04-13,176.449921,76.59285,90.216202 174 | 2014-04-20,174.512436,74.464348,91.883347 175 | 2014-04-27,173.958862,74.023689,94.043083 176 | 2014-05-04,173.866592,73.267059,91.580223 177 | 2014-05-11,172.113632,71.861923,96.017281 178 | 2014-05-18,180.447098,77.002655,96.373344 179 | 2014-05-25,182.191238,78.896011,98.430565 180 | 2014-06-01,182.804031,79.572838,98.03495 181 | 2014-06-08,182.04982,77.756569,97.995392 182 | 2014-06-15,183.558258,79.298676,97.32283 183 | 2014-06-22,178.514435,79.127335,96.056847 184 | 2014-06-29,180.352829,81.517601,99.459183 185 | 2014-07-06,173.706253,78.878883,101.041664 186 | 2014-07-13,173.093475,80.19825,102.584595 187 | 2014-07-20,169.180954,80.789383,101.951607 188 | 2014-07-27,161.120224,75.07502,97.085457 189 | 2014-08-03,154.992172,74.012672,96.452461 190 | 2014-08-10,156.264938,73.884163,99.815239 191 | 2014-08-17,162.062973,76.300125,101.476852 192 | 2014-08-24,160.743103,75.906044,102.703285 193 | 2014-08-31,169.03952,78.861748,105.353935 194 | 2014-09-07,164.797043,76.617119,105.274826 195 | 2014-09-14,164.184235,76.240158,109.547531 196 | 2014-09-21,156.406357,73.370125,101.437302 197 | 2014-09-28,147.732819,71.639534,99.142693 198 | 2014-10-05,142.076157,68.135513,97.283264 199 | 2014-10-12,152.682388,69.02652,95.305153 200 | 2014-10-19,152.399536,70.500092,97.362389 201 | 2014-10-26,159.988876,73.09597,100.250427 202 | 2014-11-02,160.790237,71.391083,103.811012 203 | 2014-11-09,158.716141,71.159767,103.811012 204 | 2014-11-16,165.928375,75.529083,107.490303 205 | 2014-11-23,171.490738,78.776077,109.547531 206 | 2014-11-30,174.88472,79.118759,109.864029 207 | 2014-12-07,168.002472,75.374878,106.422119 208 | 2014-12-14,172.103546,77.054054,109.547531 209 | 2014-12-21,171.679291,77.816544,110.536575 210 | 2014-12-28,167.766769,75.400574,108.162857 211 | 2015-01-04,167.295395,75.529083,107.490303 212 | 2015-01-11,176.864563,80.181107,112.752068 213 | 2015-01-18,188.272141,88.071564,116.906075 214 | 2015-01-25,185.868073,88.585609,115.837898 215 | 2015-02-01,199.585419,91.541313,118.013817 216 | 2015-02-08,197.699875,92.355202,117.578651 217 | 2015-02-15,206.279144,95.182404,115.996162 218 | 2015-02-22,208.683212,96.810188,118.369881 219 | 2015-03-01,214.009888,98.780663,119.675438 220 | 2015-03-08,226.925888,102.764442,123.038208 221 | 2015-03-15,228.434341,100.022911,127.983482 222 | 2015-03-22,222.400589,99.466042,126.796608 223 | 2015-03-29,224.191849,98.480797,129.368149 224 | 2015-04-05,230.791275,100.536949,134.273849 225 | 2015-04-12,215.518326,94.582695,127.587868 226 | 2015-04-19,217.969543,94.625526,123.473404 227 | 2015-04-26,214.292725,90.898766,120.743614 228 | 2015-05-03,212.454315,93.811646,119.477631 229 | 2015-05-10,207.402023,87.386192,121.678383 230 | 2015-05-17,221.129288,92.337738,125.859909 231 | 2015-05-24,211.447968,88.725281,118.200684 232 | 2015-05-31,205.475403,87.747276,118.490486 233 | 2015-06-07,204.415756,88.038025,117.993675 234 | 2015-06-14,198.780365,86.117264,116.006409 235 | 2015-06-21,209.376846,91.192314,121.305763 236 | 2015-06-28,203.067123,87.139328,117.248444 237 | 2015-07-05,195.938553,83.879318,121.264374 238 | 2015-07-12,195.264236,84.214127,127.64016 239 | 2015-07-19,182.596649,80.742645,126.480927 240 | 2015-07-26,177.298401,80.443085,123.458633 241 | 2015-08-02,184.523285,81.835197,126.894943 242 | 2015-08-09,173.396957,75.905495,126.232506 243 | 2015-08-16,158.94722,70.601357,115.840805 244 | 2015-08-23,164.245453,73.077217,117.496841 245 | 2015-08-30,154.082474,70.768761,115.882202 246 | 2015-09-06,160.151367,75.359222,116.627434 247 | 2015-09-13,155.431122,75.517815,113.439522 248 | 2015-09-20,111.311218,69.508812,114.557373 249 | 2015-09-27,97.439461,68.909676,115.468185 250 | 2015-10-04,121.281548,77.359283,121.14016 251 | 2015-10-11,116.75396,76.425331,122.837624 252 | 2015-10-18,117.380112,82.196442,129.254822 253 | 2015-10-25,121.474205,82.258118,131.945908 254 | 2015-11-01,117.428276,84.610611,130.248459 255 | 2015-11-08,114.104836,83.297806,130.496872 256 | 2015-11-15,119.354912,87.37722,133.891769 257 | 2015-11-22,129.325241,89.430153,138.528717 258 | 2015-11-29,132.263351,86.496132,134.429993 259 | 2015-12-06,132.552353,82.91893,131.117874 260 | 2015-12-13,135.056961,85.209747,134.09877 261 | 2015-12-20,137.946915,86.830948,134.968201 262 | 2015-12-27,137.079941,86.02034,135.423615 263 | 2016-01-03,120.46273,73.517754,125.694313 264 | 2016-01-10,115.935127,68.742264,123.582832 265 | 2016-01-17,120.414558,70.2313,122.671997 266 | 2016-01-24,116.175964,67.543999,123.086021 267 | 2016-01-31,114.490166,63.799389,114.30896 268 | 2016-02-07,106.542801,61.905048,106.815331 269 | 2016-02-14,115.068146,65.050522,110.996864 270 | 2016-02-21,117.765434,65.103394,114.143356 271 | 2016-02-28,133.419342,72.80407,116.875832 272 | 2016-03-06,125.664619,69.359024,119.773918 273 | 2016-03-13,125.182961,71.878937,120.022324 274 | 2016-03-20,121.811371,70.11676,118.076469 275 | 2016-03-27,118.825089,68.724648,116.089218 276 | 2016-04-03,115.935127,65.46463,115.012772 277 | 2016-04-10,120.270058,69.050652,122.175201 278 | 2016-04-17,131.637177,72.936234,128.509598 279 | 2016-04-24,133.274841,70.927361,122.754822 280 | 2016-05-01,127.061432,66.689339,115.385391 281 | 2016-05-08,131.155533,64.99765,126.639931 282 | 2016-05-15,130.529373,65.961395,126.50219 283 | 2016-05-22,134.91246,69.144478,134.767303 284 | 2016-05-29,129.999557,66.485779,131.00209 285 | 2016-06-05,127.20594,65.041435,123.747154 286 | 2016-06-12,124.460487,63.449902,119.706436 287 | 2016-06-19,122.919182,63.164715,116.446304 288 | 2016-06-26,121.480194,62.364342,116.905479 289 | 2016-07-03,117.334435,62.962318,112.451492 290 | 2016-07-10,122.974594,68.684502,117.548317 291 | 2016-07-17,125.433128,69.457268,115.573875 292 | 2016-07-24,127.89164,70.883209,117.823822 293 | 2016-07-31,126.831116,71.683578,116.12487 294 | 2016-08-07,127.747025,73.256714,123.563484 295 | 2016-08-14,123.312035,71.131599,118.558502 296 | 2016-08-21,125.674164,71.048805,119.017677 297 | 2016-08-28,127.072136,72.281548,124.619583 298 | 2016-09-04,126.975731,70.772812,125.400177 299 | 2016-09-11,122.299698,67.543739,119.38501 300 | 2016-09-18,124.420792,69.540062,125.446098 301 | 2016-09-25,124.517197,68.822487,121.313538 302 | 2016-10-02,126.204422,71.214394,124.711426 303 | 2016-10-09,127.168541,70.69001,126.823624 304 | 2016-10-16,129.096802,72.336746,128.568466 305 | 2016-10-23,130.784027,73.753494,130.313324 306 | 2016-10-30,122.974594,69.420464,125.308342 307 | 2016-11-06,124.083336,73.698296,138.486603 308 | 2016-11-13,123.456657,74.517059,138.440704 309 | 2016-11-20,127.843445,76.163803,138.394775 310 | 2016-11-27,122.974594,73.431511,136.19075 311 | 2016-12-04,130.012741,81.665176,144.409943 312 | 2016-12-11,134.640533,82.796738,143.858932 313 | 2016-12-18,136.761642,82.759941,144.134445 314 | 2016-12-25,131.844574,81.646782,144.180359 315 | 2017-01-01,137.484741,83.265923,147.945587 316 | 2017-01-08,146.306503,80.782013,147.670074 317 | 2017-01-15,144.474655,80.174843,146.246643 318 | 2017-01-22,147.559875,80.41404,148.772095 319 | 2017-01-29,143.606949,77.304558,145.374207 320 | 2017-02-05,141.148407,78.261314,144.042618 321 | 2017-02-12,139.654022,78.22451,149.50676 322 | 2017-02-19,140.714554,77.506943,150.379196 323 | 2017-02-26,142.064346,80.036842,153.777069 324 | 2017-03-05,138.545258,76.853775,155.338257 325 | 2017-03-12,135.845703,76.255798,156.486191 326 | 2017-03-19,134.977997,75.897003,156.210693 -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_cyclic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_cyclic.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_decomp0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_decomp0.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_decomp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_decomp1.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_decomp_fourier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_decomp_fourier.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_gf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_gf.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_gf_yearly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_gf_yearly.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_ma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_ma.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_p_acf_plots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_p_acf_plots.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_ts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_ts.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_daily_yearly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_daily_yearly.png -------------------------------------------------------------------------------- /python/fundamentals/images/basel_hourly_ts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/basel_hourly_ts.png -------------------------------------------------------------------------------- /python/fundamentals/images/beer_ma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/beer_ma.png -------------------------------------------------------------------------------- /python/fundamentals/images/beer_production.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/beer_production.png -------------------------------------------------------------------------------- /python/fundamentals/images/beer_seasonal_decomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/beer_seasonal_decomposed.png -------------------------------------------------------------------------------- /python/fundamentals/images/day_of_year_fourier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/fundamentals/images/day_of_year_fourier.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/ssm_ar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/ssm_ar.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/ssm_es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/ssm_es.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/ssm_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/ssm_structure.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/uc_intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/uc_intro.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/uc_other.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/uc_other.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/uc_seasonal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/uc_seasonal.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/uc_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/uc_structure.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/statsmodels_docs_images/uc_types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/statsmodels_docs_images/uc_types.png -------------------------------------------------------------------------------- /python/intro_forecasting/images/unobserved_components_predictions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/intro_forecasting/images/unobserved_components_predictions.png -------------------------------------------------------------------------------- /python/intro_forecasting/mapping.py: -------------------------------------------------------------------------------- 1 | PARAMS = { 2 | 'irregular': { 3 | 'zeta': 0, 4 | 'beta': 0, 5 | 'beta_1': 0, 6 | 'eta': 0, 7 | 'epsilon': 1, 8 | 'mu_1': 0, 9 | 'mu': 0, 10 | }, 11 | 12 | 'fixed intercept': { 13 | 'zeta': 0, 14 | 'beta': 0, 15 | 'beta_1': 0, 16 | 'eta': 0, 17 | 'epsilon': 0, 18 | 'mu_1': 0, 19 | 'mu': 1, 20 | }, 21 | 22 | 'random walk': { 23 | 'zeta': 0, 24 | 'beta': 0, 25 | 'beta_1': 0, 26 | 'eta': 1, 27 | 'epsilon': 0, 28 | 'mu_1': 1, 29 | 'mu': 1, 30 | }, 31 | 32 | 'local level': { 33 | 'zeta': 0, 34 | 'beta': 0, 35 | 'beta_1': 0, 36 | 'eta': 1, 37 | 'epsilon': 1, 38 | 'mu_1': 1, 39 | 'mu': 1, 40 | }, 41 | 42 | 'smooth trend': { 43 | 'zeta': 1, 44 | 'beta': 0, 45 | 'beta_1': 1, 46 | 'eta': 0, 47 | 'epsilon': 1, 48 | 'mu_1': 1, 49 | 'mu': 1, 50 | }, 51 | 52 | 'local linear trend': { 53 | 'zeta': 1, 54 | 'beta': 0, 55 | 'beta_1': 1, 56 | 'eta': 1, 57 | 'epsilon': 1, 58 | 'mu_1': 1, 59 | 'mu': 1, 60 | }, 61 | 62 | } 63 | -------------------------------------------------------------------------------- /python/prophet/generate_time_series.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def generate_arima_walk(batch_size, n_steps, alpha=0.7, noise=0.1, ma_component=True): 4 | 5 | y = np.zeros([n_steps], dtype=float) 6 | 7 | # Loop through the empty array and add random noise to the dataset. Make the dataset stationary with alpha=0.1 8 | for i in range(1,len(y)): 9 | y[i] = y[i-1]*alpha + np.random.normal(0,noise,1) 10 | return y 11 | 12 | 13 | def create_impulse_series(y, impulse): 14 | # Convolve 15 | y_convolved = np.convolve(y, impulse, mode="full") 16 | # Clip the end 17 | y_convolved = y_convolved[:len(y)] 18 | return y_convolved 19 | 20 | 21 | def straight_line(n_steps, gradient, intercept): 22 | t = np.arange(0,n_steps) 23 | y = gradient*t + intercept 24 | return y -------------------------------------------------------------------------------- /python/prophet/prophet_test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import fbprophet 3 | import pandas as pd 4 | import matplotlib.pyplot as plt 5 | import sys 6 | import os 7 | import statsmodels.tsa.stattools as sm 8 | import generate_time_series as gts 9 | 10 | # Import time series generating functions 11 | #sys.path.append("/Users/aaronpickering/Desktop/rnn/py/") 12 | 13 | # Load the sample data 14 | sample_data = pd.read_csv("./data/sample_data_1.csv") 15 | # Rename columns to prophet format 16 | sample_data.columns = ['ds','media','y'] 17 | # Convert the date object to datetime 18 | sample_data['ds'] = pd.to_datetime(sample_data['ds']) 19 | 20 | # Add a media variable at lag 1 and 2 21 | sample_data['media_lag_1'] = sample_data['media'].shift(1) 22 | sample_data['media_lag_2'] = sample_data['media'].shift(2) 23 | 24 | # Add a 31 day lag variable 25 | sample_data['y_lag_31'] = sample_data['y'].shift(31) 26 | 27 | # Fill NA values with zeroes 28 | sample_data.loc[0,'media_lag_1'] = 0 29 | sample_data.loc[0:1,'media_lag_2'] = 0 30 | 31 | # Fill the y_lag_31 values with the first genuine data point 32 | sample_data.loc[0:30,'y_lag_31'] = 6.258472 33 | 34 | # Add a 7th of July dummy to account for the negative spike 35 | sample_data['seven_seven'] = sample_data['ds'].isin(["2018-07-07","2019-07-07","2020-07-07","2021-07-07"]) 36 | sample_data['seven_seven'] = sample_data['seven_seven'].astype(int) 37 | 38 | # Add the structure break variable to the dataset 39 | struct_break = np.where(sample_data['ds'] == "2020-01-31") 40 | struct_break = np.concatenate([np.repeat(0, struct_break[-1]), np.repeat(1, sample_data.shape[0] - struct_break[-1])]) 41 | sample_data['struct_break'] = struct_break 42 | 43 | # Split into training and test sets 44 | train_indices = np.where(~(sample_data['y'].isnull()))[-1] 45 | test_indices = np.where(sample_data['y'].isnull())[-1] 46 | 47 | train = sample_data.iloc[train_indices,:] 48 | test = sample_data.iloc[test_indices,:] 49 | 50 | # Drop the na values from the lagged terms 51 | train = train.dropna() 52 | 53 | 54 | #-------- Exploratory analysis 55 | # Plot the sample Sales over time 56 | 57 | plt.plot(sample_data['ds'],sample_data['y']) 58 | plt.xlabel("Date") 59 | plt.ylabel("Sales") 60 | plt.show() 61 | 62 | 63 | # Non-stationarity tests (ADF, KPSS) - eyeball it to start with 64 | # ACF - Clearly autocorrelation 65 | acf_values = sm.acf(train['y']) 66 | plt.plot(acf_values) 67 | plt.show() 68 | # PACF 69 | acf_values = sm.pacf(train['y']) 70 | plt.plot(acf_values) 71 | plt.show() 72 | 73 | # Trend, seasonality remainder. 74 | # What is happening in January 2020? 75 | # Media Cross correlation (after removing seasonality) 76 | sm.ccf(train['media'], train['y']) 77 | 78 | 79 | # Calculate the errors - Error (MAPE?) 80 | 81 | # Start with a default prophet model 82 | prophet_model = fbprophet.Prophet() 83 | prophet_model.fit(train) 84 | 85 | 86 | future = prophet_model.make_future_dataframe(periods=60) 87 | future.tail() 88 | 89 | # Check the fit 90 | fit = prophet_model.predict(train) 91 | 92 | # Plot the forecast 93 | fit_plot = prophet_model.plot(fit) 94 | fit_plot.show() 95 | 96 | y_f = prophet_model.predict(test) 97 | forecast_plot = prophet_model.plot(y_f) 98 | forecast_plot.show() 99 | 100 | # Plot the fit components 101 | comp_plot = prophet_model.plot_components(fit) 102 | comp_plot.show() 103 | 104 | # Add the external regressor (Media) and retrain. Disable weekly seasonality. 105 | prophet_model = fbprophet.Prophet(weekly_seasonality=False) 106 | prophet_model.add_regressor("media") 107 | prophet_model.fit(train) 108 | 109 | fit_x = prophet_model.predict(train) 110 | 111 | # Plot the new fit 112 | fit_plot = prophet_model.plot(fit_x) 113 | fit_plot.show() 114 | 115 | plt.plot(train['y']) 116 | plt.plot(fit_x['yhat']) 117 | plt.show() 118 | 119 | 120 | # Lets look at the changepoint detection 121 | fit_plot = prophet_model.plot(fit_x) 122 | a = fbprophet.plot.add_changepoints_to_plot(fit_plot.gca(), prophet_model, fit_x) 123 | fit_plot.show() 124 | 125 | # This plot shows that Prophet is detecting a liner structure after 2020-01, but before we have an unusual combination of piecewise linear terms 126 | # This suggests to me that we are probably overfitting still missing something at around 2020-01. 127 | # Lets look at the residuals over time to double check. 128 | 129 | res = train['y'] - fit_x['yhat'] 130 | plt.plot(train['ds'], res) 131 | plt.show() 132 | 133 | # Play around with change point prior 134 | prophet_model = fbprophet.Prophet(changepoint_prior_scale=0.2, weekly_seasonality=False) 135 | prophet_model.add_regressor("media") 136 | prophet_model.add_regressor("media_lag_1") 137 | prophet_model.add_regressor("media_lag_2") 138 | fit_xc = prophet_model.fit(train) 139 | 140 | fit_xc = fit_xc.predict(train) 141 | fit_plot = prophet_model.plot(fit_xc) 142 | a = fbprophet.plot.add_changepoints_to_plot(fit_plot.gca(), prophet_model, fit_xc) 143 | fit_plot.show() 144 | 145 | # Seems to be a discontinuity at 2020-01. Lets specifiy a change point at 2020-01 and assume liner otherwise. 146 | prophet_model = fbprophet.Prophet(changepoints=["2019-12-15","2020-03-01"], weekly_seasonality=False) 147 | prophet_model.add_seasonality("yearly", period=365.25, fourier_order=12, mode="multiplicative") 148 | prophet_model.add_regressor("struct_break") 149 | prophet_model.add_regressor("media") 150 | prophet_model.add_regressor("media_lag_1") 151 | prophet_model.add_regressor("media_lag_2") 152 | prophet_model.add_regressor("media_lag_1") 153 | prophet_model.add_regressor("seven_seven") 154 | fit_xc = prophet_model.fit(train) 155 | 156 | fit_xc = fit_xc.predict(train) 157 | fit_plot = prophet_model.plot(fit_xc) 158 | a = fbprophet.plot.add_changepoints_to_plot(fit_plot.gca(), prophet_model, fit_xc) 159 | fit_plot.show() 160 | 161 | prophet_model.plot_components(fit_xc) 162 | plt.show() 163 | plt.plot(fit_xc['multiplicative_terms']) 164 | plt.show() 165 | 166 | # Plot the residuals again 167 | res = train['y'] - fit_xc['yhat'] 168 | plt.plot(train['ds'], res) 169 | plt.show() 170 | 171 | # The change is still not really picked up as seen by the residuals. Add a dummy variable for the changepoint 172 | 173 | 174 | # plot the dummy variable 175 | plt.plot(train['y']) 176 | plt.plot(train['struct_break']) 177 | plt.show() 178 | 179 | # Add the regressor and retrain 180 | prophet_model = fbprophet.Prophet(seasonality_mode="multiplicative", changepoints=[]) 181 | prophet_model.add_regressor("media") 182 | prophet_model.add_regressor("struct_break") 183 | prophet_model.add_regressor("media_lag_1") 184 | prophet_model.add_regressor("y_lag_31") 185 | prophet_model.add_seasonality('yearly', period=365.25, fourier_order=12, mode='multiplicative') 186 | prophet_model.add_seasonality('yearly', period=365.25, fourier_order=12, mode='additive') 187 | train = train.dropna() 188 | fit_xc = prophet_model.fit(train) 189 | 190 | fit_xc = fit_xc.predict(train) 191 | fit_plot = prophet_model.plot(fit_xc) 192 | a = fbprophet.plot.add_changepoints_to_plot(fit_plot.gca(), prophet_model, fit_xc) 193 | fit_plot.show() 194 | 195 | fig1 = prophet_model.plot_components(fit_xc) 196 | fig1.show() 197 | 198 | 199 | # Plot the residuals again 200 | res = train['y'] - fit_xc['yhat'] 201 | plt.plot(res) 202 | plt.show() 203 | plt.hist(res) 204 | plt.show() 205 | 206 | # Plot the fit components 207 | comp_plot = prophet_model.plot_components(fit_xc) 208 | comp_plot.show() 209 | 210 | # Add a new variable for the 'struct break' in the test set. 211 | test['struct_break'] = 1 212 | 213 | # Create the forecasts and plot 214 | forecast = prophet_model.predict(test) 215 | plt.plot(forecast['yhat'].dropna()) 216 | plt.show() 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | # Try prophet default on an AR type time series 234 | # Prophet trends the trend as a completely deterministic (but unexplained) piecewise linear function. 235 | # This would appear to be suitable for the situation where the majority of the variation is caused by external regressors 236 | # Consider the structure of the time series, if there is autocorrelation you might need to add lagged regressors. 237 | y_arima = gts.generate_arima_walk(1, 200, alpha=0.6) 238 | 239 | plt.plot(y_arima) 240 | plt.show() 241 | 242 | ds = np.arange(1, y_arima.shape[0] + 1) 243 | 244 | df = pd.concat([pd.Series(y_arima), pd.Series(ds)], axis=1) 245 | df.columns = ['y','ds'] 246 | 247 | 248 | df['ds'] = pd.to_datetime(df['ds']) 249 | df['y_1'] = df['y'].shift(1) 250 | df['y_1'][0] = 0 251 | 252 | arima_model = fbprophet.Prophet() 253 | arima_model.add_regressor('y_1') 254 | arima_model.fit(df) 255 | 256 | forecast = arima_model.predict(df) 257 | 258 | 259 | plt.plot(forecast['yhat']) 260 | plt.plot(df['y']) 261 | plt.show() 262 | -------------------------------------------------------------------------------- /python/rocket_minirocket/demo_default.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "basic-donna", 6 | "metadata": {}, 7 | "source": [ 8 | "# Demo \\#1\n", 9 | "\n", 10 | "# [github.com/angus924/minirocket](https://github.com/angus924/minirocket)" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "physical-fabric", 16 | "metadata": {}, 17 | "source": [ 18 | "***" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "id": "chinese-liverpool", 24 | "metadata": {}, 25 | "source": [ 26 | "# Imports" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "id": "controlled-sacramento", 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "import numpy as np\n", 37 | "\n", 38 | "from minirocket import fit, transform\n", 39 | "\n", 40 | "from sklearn.linear_model import RidgeClassifierCV" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "martial-consultation", 46 | "metadata": {}, 47 | "source": [ 48 | "# Load Data\n", 49 | "\n", 50 | "Note: `np.float32`" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "id": "present-executive", 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "dataset = \"ACSF1\"\n", 61 | "\n", 62 | "# load training data\n", 63 | "training_data = np.loadtxt(f\"./data/{dataset}_TRAIN.txt\")\n", 64 | "X_training, Y_training = training_data[:, 1:].astype(np.float32), training_data[:, 0]\n", 65 | "\n", 66 | "# load test data\n", 67 | "test_data = np.loadtxt(f\"./data/{dataset}_TEST.txt\")\n", 68 | "X_test, Y_test = test_data[:, 1:].astype(np.float32), test_data[:, 0]" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "faced-tonight", 74 | "metadata": {}, 75 | "source": [ 76 | "# Transform, Train, Test" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "id": "sitting-oxygen", 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "# transform training set\n", 87 | "parameters = fit(X_training)\n", 88 | "X_training_transform = transform(X_training, parameters)\n", 89 | "\n", 90 | "# train classifier\n", 91 | "classifier = RidgeClassifierCV(alphas = np.logspace(-3, 3, 10), normalize = True)\n", 92 | "classifier.fit(X_training_transform, Y_training)\n", 93 | "\n", 94 | "# transform test set\n", 95 | "X_test_transform = transform(X_test, parameters)\n", 96 | "\n", 97 | "# predict\n", 98 | "accuracy = classifier.score(X_test_transform, Y_test)\n", 99 | "print(f\"accuracy = {round(accuracy, 2)}\")" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "automatic-lightning", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.7.9" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 5 132 | } 133 | -------------------------------------------------------------------------------- /python/rocket_minirocket/demo_sktime.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "suburban-broadcasting", 6 | "metadata": {}, 7 | "source": [ 8 | "# Demo \\#2\n", 9 | "\n", 10 | "# [github.com/alan-turing-institute/sktime](https://github.com/alan-turing-institute/sktime)" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "processed-chuck", 16 | "metadata": {}, 17 | "source": [ 18 | "***" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "id": "checked-coach", 24 | "metadata": {}, 25 | "source": [ 26 | "# Imports" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "id": "therapeutic-jordan", 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "import numpy as np\n", 37 | "\n", 38 | "from sktime.transformations.panel.rocket import MiniRocket\n", 39 | "\n", 40 | "from sklearn.linear_model import RidgeClassifierCV" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "id": "derived-potato", 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "from sktime.datasets.base import load_acsf1" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "id": "efficient-xerox", 56 | "metadata": {}, 57 | "source": [ 58 | "# Load Data" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "id": "specified-reconstruction", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "X_training, Y_training = load_acsf1(split = \"train\", return_X_y = True)\n", 69 | "\n", 70 | "X_test, Y_test = load_acsf1(split = \"test\", return_X_y = True)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "id": "domestic-kingston", 76 | "metadata": {}, 77 | "source": [ 78 | "# Transform, Train, Test" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "id": "hungry-cycling", 85 | "metadata": {}, 86 | "outputs": [], 87 | "source": [ 88 | "minirocket = MiniRocket()\n", 89 | "\n", 90 | "# transform training set\n", 91 | "X_training_transform = minirocket.fit_transform(X_training)\n", 92 | "\n", 93 | "# train classifier\n", 94 | "classifier = RidgeClassifierCV(alphas = np.logspace(-3, 3, 10), normalize = True)\n", 95 | "classifier.fit(X_training_transform, Y_training)\n", 96 | "\n", 97 | "# transform test set\n", 98 | "X_test_transform = minirocket.transform(X_test)\n", 99 | "\n", 100 | "# predict\n", 101 | "accuracy = classifier.score(X_test_transform, Y_test)\n", 102 | "print(f\"accuracy = {round(accuracy, 2)}\")" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "id": "developmental-principle", 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [] 112 | } 113 | ], 114 | "metadata": { 115 | "kernelspec": { 116 | "display_name": "Python 3", 117 | "language": "python", 118 | "name": "python3" 119 | }, 120 | "language_info": { 121 | "codemirror_mode": { 122 | "name": "ipython", 123 | "version": 3 124 | }, 125 | "file_extension": ".py", 126 | "mimetype": "text/x-python", 127 | "name": "python", 128 | "nbconvert_exporter": "python", 129 | "pygments_lexer": "ipython3", 130 | "version": "3.7.9" 131 | } 132 | }, 133 | "nbformat": 4, 134 | "nbformat_minor": 5 135 | } 136 | -------------------------------------------------------------------------------- /python/rocket_minirocket/presentation_berlin_slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanitorduz/btsa/8a1d7d8148376d939301e856019a7751e7cd99c8/python/rocket_minirocket/presentation_berlin_slides.pdf -------------------------------------------------------------------------------- /renv/.gitignore: -------------------------------------------------------------------------------- 1 | local/ 2 | lock/ 3 | library/ 4 | python/ 5 | staging/ 6 | -------------------------------------------------------------------------------- /renv/activate.R: -------------------------------------------------------------------------------- 1 | 2 | local({ 3 | 4 | # the requested version of renv 5 | version <- "0.14.0" 6 | 7 | # the project directory 8 | project <- getwd() 9 | 10 | # allow environment variable to control activation 11 | activate <- Sys.getenv("RENV_ACTIVATE_PROJECT") 12 | if (!nzchar(activate)) { 13 | 14 | # don't auto-activate when R CMD INSTALL is running 15 | if (nzchar(Sys.getenv("R_INSTALL_PKG"))) 16 | return(FALSE) 17 | 18 | } 19 | 20 | # bail if activation was explicitly disabled 21 | if (tolower(activate) %in% c("false", "f", "0")) 22 | return(FALSE) 23 | 24 | # avoid recursion 25 | if (nzchar(Sys.getenv("RENV_R_INITIALIZING"))) 26 | return(invisible(TRUE)) 27 | 28 | # signal that we're loading renv during R startup 29 | Sys.setenv("RENV_R_INITIALIZING" = "true") 30 | on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE) 31 | 32 | # signal that we've consented to use renv 33 | options(renv.consent = TRUE) 34 | 35 | # load the 'utils' package eagerly -- this ensures that renv shims, which 36 | # mask 'utils' packages, will come first on the search path 37 | library(utils, lib.loc = .Library) 38 | 39 | # check to see if renv has already been loaded 40 | if ("renv" %in% loadedNamespaces()) { 41 | 42 | # if renv has already been loaded, and it's the requested version of renv, 43 | # nothing to do 44 | spec <- .getNamespaceInfo(.getNamespace("renv"), "spec") 45 | if (identical(spec[["version"]], version)) 46 | return(invisible(TRUE)) 47 | 48 | # otherwise, unload and attempt to load the correct version of renv 49 | unloadNamespace("renv") 50 | 51 | } 52 | 53 | # load bootstrap tools 54 | bootstrap <- function(version, library) { 55 | 56 | # attempt to download renv 57 | tarball <- tryCatch(renv_bootstrap_download(version), error = identity) 58 | if (inherits(tarball, "error")) 59 | stop("failed to download renv ", version) 60 | 61 | # now attempt to install 62 | status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity) 63 | if (inherits(status, "error")) 64 | stop("failed to install renv ", version) 65 | 66 | } 67 | 68 | renv_bootstrap_tests_running <- function() { 69 | getOption("renv.tests.running", default = FALSE) 70 | } 71 | 72 | renv_bootstrap_repos <- function() { 73 | 74 | # check for repos override 75 | repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) 76 | if (!is.na(repos)) 77 | return(repos) 78 | 79 | # if we're testing, re-use the test repositories 80 | if (renv_bootstrap_tests_running()) 81 | return(getOption("renv.tests.repos")) 82 | 83 | # retrieve current repos 84 | repos <- getOption("repos") 85 | 86 | # ensure @CRAN@ entries are resolved 87 | repos[repos == "@CRAN@"] <- getOption( 88 | "renv.repos.cran", 89 | "https://cloud.r-project.org" 90 | ) 91 | 92 | # add in renv.bootstrap.repos if set 93 | default <- c(FALLBACK = "https://cloud.r-project.org") 94 | extra <- getOption("renv.bootstrap.repos", default = default) 95 | repos <- c(repos, extra) 96 | 97 | # remove duplicates that might've snuck in 98 | dupes <- duplicated(repos) | duplicated(names(repos)) 99 | repos[!dupes] 100 | 101 | } 102 | 103 | renv_bootstrap_download <- function(version) { 104 | 105 | # if the renv version number has 4 components, assume it must 106 | # be retrieved via github 107 | nv <- numeric_version(version) 108 | components <- unclass(nv)[[1]] 109 | 110 | methods <- if (length(components) == 4L) { 111 | list( 112 | renv_bootstrap_download_github 113 | ) 114 | } else { 115 | list( 116 | renv_bootstrap_download_cran_latest, 117 | renv_bootstrap_download_cran_archive 118 | ) 119 | } 120 | 121 | for (method in methods) { 122 | path <- tryCatch(method(version), error = identity) 123 | if (is.character(path) && file.exists(path)) 124 | return(path) 125 | } 126 | 127 | stop("failed to download renv ", version) 128 | 129 | } 130 | 131 | renv_bootstrap_download_impl <- function(url, destfile) { 132 | 133 | mode <- "wb" 134 | 135 | # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 136 | fixup <- 137 | Sys.info()[["sysname"]] == "Windows" && 138 | substring(url, 1L, 5L) == "file:" 139 | 140 | if (fixup) 141 | mode <- "w+b" 142 | 143 | utils::download.file( 144 | url = url, 145 | destfile = destfile, 146 | mode = mode, 147 | quiet = TRUE 148 | ) 149 | 150 | } 151 | 152 | renv_bootstrap_download_cran_latest <- function(version) { 153 | 154 | spec <- renv_bootstrap_download_cran_latest_find(version) 155 | 156 | message("* Downloading renv ", version, " ... ", appendLF = FALSE) 157 | 158 | type <- spec$type 159 | repos <- spec$repos 160 | 161 | info <- tryCatch( 162 | utils::download.packages( 163 | pkgs = "renv", 164 | destdir = tempdir(), 165 | repos = repos, 166 | type = type, 167 | quiet = TRUE 168 | ), 169 | condition = identity 170 | ) 171 | 172 | if (inherits(info, "condition")) { 173 | message("FAILED") 174 | return(FALSE) 175 | } 176 | 177 | # report success and return 178 | message("OK (downloaded ", type, ")") 179 | info[1, 2] 180 | 181 | } 182 | 183 | renv_bootstrap_download_cran_latest_find <- function(version) { 184 | 185 | # check whether binaries are supported on this system 186 | binary <- 187 | getOption("renv.bootstrap.binary", default = TRUE) && 188 | !identical(.Platform$pkgType, "source") && 189 | !identical(getOption("pkgType"), "source") && 190 | Sys.info()[["sysname"]] %in% c("Darwin", "Windows") 191 | 192 | types <- c(if (binary) "binary", "source") 193 | 194 | # iterate over types + repositories 195 | for (type in types) { 196 | for (repos in renv_bootstrap_repos()) { 197 | 198 | # retrieve package database 199 | db <- tryCatch( 200 | as.data.frame( 201 | utils::available.packages(type = type, repos = repos), 202 | stringsAsFactors = FALSE 203 | ), 204 | error = identity 205 | ) 206 | 207 | if (inherits(db, "error")) 208 | next 209 | 210 | # check for compatible entry 211 | entry <- db[db$Package %in% "renv" & db$Version %in% version, ] 212 | if (nrow(entry) == 0) 213 | next 214 | 215 | # found it; return spec to caller 216 | spec <- list(entry = entry, type = type, repos = repos) 217 | return(spec) 218 | 219 | } 220 | } 221 | 222 | # if we got here, we failed to find renv 223 | fmt <- "renv %s is not available from your declared package repositories" 224 | stop(sprintf(fmt, version)) 225 | 226 | } 227 | 228 | renv_bootstrap_download_cran_archive <- function(version) { 229 | 230 | name <- sprintf("renv_%s.tar.gz", version) 231 | repos <- renv_bootstrap_repos() 232 | urls <- file.path(repos, "src/contrib/Archive/renv", name) 233 | destfile <- file.path(tempdir(), name) 234 | 235 | message("* Downloading renv ", version, " ... ", appendLF = FALSE) 236 | 237 | for (url in urls) { 238 | 239 | status <- tryCatch( 240 | renv_bootstrap_download_impl(url, destfile), 241 | condition = identity 242 | ) 243 | 244 | if (identical(status, 0L)) { 245 | message("OK") 246 | return(destfile) 247 | } 248 | 249 | } 250 | 251 | message("FAILED") 252 | return(FALSE) 253 | 254 | } 255 | 256 | renv_bootstrap_download_github <- function(version) { 257 | 258 | enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") 259 | if (!identical(enabled, "TRUE")) 260 | return(FALSE) 261 | 262 | # prepare download options 263 | pat <- Sys.getenv("GITHUB_PAT") 264 | if (nzchar(Sys.which("curl")) && nzchar(pat)) { 265 | fmt <- "--location --fail --header \"Authorization: token %s\"" 266 | extra <- sprintf(fmt, pat) 267 | saved <- options("download.file.method", "download.file.extra") 268 | options(download.file.method = "curl", download.file.extra = extra) 269 | on.exit(do.call(base::options, saved), add = TRUE) 270 | } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { 271 | fmt <- "--header=\"Authorization: token %s\"" 272 | extra <- sprintf(fmt, pat) 273 | saved <- options("download.file.method", "download.file.extra") 274 | options(download.file.method = "wget", download.file.extra = extra) 275 | on.exit(do.call(base::options, saved), add = TRUE) 276 | } 277 | 278 | message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE) 279 | 280 | url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) 281 | name <- sprintf("renv_%s.tar.gz", version) 282 | destfile <- file.path(tempdir(), name) 283 | 284 | status <- tryCatch( 285 | renv_bootstrap_download_impl(url, destfile), 286 | condition = identity 287 | ) 288 | 289 | if (!identical(status, 0L)) { 290 | message("FAILED") 291 | return(FALSE) 292 | } 293 | 294 | message("OK") 295 | return(destfile) 296 | 297 | } 298 | 299 | renv_bootstrap_install <- function(version, tarball, library) { 300 | 301 | # attempt to install it into project library 302 | message("* Installing renv ", version, " ... ", appendLF = FALSE) 303 | dir.create(library, showWarnings = FALSE, recursive = TRUE) 304 | 305 | # invoke using system2 so we can capture and report output 306 | bin <- R.home("bin") 307 | exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" 308 | r <- file.path(bin, exe) 309 | args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(library), shQuote(tarball)) 310 | output <- system2(r, args, stdout = TRUE, stderr = TRUE) 311 | message("Done!") 312 | 313 | # check for successful install 314 | status <- attr(output, "status") 315 | if (is.numeric(status) && !identical(status, 0L)) { 316 | header <- "Error installing renv:" 317 | lines <- paste(rep.int("=", nchar(header)), collapse = "") 318 | text <- c(header, lines, output) 319 | writeLines(text, con = stderr()) 320 | } 321 | 322 | status 323 | 324 | } 325 | 326 | renv_bootstrap_platform_prefix <- function() { 327 | 328 | # construct version prefix 329 | version <- paste(R.version$major, R.version$minor, sep = ".") 330 | prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-") 331 | 332 | # include SVN revision for development versions of R 333 | # (to avoid sharing platform-specific artefacts with released versions of R) 334 | devel <- 335 | identical(R.version[["status"]], "Under development (unstable)") || 336 | identical(R.version[["nickname"]], "Unsuffered Consequences") 337 | 338 | if (devel) 339 | prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") 340 | 341 | # build list of path components 342 | components <- c(prefix, R.version$platform) 343 | 344 | # include prefix if provided by user 345 | prefix <- renv_bootstrap_platform_prefix_impl() 346 | if (!is.na(prefix) && nzchar(prefix)) 347 | components <- c(prefix, components) 348 | 349 | # build prefix 350 | paste(components, collapse = "/") 351 | 352 | } 353 | 354 | renv_bootstrap_platform_prefix_impl <- function() { 355 | 356 | # if an explicit prefix has been supplied, use it 357 | prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) 358 | if (!is.na(prefix)) 359 | return(prefix) 360 | 361 | # if the user has requested an automatic prefix, generate it 362 | auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) 363 | if (auto %in% c("TRUE", "True", "true", "1")) 364 | return(renv_bootstrap_platform_prefix_auto()) 365 | 366 | # empty string on failure 367 | "" 368 | 369 | } 370 | 371 | renv_bootstrap_platform_prefix_auto <- function() { 372 | 373 | prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) 374 | if (inherits(prefix, "error") || prefix %in% "unknown") { 375 | 376 | msg <- paste( 377 | "failed to infer current operating system", 378 | "please file a bug report at https://github.com/rstudio/renv/issues", 379 | sep = "; " 380 | ) 381 | 382 | warning(msg) 383 | 384 | } 385 | 386 | prefix 387 | 388 | } 389 | 390 | renv_bootstrap_platform_os <- function() { 391 | 392 | sysinfo <- Sys.info() 393 | sysname <- sysinfo[["sysname"]] 394 | 395 | # handle Windows + macOS up front 396 | if (sysname == "Windows") 397 | return("windows") 398 | else if (sysname == "Darwin") 399 | return("macos") 400 | 401 | # check for os-release files 402 | for (file in c("/etc/os-release", "/usr/lib/os-release")) 403 | if (file.exists(file)) 404 | return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) 405 | 406 | # check for redhat-release files 407 | if (file.exists("/etc/redhat-release")) 408 | return(renv_bootstrap_platform_os_via_redhat_release()) 409 | 410 | "unknown" 411 | 412 | } 413 | 414 | renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { 415 | 416 | # read /etc/os-release 417 | release <- utils::read.table( 418 | file = file, 419 | sep = "=", 420 | quote = c("\"", "'"), 421 | col.names = c("Key", "Value"), 422 | comment.char = "#", 423 | stringsAsFactors = FALSE 424 | ) 425 | 426 | vars <- as.list(release$Value) 427 | names(vars) <- release$Key 428 | 429 | # get os name 430 | os <- tolower(sysinfo[["sysname"]]) 431 | 432 | # read id 433 | id <- "unknown" 434 | for (field in c("ID", "ID_LIKE")) { 435 | if (field %in% names(vars) && nzchar(vars[[field]])) { 436 | id <- vars[[field]] 437 | break 438 | } 439 | } 440 | 441 | # read version 442 | version <- "unknown" 443 | for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { 444 | if (field %in% names(vars) && nzchar(vars[[field]])) { 445 | version <- vars[[field]] 446 | break 447 | } 448 | } 449 | 450 | # join together 451 | paste(c(os, id, version), collapse = "-") 452 | 453 | } 454 | 455 | renv_bootstrap_platform_os_via_redhat_release <- function() { 456 | 457 | # read /etc/redhat-release 458 | contents <- readLines("/etc/redhat-release", warn = FALSE) 459 | 460 | # infer id 461 | id <- if (grepl("centos", contents, ignore.case = TRUE)) 462 | "centos" 463 | else if (grepl("redhat", contents, ignore.case = TRUE)) 464 | "redhat" 465 | else 466 | "unknown" 467 | 468 | # try to find a version component (very hacky) 469 | version <- "unknown" 470 | 471 | parts <- strsplit(contents, "[[:space:]]")[[1L]] 472 | for (part in parts) { 473 | 474 | nv <- tryCatch(numeric_version(part), error = identity) 475 | if (inherits(nv, "error")) 476 | next 477 | 478 | version <- nv[1, 1] 479 | break 480 | 481 | } 482 | 483 | paste(c("linux", id, version), collapse = "-") 484 | 485 | } 486 | 487 | renv_bootstrap_library_root_name <- function(project) { 488 | 489 | # use project name as-is if requested 490 | asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE") 491 | if (asis) 492 | return(basename(project)) 493 | 494 | # otherwise, disambiguate based on project's path 495 | id <- substring(renv_bootstrap_hash_text(project), 1L, 8L) 496 | paste(basename(project), id, sep = "-") 497 | 498 | } 499 | 500 | renv_bootstrap_library_root <- function(project) { 501 | 502 | path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) 503 | if (!is.na(path)) 504 | return(path) 505 | 506 | path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) 507 | if (!is.na(path)) { 508 | name <- renv_bootstrap_library_root_name(project) 509 | return(file.path(path, name)) 510 | } 511 | 512 | prefix <- renv_bootstrap_profile_prefix() 513 | paste(c(project, prefix, "renv/library"), collapse = "/") 514 | 515 | } 516 | 517 | renv_bootstrap_validate_version <- function(version) { 518 | 519 | loadedversion <- utils::packageDescription("renv", fields = "Version") 520 | if (version == loadedversion) 521 | return(TRUE) 522 | 523 | # assume four-component versions are from GitHub; three-component 524 | # versions are from CRAN 525 | components <- strsplit(loadedversion, "[.-]")[[1]] 526 | remote <- if (length(components) == 4L) 527 | paste("rstudio/renv", loadedversion, sep = "@") 528 | else 529 | paste("renv", loadedversion, sep = "@") 530 | 531 | fmt <- paste( 532 | "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", 533 | "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", 534 | "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", 535 | sep = "\n" 536 | ) 537 | 538 | msg <- sprintf(fmt, loadedversion, version, remote) 539 | warning(msg, call. = FALSE) 540 | 541 | FALSE 542 | 543 | } 544 | 545 | renv_bootstrap_hash_text <- function(text) { 546 | 547 | hashfile <- tempfile("renv-hash-") 548 | on.exit(unlink(hashfile), add = TRUE) 549 | 550 | writeLines(text, con = hashfile) 551 | tools::md5sum(hashfile) 552 | 553 | } 554 | 555 | renv_bootstrap_load <- function(project, libpath, version) { 556 | 557 | # try to load renv from the project library 558 | if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) 559 | return(FALSE) 560 | 561 | # warn if the version of renv loaded does not match 562 | renv_bootstrap_validate_version(version) 563 | 564 | # load the project 565 | renv::load(project) 566 | 567 | TRUE 568 | 569 | } 570 | 571 | renv_bootstrap_profile_load <- function(project) { 572 | 573 | # if RENV_PROFILE is already set, just use that 574 | profile <- Sys.getenv("RENV_PROFILE", unset = NA) 575 | if (!is.na(profile) && nzchar(profile)) 576 | return(profile) 577 | 578 | # check for a profile file (nothing to do if it doesn't exist) 579 | path <- file.path(project, "renv/local/profile") 580 | if (!file.exists(path)) 581 | return(NULL) 582 | 583 | # read the profile, and set it if it exists 584 | contents <- readLines(path, warn = FALSE) 585 | if (length(contents) == 0L) 586 | return(NULL) 587 | 588 | # set RENV_PROFILE 589 | profile <- contents[[1L]] 590 | if (nzchar(profile)) 591 | Sys.setenv(RENV_PROFILE = profile) 592 | 593 | profile 594 | 595 | } 596 | 597 | renv_bootstrap_profile_prefix <- function() { 598 | profile <- renv_bootstrap_profile_get() 599 | if (!is.null(profile)) 600 | return(file.path("renv/profiles", profile)) 601 | } 602 | 603 | renv_bootstrap_profile_get <- function() { 604 | profile <- Sys.getenv("RENV_PROFILE", unset = "") 605 | renv_bootstrap_profile_normalize(profile) 606 | } 607 | 608 | renv_bootstrap_profile_set <- function(profile) { 609 | profile <- renv_bootstrap_profile_normalize(profile) 610 | if (is.null(profile)) 611 | Sys.unsetenv("RENV_PROFILE") 612 | else 613 | Sys.setenv(RENV_PROFILE = profile) 614 | } 615 | 616 | renv_bootstrap_profile_normalize <- function(profile) { 617 | 618 | if (is.null(profile) || profile %in% c("", "default")) 619 | return(NULL) 620 | 621 | profile 622 | 623 | } 624 | 625 | # load the renv profile, if any 626 | renv_bootstrap_profile_load(project) 627 | 628 | # construct path to library root 629 | root <- renv_bootstrap_library_root(project) 630 | 631 | # construct library prefix for platform 632 | prefix <- renv_bootstrap_platform_prefix() 633 | 634 | # construct full libpath 635 | libpath <- file.path(root, prefix) 636 | 637 | # attempt to load 638 | if (renv_bootstrap_load(project, libpath, version)) 639 | return(TRUE) 640 | 641 | # load failed; inform user we're about to bootstrap 642 | prefix <- paste("# Bootstrapping renv", version) 643 | postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "") 644 | header <- paste(prefix, postfix) 645 | message(header) 646 | 647 | # perform bootstrap 648 | bootstrap(version, libpath) 649 | 650 | # exit early if we're just testing bootstrap 651 | if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) 652 | return(TRUE) 653 | 654 | # try again to load 655 | if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { 656 | message("* Successfully installed and loaded renv ", version, ".") 657 | return(renv::load()) 658 | } 659 | 660 | # failed to download or load renv; warn the user 661 | msg <- c( 662 | "Failed to find an renv installation: the project will not be loaded.", 663 | "Use `renv::activate()` to re-initialize the project." 664 | ) 665 | 666 | warning(paste(msg, collapse = "\n"), call. = FALSE) 667 | 668 | }) 669 | -------------------------------------------------------------------------------- /renv/settings.dcf: -------------------------------------------------------------------------------- 1 | external.libraries: 2 | ignored.packages: 3 | package.dependency.fields: Imports, Depends, LinkingTo 4 | snapshot.type: implicit 5 | use.cache: TRUE 6 | vcs.ignore.library: TRUE 7 | -------------------------------------------------------------------------------- /resources.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | ## Articles 4 | 5 | - [Forecasting at Scale (Facebook Prophet)](https://peerj.com/preprints/3190.pdf) 6 | - [Gaussian Processes for Timeseries Modelling](http://www.robots.ox.ac.uk/~sjrob/Pubs/philTransA_2012.pdf) 7 | - [Neural forecasting: Introduction and Literature Overview, Amazon Research](https://arxiv.org/pdf/2004.10240.pdf) 8 | - [DeepAR: Probabilistic forecasting with autoregressive recurrent networks](https://www.sciencedirect.com/science/article/pii/S0169207019301888) 9 | - [Multi-variate Probabilistic Time Series Forecasting via Conditioned 10 | Normalizing Flows](https://arxiv.org/pdf/2002.06103.pdf) 11 | 12 | ## Books 13 | 14 | - [Applied Time Series Analysis for Fisheries and Environmental Sciences, E. E. Holmes, M. D. Scheuerell, and E. J. Ward](https://nwfsc-timeseries.github.io/atsa-labs/) 15 | - [Forecasting: Principles and Practice, Rob J Hyndman and George Athanasopoulos](https://otexts.com/fpp2/) 16 | - [Gaussian Processes for Machine Learning, Carl Edward Rasmussen and Christopher K. I. Williams](http://gaussianprocess.org/gpml/) 17 | - [Introduction to Algorithmic Marketing, Ilya Katsov](https://algorithmicweb.files.wordpress.com/2018/07/algorithmic-marketing-ai-for-marketing-operations-r1-7g.pdf) 18 | - [Introduction to Time Series and Forecasting, Peter J. Brockwell and Richard A. Davis](http://home.iitj.ac.in/~parmod/document/introduction%20time%20series.pdf) 19 | - [Little Book of R for Time Series, Avril Coghlan](https://a-little-book-of-r-for-time-series.readthedocs.io/en/latest/#) 20 | - [Statistical Rethinking, Richard McElreath](https://xcelab.net/rm/statistical-rethinking/) 21 | - [Time Series Analysis and its Applications: with R Examples, Robert H. Shumway and David S. Stoffer](http://db.ucsd.edu/static/TimeSeries.pdf) 22 | 23 | ## Docs 24 | 25 | - [Facebook Prophet - Docs](https://facebook.github.io/prophet/docs/quick_start.html) 26 | - [stumpy](https://stumpy.readthedocs.io/en/latest/index.html) - Used to efficiently compute the *matrix profile*. 27 | 28 | ## Blogs / Tutorials 29 | 30 | - [100 Time Series Data Mining Questions (with answers!)](https://www.cs.ucr.edu/~eamonn/100_Time_Series_Data_Mining_Questions__with_Answers.pdf) 31 | - [https://petolau.github.io](https://petolau.github.io) - Many interesting posts around time series analysis. 32 | - [Exploring TensorFlow Probability STS Forecasting](https://juanitorduz.github.io/intro_sts_tfp/) 33 | - [Forecasting Weekly Data with Prophet](https://juanitorduz.github.io/fb_prophet/) 34 | - [Intro CausalImpact](https://google.github.io/CausalImpact/CausalImpact.html) 35 | - [Structural Time Series modeling in TensorFlow Probability](https://blog.tensorflow.org/2019/03/structural-time-series-modeling-in.html) 36 | - [Time Series Analysis and Forecasting with ARIMA (Python)](https://kanoki.org/2020/04/30/time-series-analysis-and-forecasting-with-arima-python/) 37 | 38 | ## Repositories 39 | 40 | - [atspy](https://github.com/firmai/atspy) - Automated Time Series Models in Python. 41 | - [CausalImpact (Google)](https://github.com/google/CausalImpact) 42 | - [GluonTS - Probabilistic Time Series Modeling](https://github.com/awslabs/gluon-ts/) 43 | - [deep-learning-with-python-notebooks](https://github.com/fchollet/deep-learning-with-python-notebooks) 44 | - [deep-learning-with-r-notebooks](https://github.com/jjallaire/deep-learning-with-r-notebooks) 45 | - [tensor-house (Introduction to Algorithmic Marketing)](https://github.com/ikatsov/tensor-house) 46 | - [SHAP](https://github.com/slundberg/shap) 47 | - [sktime](https://github.com/alan-turing-institute/sktime)- Python toolbox for machine learning with time series compatible with scikit-learn. 48 | - [tsfresh](https://github.com/blue-yonder/tsfresh) - Time Series Feature extraction based on scalable hypothesis tests. 49 | 50 | ## Videos 51 | - [Gaussian Processes for Time Series Forecasting](https://www.youtube.com/watch?v=n42uQjhoS9g), [Second Symposium on Machine Learning and Dynamical Systems](http://www.fields.utoronto.ca/activities/20-21/dynamical) @Fields Institute, Juan Orduz 52 | --------------------------------------------------------------------------------