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

Added NAMESPACE and man, otherwise the install from the git is not working

parent f41468d5
No related branches found
No related tags found
No related merge requests found
...@@ -3,19 +3,14 @@ ...@@ -3,19 +3,14 @@
.RData .RData
.Ruserdata .Ruserdata
NAMESPACE
*.o *.o
src/onlineforecast\.so src/onlineforecast\.so
inst/doc
modifications_old_notstaged/ modifications_old_notstaged/
cache/ cache/
man/
misc-R/*cache* misc-R/*cache*
vignettes/*cache* vignettes/*cache*
......
NAMESPACE 0 → 100644
# Generated by roxygen2: do not edit by hand
S3method("==",data.list)
S3method(as.data.frame,data.list)
S3method(as.data.list,data.frame)
S3method(aslt,POSIXct)
S3method(aslt,POSIXlt)
S3method(aslt,character)
S3method(aslt,numeric)
S3method(check,data.list)
S3method(complete_cases,data.frame)
S3method(complete_cases,list)
S3method(ct,POSIXct)
S3method(ct,POSIXlt)
S3method(ct,character)
S3method(ct,numeric)
S3method(lagdf,character)
S3method(lagdf,data.frame)
S3method(lagdf,factor)
S3method(lagdf,logical)
S3method(lagdf,matrix)
S3method(lagdf,numeric)
S3method(pairs,data.list)
S3method(plot_ts,data.frame)
S3method(plot_ts,data.list)
S3method(plot_ts,matrix)
S3method(plot_ts,rls_fit)
S3method(plotly_ts,data.frame)
S3method(plotly_ts,data.list)
S3method(print,forecastmodel)
S3method(resample,data.frame)
S3method(residuals,data.frame)
S3method(residuals,forecastmodel_fit)
S3method(residuals,list)
S3method(residuals,matrix)
S3method(score,data.frame)
S3method(score,list)
S3method(subset,data.list)
S3method(summary,rls_fit)
export("%**%")
export("nams<-")
export(AR)
export(as.data.list)
export(aslt)
export(bspline)
export(cache_name)
export(cache_save)
export(check)
export(complete_cases)
export(ct)
export(data.list)
export(forecastmodel)
export(fs)
export(getse)
export(gof)
export(in_range)
export(lagdf)
export(lagdl)
export(lagvec)
export(lapply_cbind)
export(lapply_cbind_df)
export(lapply_rbind)
export(lapply_rbind_df)
export(lm_fit)
export(lm_optim)
export(lm_predict)
export(long_format)
export(lp)
export(make_input)
export(make_periodic)
export(make_tday)
export(nams)
export(one)
export(par_ts)
export(pbspline)
export(persistence)
export(plot_ts)
export(plotly_ts)
export(pst)
export(resample)
export(rls_fit)
export(rls_optim)
export(rls_predict)
export(rls_prm)
export(rls_summary)
export(rls_update)
export(rmse)
export(score)
export(setpar)
export(stairs)
export(step_optim)
importFrom(Rcpp,sourceCpp)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,graphics.off)
importFrom(graphics,axis)
importFrom(graphics,axis.POSIXct)
importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,mtext)
importFrom(graphics,pairs)
importFrom(graphics,panel.smooth)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(graphics,title)
importFrom(parallel,mclapply)
importFrom(stats,aggregate)
importFrom(stats,complete.cases)
importFrom(stats,lm)
importFrom(stats,optim)
importFrom(stats,predict)
importFrom(stats,residuals)
importFrom(stats,sd)
useDynLib(onlineforecast)
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/AR.R
\name{AR}
\alias{AR}
\title{Auto-Regressive (AR) input}
\usage{
AR(lags)
}
\arguments{
\item{lags}{integer vector: The lags of the AR to include.}
}
\value{
A list of matrices, one for each lag in lags, each with columns according to model$kseq.
}
\description{
Generate auto-regressive (AR) inputs in a model
}
\details{
The AR function can be used in an onlineforecast model formulation. It
creates the input matrices for including AR inputs in a model during the
transformation stage. It takes the values from the model output in the provided data
does the needed lagging.
The lags must be given according to the one-step ahead model, e.g.:
\code{AR(lags=c(0,1))} will give: Y_{t+1|t} = \eqn{\phi_1} y_{t-0} + \eqn{\phi_2} y_{t-1} + \eqn{\epsilon}_{t+1}
and:
\code{AR(lags=c(0,3,12))} will give: Y_{t+1|t} = \eqn{\phi}_1 y_{t-0} + \eqn{\phi}_2 y_{t-3} + \eqn{\phi}_3 y_{t-12} + \eqn{\epsilon}_{t+1}
Note, that
For k>1 the coefficients will be fitted individually for each horizon, e.g.:
\code{AR(lags=c(0,1))} will be the multi-step AR: Y_{t+k|t} = \eqn{\phi}_{1,k} y_{t-0} + \eqn{\phi}_{2,k} y_{t-1} + \eqn{\epsilon}_{t+k|t}
See the details in ??(ref til vignette).
}
\examples{
# Setup data and a model for the example
D <- Dbuilding
model <- forecastmodel$new()
model$output = "heatload"
# Use the AR in the transformation stage
model$add_inputs(AR = "AR(c(0,1))")
# Regression parameters
model$add_regprm("rls_prm(lambda=0.9)")
# kseq must be added
model$kseq <- 1:4
# In the transformation stage the AR input will be generated
# See that it generates two input matrices, simply with the lagged heat load at t for every k
model$transform_data(subset(D, 1:10))
# Fit with recursive least squares (no parameters prm in the model)
fit <- rls_fit(c(lambda=0.99), model, D, returnanalysis=TRUE)
# Plot the result, see "?plot_ts.rls_fit"
plot_ts(fit, xlim=c(ct("2010-12-20"),max(D$t)))
# Plot for a short period with peaks
plot_ts(fit, xlim=c("2011-01-05","2011-01-07"))
# For online updating, see ??ref{vignette, not yet available}:
# the needed lagged output values are stored in the model for next time new data is available
model$yAR
# The maximum lag needed is also kept
model$maxlagAR
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{Dbuilding}
\alias{Dbuilding}
\title{Observations and weather forecasts from a single-family building, weather station and Danish Meteorological Institute (DMI)}
\format{
A data list with 1854 rows and 7 variables:
\describe{
\item{t}{Time in GMT as POSIXct}
\item{heatload}{The heatload of a single family building in W}
\item{heatloadtotal}{The average heatload of a 16 single family buildings in W}
\item{Taobs}{Observed ambient temperature at the weather station in Celcius}
\item{Iobs}{Observed global radiation at the weather station in W/m^2}
\item{Ta}{Weather forecasts of ambient temperature up to 36 hours ahead from DMI in Celcius}
\item{Ta}{Weather forecasts of global radiation up to 36 hours ahead from DMI in W/m^2}
}
}
\source{
See \url{https://onlineforecasting.org/examples/datasets.html}.
}
\usage{
Dbuilding
}
\description{
Data of the period from 2010-12-15 to 2011-03-01. The weather station was located within a range of 10 km from the building.
}
\details{
Hourly average values. The time point is set in the end of the hour.
Set in the format of a data.list used as input to forecast models in the onlineforecast package.
}
\keyword{datasets}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.list.R
\name{as.data.frame.data.list}
\alias{as.data.frame.data.list}
\title{Convert to data.frame}
\usage{
\method{as.data.frame}{data.list}(x, row.names = NULL, optional = FALSE, ...)
}
\arguments{
\item{x}{The data.list to be converted.}
\item{row.names}{Not used.}
\item{optional}{Not used.}
\item{...}{Not used.}
}
\value{
A data.frame
}
\description{
Converts a data.list to a data.frame.
}
\details{
The forecasts in the data.list will result in columns named \code{varname.kxx} in the data.frame.
}
\examples{
#' # Use the data.list with building heat load
D <- Dbuilding
# Take a subset
D <- subset(D, 1:5, nms=c("t","Taobs","Ta","Iobs","I"), kseq=1:3)
# Convert to a data.frame, note the names of the forecasts are appended .kxx (i.e. for Ta and I)
as.data.frame(D)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as.data.list.R
\name{as.data.list}
\alias{as.data.list}
\alias{as.data.list.data.frame}
\title{Convert to data.list class}
\usage{
as.data.list(object)
\method{as.data.list}{data.frame}(object)
}
\arguments{
\item{object}{The data.frame to be converted.}
}
\value{
a value of class data.list
a data.list
}
\description{
These functions will convert the object into a data.list.
Convert a data.frame into a data.list
}
\details{
A data.list is simply a list of vectors and data.frames. For the use in the
onlineforecast package the following format must be kept:
- t: A vector of time.
- vectors with same length as t: Holds observations and values synced to time t.
- data.frames with number of rows as time t: Holds forecasts in each column named by \code{kxx} where \code{xx} is the
horizon, e.g. \code{k0} is synced as observations, and \code{k1} is one-step ahead.
The convention is that columns with forecasts are postfixed with \code{.kxx} where
\code{xx} is the horizon. See the examples.
}
\examples{
# Convert a dataframe with time and two observed variables
X <- data.frame(t=1:10, x=1:10, y=1:10)
as.data.list(X)
# Convert a dataframe with time, forecast and an observed variable
X <- data.frame(t=1:10, x.k1=1:10, x.k2=10:1, yobs=1:10, y.k1=1:10, y.k2=1:10)
as.data.list(X)
# Can be converted back and forth
X
as.data.frame(as.data.list(X))
}
\seealso{
\code{For specific detailed info see the children, e.g. \link{onlinefocast:::as.data.list.data.frame} }
as.data.list
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/aslt.R
\name{aslt}
\alias{aslt}
\alias{aslt.character}
\alias{aslt.POSIXct}
\alias{aslt.POSIXlt}
\alias{aslt.numeric}
\title{Convertion to POSIXlt}
\usage{
aslt(object, ...)
\method{aslt}{character}(object, tz = "GMT", ...)
\method{aslt}{POSIXct}(object, tz = NA, ...)
\method{aslt}{POSIXlt}(object, tz = NA, ...)
\method{aslt}{numeric}(object, ...)
}
\arguments{
\item{object}{The character, POSIXct, POSIClt, or numeric which is converted to POSIXct.}
\item{...}{Arguments to be passed to methods.}
\item{tz}{Timezone. If set, then the time zone will be changed of the object.}
}
\value{
An object of class POSIXlt
}
\description{
The argument is converted into POSIXlt with tz="GMT".
}
\section{Methods}{
#' @examples
# Create a POSIXlt with tz="GMT"
aslt("2019-01-01")
class(aslt("2019-01-01"))
aslt("2019-01-01 01:00:05")
# Convert between time zones
x <- aslt("2019-01-01", tz="CET")
aslt(x,tz="GMT")
# To seconds and back again
aslt(as.numeric(x, units="sec"))
- aslt.character: Simply a wrapper for \code{as.POSIXlt}
- aslt.POSIXct: Converts to POSIXct.
- aslt.POSIXlt: Changes the time zone of the object if tz is given.
- aslt.numeric: Converts from UNIX time in seconds to POSIXlt.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bspline.R
\name{bspline}
\alias{bspline}
\title{Compute base splines of a variable using the R function \code{splines::bs}, use in the transform stage.}
\usage{
bspline(
X,
Boundary.knots = NA,
intercept = FALSE,
df = NULL,
knots = NULL,
degree = 3,
bknots = NA,
periodic = FALSE
)
}
\arguments{
\item{X}{data.frame (as part of data.list) with horizons as columns named \code{kxx} (i.e. one for each horizon)}
\item{Boundary.knots}{The value is NA: then the boundaries are set to the range of each horizons (columns in X). See \code{?splines::bs}}
\item{intercept}{See \code{?splines::bs}.}
\item{df}{See \code{?splines::bs}}
\item{knots}{See \code{?splines::bs}}
\item{degree}{See \code{?splines::bs}}
\item{bknots}{Is just a short for Boundary.knots and replace Boundary.knots (if Boundary.knots is not given)}
\item{periodic}{Default FALSE. If TRUE, then \code{pbs::pbs} is called and periodic splines are generated.}
}
\value{
List of data frames with the computed base splines, each with columns for the same horizons as in X
}
\description{
Simply wraps the \code{splines::bs}, such that it can be used in the transformation stage.
}
\details{
See the help for all arguments with \code{?splines::bs}. NOTE that two arguments have different default values.
See the example \url{https://onlineforecasting.org/examples/solar-power-forecasting.html} where the function is used in a model.
}
\examples{
# How to make a diurnal curve using splines
# Select first 54 hours from the load data
D <- subset(Dbuilding, 1:76, kseq=1:4)
# Make the hour of the day as a forecast input
D$tday <- make_tday(D$t, kseq=1:4)
D$tday
# Calculate the base splines for each column in tday
L <- bspline(D$tday)
# Now L holds a data.frame for each base spline
str(L)
# Hence this will result in four inputs for the regression model
# Plot (note that the splines period starts at tday=0)
plot(D$t, L$bs1$k1, type="s")
for(i in 2:length(L)){
lines(D$t, L[[i]]$k1, col=i, type="s")
}
# In a model formulation it will be:
model <- forecastmodel$new()
model$add_inputs(mutday = "bspline(tday)")
# Such that at the transform stage will give the same as above
model$transform_data(D)
# Periodic splines are useful for modelling a diurnal harmonical functions
L <- bspline(D$tday, bknots=c(0,24), df=4, periodic=TRUE)
# or
L <- pbspline(D$tday, bknots=c(0,24), df=4)
# Note, how it has to have high enough df, else it generates an error
# Plot
plot(D$t, L$bs1$k1, type="s")
for(i in 2:length(L)){
lines(D$t, L[[i]]$k1, col=i, type="s")
}
}
\seealso{
Other Transform stage functions:
\code{\link{pbspline}()}
}
\concept{Transform stage functions}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cache_name.R
\name{cache_name}
\alias{cache_name}
\title{Generation of a name for a cache file for the value of a function.}
\usage{
cache_name(..., cachedir = "cache")
}
\arguments{
\item{...}{The objects from which to calculate cache file name.
If no objects given, then all the objects of the calling function are used for generating the checksum for the file name.}
\item{cachedir}{Path for saving the cache, i.e. prefixed to the generated name, remember to end with '/' to make a directory.}
}
\value{
A generated cache file name.
}
\description{
Caching of the value returned by a function
}
\details{
Use it in the beginning of a function, which runs a time consuming calculation, like fitting a model using optimization.
It makes a cache name, which can be used to save a unique cache file (see \code{\link{cache_save}()}).
The \code{cache_name} function must receive all the objects (in \code{...}) which influence the value of the function. It simply calculates a checksum using the \code{digest} package.
Further, it finds the name of the calling function and its definition, such that if anything changes in the function definition, then the cache file name changes too.
}
\examples{
# A function for demonstrating the using caching
fun <- function(x, y){
# Generate the cache name (no argument given, so both x and y is used)
nm <- cache_name(cachedir=cachedir)
# If the result is cached, then just return it
if(file.exists(nm)){ return(readRDS(nm)) }
# Do the calculation
res <- x^2 + y + 1
# Wait 1 sec
Sys.sleep(1)
# Save for cache
cache_save(res, nm)
# Return
return(res)
}
# For this example use a temporary directory
# In real use this should not be temporary! (changes between R sessions with tempdir())
cachedir <- tempdir()
# Uncomment to run:
# First time it takes at least 1 sec.
#fun(x=2,y=2)
# Second time it loads the cache and is much faster
#fun(x=2,y=2)
# Try changing the arguments (x,y) and run again
# See the cache file(s)
#dir(cachedir)
# Delete the cache folder
#unlink(cachedir, recursive=TRUE)
# Demonstrate how cache_name() is functioning
# Cache using the all objects given in the function calling, i.e. both x and y
fun <- function(x,y){
x^2 + y + 1
return(cache_name())
}
# These are the same (same values)
fun(x=1,y=2)
fun(1,2)
fun(y=2,x=1)
# But this one is different
fun(x=2,y=1)
# Test: cache using the values specified in the cache_name call
fun2 <- function(x,y){
x^2 + y + 1
return(cache_name(x))
}
# So now its only the x value that change the name
fun2(1,2)
fun2(1,3)
# But this one is different
fun2(3,3)
# And the function named changed the name
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cache_save.R
\name{cache_save}
\alias{cache_save}
\title{Save a cache file (name generated with \code{code_name()}}
\usage{
cache_save(object, filename)
}
\arguments{
\item{object}{The object to cache (i.e. the value of the evaluating function).}
\item{filename}{The cache file name (i.e. use the one generated by cache_name, see examples).}
}
\description{
Saves the object as an .RDS file with the filename
}
\details{
See the examples for \code{\link{cache_name}()}.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.list.R
\name{check}
\alias{check}
\title{Checking the object for appropriate form.}
\usage{
check(object)
}
\arguments{
\item{object}{The object to be checked.}
}
\value{
The tables generated.
# Check a data.list (see \code{?\link{check.data.list}})
check(Dbuilding)
}
\description{
Checking the object for appropriate form.
}
\details{
Prints on table form the result of the check.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.list.R
\name{check.data.list}
\alias{check.data.list}
\title{Checking the data.list for appropriate form.}
\usage{
\method{check}{data.list}(object)
}
\arguments{
\item{object}{The object to be checked.}
}
\value{
The tables generated.
# Check a data.list (see \code{?\link{check.data.list}})
check(Dbuilding)
# Vector with observations not same length as t
D <- Dbuilding
D$heatload <- D$heatload[1:10]
check(D)
# Some NAs in k1 forecast
D <- Dbuilding
D$Ta$k1[1:1500] <- NA
check(D)
# Wrong column names
names(D$Ta)
}
\description{
Checking the data.list for appropriate form.
}
\details{
Prints a check of the time vector t, which must have equidistant time points and no NAs.
Then the results of checking vectors (observations):
- ok: A 'V' indicates a successful check
- maxNAs: Proportion of NAs
- length: printed if not the same as the 't' vector
- class: the class
Then the results of checking data.frames and matrices (forecasts):
- ok: a 'V' indicates a successful check
- maxNAs: the proportion of NAs for the horizon (i.e. column) with the highest proportion of NAs
- meanNAs: the proportion of NAs of the entire data.frame
- nrow: printed if not the same as the 't' vector length
- colnames: columns must be names 'kxx', where 'xx' is the horizon
- sameclass: 'X' if not all columns are the same class
- class: prints the class of the columns if they are all the same
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/complete_cases.R
\name{complete_cases}
\alias{complete_cases}
\alias{complete_cases.list}
\alias{complete_cases.data.frame}
\title{Find complete cases in forecast matrices}
\usage{
complete_cases(object, kseq = NA)
\method{complete_cases}{list}(object, kseq = NA)
\method{complete_cases}{data.frame}(object, kseq = NA)
}
\arguments{
\item{object}{A data.frame (with columns named 'kxx') or a list of
data.frames.}
\item{kseq}{integer vector: If given then only these horizons are processed.}
}
\value{
A logical vector specifying if there is no missing
values across all horizonsd.
}
\description{
Returns a logical vector indicating the time points which
}
\details{
Given a forecast matrix the forecasts are lagged "+k" steps to align them and
then 'complete.cases()' is run on that .
Gieven a list of forecast matrices the points where all are complete (also all horizons) are complete are TRUE.
}
\examples{
# Take a small data set
D <- subset(Dbuilding, 1:20, kseq=1:5)
# Check the forecast matrix of ambient temperature
D$Ta
# Which are complete over all horizons? The first are not since not all horizons
# have a value there (after lagging)
complete_cases(D$Ta)
# Same goes if given as a list
complete_cases(D["Ta"])
# and if more than one is given
complete_cases(D[c("Ta","I")])
# Set some NA of some horizon
D$I$k3[8:9] <- NA
# Now they are recognized as not complete
complete_cases(D[c("Ta","I")])
# If we deal with residuals, which are observations and there for have column names "hxx"
Resid <- residuals(D$Ta, D$Taobs)
names(Resid)
# With columns with "h" instead of "k" no lagging occurs in complete_cases
complete_cases(Resid)
#
Resid2 <- Resid
Resid$h3[8:9] <- NA
complete_cases(list(Resid,Resid2))
}
\author{
Peder Bacher
}
man/ct.Rd 0 → 100644
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ct.R
\name{ct}
\alias{ct}
\alias{ct.character}
\alias{ct.POSIXct}
\alias{ct.POSIXlt}
\alias{ct.numeric}
\title{Convertion to POSIXct}
\usage{
ct(object, ...)
\method{ct}{character}(object, tz = "GMT", ...)
\method{ct}{POSIXct}(object, tz = NA, duplicatedadd = NA, ...)
\method{ct}{POSIXlt}(object, tz = NA, duplicatedadd = NA, ...)
\method{ct}{numeric}(object, ...)
}
\arguments{
\item{object}{The object to convert can be: character, numeric, POSIXct or POSIXlt}
\item{...}{Arguments to be passed to methods.}
\item{tz}{Timezone. If set, then the time zone will be changed of the object.}
\item{duplicatedadd}{Seconds to be added to duplicated time stamps, to mitigate the problem of duplicated timestamps at the shift to winter time. So the second time a time stamp occurs (identified with \code{duplicated}) then the seconds will be added.}
}
\value{
An object of class POSIXct
}
\description{
The object is converted into POSIXct with tz="GMT".
}
\details{
A simple helper, which wraps \code{\link{as.POSIXct}}` and sets the time zone to "GMT" per default.
}
\section{Methods}{
- ct.character: Simply a wrapper for \code{as.POSIXct} with default \code{tz}
- ct.POSIXct: Changes the time zone of the object if \code{tz} is given.
- ct.POSIXlt: Converts to POSIXct.
- ct.numeric: Converts from UNIX time in seconds to POSIXct with \code{tz} as GMT.
}
\examples{
# Create a POSIXct with tz="GMT"
ct("2019-01-01")
class(ct("2019-01-01"))
ct("2019-01-01 01:00:05")
# Convert to POSIXct
class(ct(as.POSIXlt("2019-01-01")))
# To seconds and back again
ct(as.numeric(1000, units="sec"))
# --------
# Convert character of time which has summer time leaps
# Example from CET (with CEST which is winter time)
#
# The point of shifting to and from summer time:
# DST Start (Clock Forward) DST End (Clock Backward)
# Sunday, March 31, 02:00 Sunday, October 27, 03:00
# --------
# From to winter time to summer time
txt <- c("2019-03-31 01:00",
"2019-03-31 01:30",
"2019-03-31 03:00",
"2019-03-31 03:30")
x <- ct(txt, tz="CET")
x
ct(x, tz="GMT")
# BE AWARE of this conversion of the 02:00: to 02:59:59 (exact time of shift) will lead to a
# wrong conversion
txt <- c("2019-03-31 01:30",
"2019-03-31 02:00",
"2019-03-31 03:30")
x <- ct(txt, tz="CET")
x
ct(x, tz="GMT")
# Which a diff on the time can detect, since all steps are not equal
plot(diff(ct(x, tz="GMT")))
# --------
# Shift to winter time is more problematic
# It works like this
txt <- c("2019-10-27 01:30",
"2019-10-27 02:00",
"2019-10-27 02:30",
"2019-10-27 03:00",
"2019-10-27 03:30")
x <- ct(txt, tz="CET")
x
ct(x, tz="GMT")
# however, timestamps can be given like this
txt <- c("2019-10-27 01:30",
"2019-10-27 02:00",
"2019-10-27 02:30",
"2019-10-27 02:00",
"2019-10-27 02:30",
"2019-10-27 03:00",
"2019-10-27 03:30")
x <- ct(txt, tz="CET")
x
ct(x, tz="GMT")
# Again can be detected, since all steps are not equal
plot(diff(ct(x, tz="GMT")))
# This can be fixed by (note that it can go wrong, e.g. with gaps around convertion etc.)
ct(x, tz="GMT", duplicatedadd=3600)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.list.R
\name{data.list}
\alias{data.list}
\title{Make a data.list}
\usage{
data.list(...)
}
\arguments{
\item{...}{Should hold: time t, observations as vectors and forecasts as data.frames}
}
\value{
a data.list.
}
\description{
Make a data.list of the vectors and data.frames given.
}
\details{
See the vignette 'setup-data' on how a data.list must be setup.
It's simply a list of class \code{data.list} holding:
- vector \code{t}
- vector(s) of observations
- data.frames (or matrices) of forecast inputs
}
\examples{
# Put together a data.list
# The time vector
time <- seq(ct("2019-01-01"),ct("2019-01-02"),by=3600)
# Observations time series (as vector)
xobs <- rnorm(length(time))
# Forecast input as data.frame
X <- data.frame(matrix(rnorm(length(time)*3), ncol=3))
names(X) <- pst("k",1:3)
D <- data.list(t=time, xobs=xobs, X=X)
# Check it
check(D)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/depth.R
\name{depth}
\alias{depth}
\title{Depth of a list}
\usage{
depth(this)
}
\arguments{
\item{this}{list}
}
\value{
integer
}
\description{
Depth of a list
}
\details{
Returns the depth of a list
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.list.R
\name{==.data.list}
\alias{==.data.list}
\title{Determine if two data.lists are identical}
\usage{
\method{==}{data.list}(x, y)
}
\arguments{
\item{x}{first data.list}
\item{y}{second data.list}
}
\value{
logical
}
\description{
Compare two data.lists
}
\details{
Returns TRUE if the two data.lists are fully identical, so all data, order of variables etc. must be fully identical
}
\examples{
Dbuilding == Dbuilding
D <- Dbuilding
D$Ta$k2[1] <- NA
Dbuilding == D
D <- Dbuilding
names(D)[5] <- "I"
names(D)[6] <- "Ta"
Dbuilding == D
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/flattenlist.R
\name{flattenlist}
\alias{flattenlist}
\title{Flattens list}
\usage{
flattenlist(x)
}
\arguments{
\item{x}{List to flatten.}
}
\value{
A flatten list
}
\description{
Flattens list in a single list of data.frames
}
\details{
Flattens list. Can maybe be made better. It might end up copying data in
memory!? It might change the order of the elements.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/forecastmodel.R-documentation.R
\name{forecastmodel}
\alias{forecastmodel}
\title{Class for forecastmodels}
\description{
R6 class for a forecastmodel
}
\details{
This class holds the variables and functions needed for defining and setting up a forecast model - independent of the fitting scheme.
See the vignettes on how to setup and use a model and the website \url{https://onlineforecasting.org} for more info.
Holds all the information needed independently of the fitting scheme (e.g. lm_fit or rls_fit), see the fields and functions below.
The fields are separated into:
- Fields for setting up the model
- Fields used when fitting (e.g. which horizons to fit for is set in \code{kseq}
See the fields description below.
Note, it's an R6 class, hence an object variable is a pointer (reference), which means two important points:
- In order to make a copy, the function clone_deep() must be used (usually \code{clone(deep=TRUE)}, but that will end in an infinite loop).
- It can be manimulated directly in functions (without return). The code is written such that no external functions manipulate the model object, except for online updating.
For online updating (i.e. receiving new data and updating the fit), then the model definition and the data becomes entangled, since transformation functions like low-pass filtering with \code{\link{lp}()} requires past values.
See the vignette ??(ref to online vignette, not yet available) and note that \code{\link{rls_fit}()} resets the state, which is also done in all \code{xxx_fit} functions (e.g. \code{\link{rls_fit}}.
}
\section{Public fields used for setting up the model}{
- output = NA, character: Name of the output.
- inputs = list(), add them with add_inputs(): List of inputs (which are R6 objects) (note the "cloning of list of reference objects" issue below in deep_clone function)
- regprmexpr = NA: The expression (as character) used for generating the regprm, e.g. "\code{\link{rls_prm}()}" for RLS.
- regprm = list(): Regression parameters calculated by evaluating the \code{regprmexpr}.
- prmbounds = as.matrix(data.frame(lower=NA, init=NA, upper=NA)): The bounds for optimization of the parameters, e.g. with \code{\link{rls_optim}()}.
- outputrange = NA, numeric vector of length 2: Limits of the predictions cropped in the range, e.g. outputrange = c(0,Inf) removes all negative output predictions.
}
\section{Public fields used when the model is fitted}{
- kseq = NA: The horizons to fit for.
- kseqopt = NA: The horizons to fit for when optimizing.
- p = NA: The (transformation stage) parameters used for the fit.
- Lfits = list(): The regression fits, one for each k in kseq (simply a list with the latest fit).
- datatr = NA: Transformed input data (data.list with all inputs for regression)
}
\section{Public methods}{
All public functions are described below and in examples a section for each is included:
}
\section{\code{$new()}}{
Create a new `forecastmodel` object.
Returns a forecastmodel object.
}
\section{\code{$add_inputs(...)}}{
Add inputs to the model.
- \code{...}: The inputs are given as arguments, see examples.
}
\section{\code{$add_regprm(regprm_expr)}}{
Add expression (as character) which generates regression parameters.
}
\section{\code{$add_prmbounds(...)}}{
Add the transformation parameters and bounds for optimization.
}
\section{\code{$get_prmbounds(...)}}{
Get the transformation parameter bounds, used by optimization functions e.g. \code{\link{rls_optim}()}.
}
\section{\code{$insert_prm(prm)}}{
Insert the transformation parameters prm in the input expressions and regression expressions, and keep them in $prm (simply string manipulation).
}
\section{\code{$transform_data(data)}}{
Function for transforming the input data to the regression stage input data (see \code{vignette("setup-data", package = "onlineforecast")}).
}
\section{\code{$reset_state()}}{
Resets the input states and stored data for iterative fitting (datatr rows and yAR) (see ??(ref to online updating vignette, not yet available).
}
\section{\code{$check(data = NA)}}{
Check if the model is setup correctly.
}
\examples{
# New object
model <- forecastmodel$new()
# Print it
model
# Add model inputs
model$add_inputs(Ta = "lp(Ta)")
# See it
model$inputs
# Update to use no low-pass filter
model$add_inputs(Ta = "Ta")
model$inputs
# Add another
model$add_inputs(I = "lp(I)")
model$inputs
# Simply a list, so manipulate directly
class(model$inputs$Ta)
model$inputs$Ta$expr <- "lp(Ta, a1=0.9)"
# Add the parameters for the regression stage
model$add_regprm("rls_prm(lambda=0.99)")
# The evaluation is a list, which is set in
model$regprm
# Set the lambda to be optimized between 0.9 and 0.999, starting at 0.99
model$add_prmbounds(lambda = c(0.9, 0.99, 0.999))
# Note the "__" syntax to set parameters for inputs: "input__prm"
model$add_prmbounds(Ta__a1 = c(0.8, 0.95, 0.99))
# Get the lower bounds
model$get_prmbounds("lower")
# Insert the init parameters
prm <- model$get_prmbounds("init")
prm
# Before
model$inputs$Ta$expr
# After
model$insert_prm(prm)
model$inputs$Ta$expr
# Check if the model is setup and can be used with a given data.list
# An error is thrown
try(model$check(Dbuilding))
# Add the model output
model$output <- "heatload"
# Still not error free
try(model$check(Dbuilding))
# Add the horizons to fit for
model$kseq <- 1:4
# Finally, no errors :)
model$check(Dbuilding)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fs.R
\name{fs}
\alias{fs}
\title{Generation of Fourrier series.}
\usage{
fs(X, nharmonics)
}
\arguments{
\item{X}{must be a dataframe with columns k1,k2,..., . One period is from 0 to 1
(so for example if X is hour of day, then divide X by 24 to obtain a daily period).}
\item{nharmonics}{the number of harmonics, so creates double as many inputs! i.e. one sine and one cos for each harmonic.}
}
\value{
Returns a list of dataframes (two for each i in \code{1:nharmonics}) with same number of columns as X.
}
\description{
Function for generating Fourrier series as a function of x E.g. use for
harmonic functions for modelling the diurnal patterns or for basis functions.
}
\examples{
# Make a data.frame with time of day in hours for different horizons
tday <- make_tday(seq(ct("2019-01-01"), ct("2019-01-04"), by=3600), kseq=1:5)
# See whats in it
str(tday)
head(tday)
# Now use the function to generate Fourier series
L <- fs(tday/24, nharmonics=2)
# See what is in it
str(L)
# Make a plot to see the harmonics
par(mfrow=c(2,1))
# The first harmonic
plot(L$sin1$k1, type="l")
lines(L$cos1$k1, type="l")
# The second harmonic
plot(L$sin2$k1, type="l")
lines(L$cos2$k1, type="l")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment