Skip to content
Snippets Groups Projects
Commit a58ec3c7 authored by pbac's avatar pbac
Browse files

v0.9.1 submitted

parent 103aa8ec
No related branches found
No related tags found
No related merge requests found
...@@ -15,15 +15,14 @@ Imports: ...@@ -15,15 +15,14 @@ Imports:
R6 (>= 2.2.2), R6 (>= 2.2.2),
splines (>= 3.1.1), splines (>= 3.1.1),
pbs, pbs,
digest, digest
LinkingTo: Rcpp, RcppArmadillo LinkingTo: Rcpp, RcppArmadillo
Suggests: Suggests:
knitr, knitr,
rmarkdown, rmarkdown,
R.rsp, R.rsp,
testthat (>= 2.1.0), testthat (>= 2.1.0),
data.table, data.table
plotly
VignetteBuilder: knitr VignetteBuilder: knitr
RoxygenNote: 7.1.1 RoxygenNote: 7.1.1
URL: http://onlineforecasting.org URL: http://onlineforecasting.org
......
...@@ -60,17 +60,6 @@ ...@@ -60,17 +60,6 @@
#' names(L[[2]]) #' names(L[[2]])
#' #'
#' #'
#' # Use plotly
#' \donttest{library(plotly)
#' L <- plot_ts(D, c("heatload","Ta"), kseq=c(1,24), usely=TRUE, xlab="Time",
#' ylabs=c("Heat (kW)","Temperature (C)"))
#'
#' # From plotly the figures are returned and can be further manipulated
#' # e.g. put the legend in the top by
#' L[[length(L)]] <- L[[length(L)]] %>% layout(legend = list(x = 100, y = 0.98))
#' print(subplot(L, shareX=TRUE, nrows=length(L), titleY = TRUE))
#' }
#'
#' @rdname plot_ts #' @rdname plot_ts
#' @export #' @export
plot_ts <- function(object, patterns=".*", xlim = NA, ylims = NA, xlab = "", ylabs = NA, plot_ts <- function(object, patterns=".*", xlim = NA, ylims = NA, xlab = "", ylabs = NA,
...@@ -474,11 +463,6 @@ plot_ts_series <- function(data, pattern, iplot = 1, ...@@ -474,11 +463,6 @@ plot_ts_series <- function(data, pattern, iplot = 1,
#' # Plot it #' # Plot it
#' plot_ts(fit1) #' plot_ts(fit1)
#' #'
#' # Plot it with plotly
#' \donttest{
#' plot_ts(fit1, usely=TRUE)
#' }
#'
#' # Return the data #' # Return the data
#' Dplot <- plot_ts(fit1) #' Dplot <- plot_ts(fit1)
#' #'
......
...@@ -9,19 +9,16 @@ ...@@ -9,19 +9,16 @@
#' #'
#' Simply the same as \code{\link{plot_ts}()} with \code{usely=TRUE}, such that plotly is used. #' Simply the same as \code{\link{plot_ts}()} with \code{usely=TRUE}, such that plotly is used.
#' #'
#' The \code{plotly} package must be loaded. #' The \code{plotly} package must be installed and loaded.
#' #'
#' Note that the plot parameters set with \code{\link{par_ts}()} have no effect on the \code{plotly} plots. #' Note that the plot parameters set with \code{\link{par_ts}()} have no effect on the \code{plotly} plots.
#' #'
#' See \url{http://https://onlineforecasting.org/vignettes/nice-tricks.html}.
#'
#' @rdname plot_ts #' @rdname plot_ts
#' @examples #' @examples
#' #'
#' \donttest{ #' # See the website link above
#' D <- Dbuilding
#' plotly_ts(D, c("heatload","Ta"), kseq=c(1,24))
#' plotly_ts(D, c("heatload","Ta"), kseq=c(1,24))
#' plotly_ts(D, c("heatload","Ta$|Taobs$"), kseq=c(1,24))
#' }
#' #'
#' @export #' @export
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#' Resid <- residuals(Yhat, y) #' Resid <- residuals(Yhat, y)
#' #'
#' # Calculate the score for the k1 horizon #' # Calculate the score for the k1 horizon
#' score(Resid)$val #' score(Resid)$scoreval
#' #'
#' # The first values were excluded, since there are NAs #' # The first values were excluded, since there are NAs
#' head(Resid) #' head(Resid)
...@@ -50,10 +50,10 @@ score <- function(Residuals, scoreperiod = NA, usecomplete = TRUE, scorefun = rm ...@@ -50,10 +50,10 @@ score <- function(Residuals, scoreperiod = NA, usecomplete = TRUE, scorefun = rm
scoreperiod <- scoreperiod & complete.cases(Residuals) scoreperiod <- scoreperiod & complete.cases(Residuals)
} }
# Calculate the objective function for each horizon # Calculate the objective function for each horizon
val <- sapply(1:ncol(Residuals), function(i){ scoreval <- sapply(1:ncol(Residuals), function(i){
scorefun(Residuals[scoreperiod,i]) scorefun(Residuals[scoreperiod,i])
}) })
nams(val) <- gsub("h","k",nams(Residuals)) nams(scoreval) <- gsub("h","k",nams(Residuals))
# #
return(list(val=val,scoreperiod=scoreperiod)) return(list(scoreval=scoreval,scoreperiod=scoreperiod))
} }
...@@ -326,14 +326,14 @@ Now the residuals can be calculated and the score: ...@@ -326,14 +326,14 @@ Now the residuals can be calculated and the score:
# Use the residuals function # Use the residuals function
R <- residuals(D$Yhat1, D$y) R <- residuals(D$Yhat1, D$y)
# And the score as a function of the horizon # And the score as a function of the horizon
score(R, scoreperiod=ok)$val score(R, scoreperiod=ok)$scoreval
``` ```
Calculated the score (default is RMSE) for all models: Calculated the score (default is RMSE) for all models:
```{r} ```{r}
RMSE <- sapply(nms, function(nm){ RMSE <- sapply(nms, function(nm){
score(residuals(D[[nm]],D$y), ok)$val score(residuals(D[[nm]],D$y), ok)$scoreval
}) })
``` ```
...@@ -386,7 +386,7 @@ fittmp <- rls_fit(model$prm, model, D) ...@@ -386,7 +386,7 @@ fittmp <- rls_fit(model$prm, model, D)
Finally, the score can be calculated on the period following the train period by: Finally, the score can be calculated on the period following the train period by:
```{r scorefit} ```{r scorefit}
score_fit(fittmp, !D$trainperiod)$val score_fit(fittmp, !D$trainperiod)$scoreval
``` ```
In this way it's rather easy to set up different schemes, like optimizing the In this way it's rather easy to set up different schemes, like optimizing the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment