#' @description Plot measured curve (in black) and predicted curve (in red)
#'
#' @param data Object return by \code{getData}
-#' @param pred Object as returned by \code{getForecast}
+#' @param pred Object as returned by \code{computeForecast}
#' @param index Index in forecasts
#'
#' @export
L = length(ref_serie)
# Determine indices of no-NAs days followed by no-NAs tomorrows
- first_day = ifelse(length(data$getCenteredSerie(1))<L, 2, 1)
- fdays_indices = c()
- for (i in first_day:(index-1))
+ fdays = c()
+ for (i in 1:(index-1))
{
if ( !any(is.na(data$getSerie(i)) | is.na(data$getSerie(i+1))) )
- fdays_indices = c(fdays_indices, i)
+ fdays = c(fdays, i)
}
- distances = sapply(fdays_indices, function(i) {
+ distances = sapply(fdays, function(i) {
sqrt( sum( (ref_serie - data$getCenteredSerie(i))^2 ) / L )
})
indices = sort(distances, index.return=TRUE)$ix[1:min(limit,length(distances))]
yrange = quantile( c(ref_serie, sapply( indices, function(i) {
- ii = fdays_indices[i]
- serie = c(data$getCenteredSerie(ii), data$getCenteredSerie(ii+1))
+ serie = c(data$getCenteredSerie(fdays[i]), data$getCenteredSerie(fdays[i]+1))
if (!all(is.na(serie)))
return (range(serie, na.rm=TRUE))
c()
par(mar=c(4.7,5,1,1), cex.axis=1.5, cex.lab=1.5, lwd=2)
for ( i in seq_len(length(indices)+1) )
{
- ii = ifelse(i<=length(indices), fdays_indices[ indices[plot_order[i]] ], index)
+ ii = ifelse(i<=length(indices), fdays[ indices[plot_order[i]] ], index)
plot(c(data$getCenteredSerie(ii),data$getCenteredSerie(ii+1)),
ylim=yrange, type="l", col=colors[i],
xlab=ifelse(i==1,"Temps (en heures)",""), ylab=ifelse(i==1,"PM10 centré",""))
}
abline(v=24, lty=2, col=colors()[56])
}
- list("indices"=c(fdays_indices[ indices[plot_order] ],index), "colors"=colors)
+ list("indices"=c(fdays[ indices[plot_order] ],index), "colors"=colors)
}
#' @title Plot similarities
#'
#' @description Plot histogram of similarities (weights)
#'
-#' @param pred Object as returned by \code{getForecast}
+#' @param pred Object as returned by \code{computeForecast}
#' @param index Index in forecasts (not in data)
#'
#' @export
#' @title Plot error
#'
-#' @description Draw error graphs, potentially from several runs of \code{getForecast}
+#' @description Draw error graphs, potentially from several runs of \code{computeForecast}
#'
-#' @param err Error as returned by \code{getError}
+#' @param err Error as returned by \code{computeError}
#' @param cols Colors for each error (default: 1,2,3,...)
#'
#' @seealso \code{\link{plotPredReal}}, \code{\link{plotFilaments}}, \code{\link{plotSimils}}
if (!requireNamespace("rainbow", quietly=TRUE))
stop("Functional boxplot requires the rainbow package")
- start_index = 1
- end_index = data$getSize()
- if (length(data$getCenteredSerie(1)) < length(data$getCenteredSerie(2)))
- {
- # Shifted start (7am, or 1pm, or...)
- start_index = 2
- end_index = data$getSize() - 1
- }
-
- series_matrix = sapply(start_index:end_index, function(index) {
- as.matrix(data$getSerie(index))
+ L = length(data$getCenteredSerie(2))
+ series_matrix = sapply(1:data$getSize(), function(index) {
+ if (filter(index))
+ as.matrix(data$getSerie(index))
+ else
+ rep(NA,L)
})
- # Remove NAs. + filter TODO: merge with previous step: only one pass required...
- nas_indices = seq_len(ncol(series_matrix))[ sapply( 1:ncol(series_matrix),
- function(index) ( !filter(index) || any(is.na(series_matrix[,index])) ) ) ]
- series_matrix = series_matrix[,-nas_indices]
+ # TODO: merge with previous step: only one pass should be required
+ no_NAs_indices = sapply( 1:ncol(series_matrix), function(i) all(!is.na(series_matrix[,i])) )
+ series_matrix = series_matrix[,no_NAs_indices]
series_fds = rainbow::fds(seq_len(nrow(series_matrix)), series_matrix)
if (plot_bivariate)
ref_var = apply(ref_series, 2, sd)
# Determine indices of no-NAs days followed by no-NAs tomorrows
- first_day = ifelse(length(data$getCenteredSerie(1))<length(ref_series[1,]), 2, 1)
- fdays_indices = c()
- for (i in first_day:(tail(indices,1)-1))
+ fdays = c()
+ for (i in 1:(tail(indices,1)-1))
{
if ( !any(is.na(data$getSerie(i)) | is.na(data$getSerie(i+1))) )
- fdays_indices = c(fdays_indices, i)
+ fdays = c(fdays, i)
}
# TODO: 3 == magic number
random_var = matrix(nrow=3, ncol=48)
for (mc in seq_len(nrow(random_var)))
{
- random_indices = sample(fdays_indices, length(indices))
+ random_indices = sample(fdays, length(indices))
random_series = t( sapply(random_indices, function(i) {
c( data$getSerie(i), data$getSerie(i+1) )
}) )