Browse Source

Combined and shiny documentation

Petra Lamborn 5 years ago
parent
commit
2dad2bfc08
2 changed files with 26 additions and 12 deletions
  1. 8
    10
      R/combmodels.R
  2. 18
    2
      README.md

+ 8
- 10
R/combmodels.R View File

81
 cmplot <-ggplot(cmdf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
81
 cmplot <-ggplot(cmdf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
82
     geom_point(aes(y = r), color = "darkgreen")
82
     geom_point(aes(y = r), color = "darkgreen")
83
 
83
 
84
-cmplot
84
+# cmplot
85
 
85
 
86
-cmplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
86
+# cmplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
87
 
87
 
88
-# sres <- stepAIC(charmmod, scope = list(upper = nform.full, lower = nform.min),
89
-#                 direction = "both", steps = 300)
90
 
88
 
91
 
89
 
92
 newagg <- p$read_pickle("../data/1617-agg.pkl")
90
 newagg <- p$read_pickle("../data/1617-agg.pkl")
117
 predplot <-ggplot(predf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
115
 predplot <-ggplot(predf, aes(x = x, y = y)) + geom_line(aes(y = f), color = "blue", size = 2) + geom_point() +
118
     geom_point(aes(y = r), color = "darkgreen")
116
     geom_point(aes(y = r), color = "darkgreen")
119
 
117
 
120
-predplot
118
+# predplot
121
 
119
 
122
-predplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
120
+# predplot + coord_cartesian(xlim = c(as.POSIXct("2017-03-01", tz = "UTC"), as.POSIXct("2017-04-01", tz = "UTC")))
123
 
121
 
124
 mean(abs(predf$r))
122
 mean(abs(predf$r))
125
 sd(predf$r)
123
 sd(predf$r)
126
 
124
 
127
 
125
 
128
 # number of icps per cluster
126
 # number of icps per cluster
129
-ocdf <- p$read_pickle('../data/9-clusters-sample-table.pkl')
130
-ncdf <- p$read_pickle('../data/1617-asgn-table.pkl')
131
-table(ocdf$cluster)
132
-table(ncdf$cluster)
127
+# ocdf <- p$read_pickle('../data/9-clusters-sample-table.pkl')
128
+# ncdf <- p$read_pickle('../data/1617-asgn-table.pkl')
129
+# table(ocdf$cluster)
130
+# table(ncdf$cluster)
133
 
131
 
134
 
132
 
135
 allmods <- list()
133
 allmods <- list()

+ 18
- 2
README.md View File

229
 
229
 
230
 ### `weathmod.R`
230
 ### `weathmod.R`
231
 
231
 
232
-This script takes the downloaded weather data, (hard-coded path: `../data/2016-18-weather.pkl`) and calculates running last-24-hour minimum and maximum temperatures. It then fits harmonic regressions using the first and second harmonic to de-trend the yearly pattern of each series, saving the resulting dataset at `../data/weatherharm.csv` and stores the models in `../models/weatherMinharmonic.rds` and `../models/weatherMaxharmonic.rds`. These paths can be changed in the source, but there are no command line options.
232
+This script takes the downloaded weather data, (hard-coded path: `../data/2016-18-weather.pkl`) and calculates running last-24-hour minimum and maximum temperatures. It then fits harmonic regressions using the first and second harmonic to de-trend the yearly pattern of each series, saving the resulting dataset at `../data/weatherharm.csv` and stores the models in `../models/weatherMinharmonic.rds` and `../models/weatherMaxharmonic.rds`. These paths can be changed in the source (and will likely need to be as the data files are not included in the repository), but there are no command line options.
233
 
233
 
234
 Commented out in the source are a number of potentially informative plots showing this process. For example:
234
 Commented out in the source are a number of potentially informative plots showing this process. For example:
235
 
235
 
241
 
241
 
242
 ### `combmodels.R`
242
 ### `combmodels.R`
243
 
243
 
244
-This script takes the 
244
+Taking `../data/9-clusters.agg.pkl` and `../data/weatherharm.csv` as inputs, this script first fits a harmonic model to cluster 1 and tests it with the assigned clusters in `../data/1617-agg.pkl`. It then fits models to all clusters and saves them collectively in `../models/1kmods.rds`.
245
+
246
+Similar to the previous, some plots are again commented out.
247
+
248
+## Shiny App
249
+
250
+The [R Shiny](https://shiny.rstudio.com/) app is located in `shiny/app.R`. It requires the outputs from `weathmod.R` and `combmodels.R`, along with a couple of extra packages, installed with:
251
+
252
+```R
253
+install.packages(c("shiny", "shinycssloaders"))
254
+```
255
+
256
+Explaining Shiny and how to properly install it on a server in order to have a nice web app on a domain behind https _etc_ would take more time than I have (email me!) but for an example of a simple, self-hosted app in action see [this project](https://shiny.petras.space/Emissions/) I made awhile ago ([source](https://git.petras.space/petra/Emissions)).
257
+
258
+The app in this project can be run with `Rscript app.R`; this will (after several seconds of start-up) launch the app at a random port (e.g. 5576). Navigating to this location in your browser (firewall permitting) should display the app.
259
+
260
+The "data and model" tab allows exploration of the data along with the model projection; plots can be saved by right-clicking. The "prediction" tab allows, after specification of the number of icps in each of nine clusters, the temperature range, and the month and day of the week, the projected demand pattern. The month is approximate because it models a "typical" day in the approximate middle of that month, without a specific date.