Suppress internal functions from reference manual

This commit is contained in:
bl 2017-07-28 22:03:27 -07:00
parent 3060536563
commit 58fa0bcec5
31 changed files with 75 additions and 8 deletions

View file

@ -133,6 +133,7 @@ prophet <- function(df = NULL,
#' #'
#' @param m Prophet object. #' @param m Prophet object.
#' #'
#' @keywords internal
validate_inputs <- function(m) { validate_inputs <- function(m) {
if (!(m$growth %in% c('linear', 'logistic'))) { if (!(m$growth %in% c('linear', 'logistic'))) {
stop("Parameter 'growth' should be 'linear' or 'logistic'.") stop("Parameter 'growth' should be 'linear' or 'logistic'.")
@ -176,6 +177,8 @@ validate_inputs <- function(m) {
#' trend. #' trend.
#' #'
#' @return Stan model. #' @return Stan model.
#'
#' @keywords internal
get_prophet_stan_model <- function(model) { get_prophet_stan_model <- function(model) {
fn <- paste('prophet', model, 'growth.RData', sep = '_') fn <- paste('prophet', model, 'growth.RData', sep = '_')
## If the cached model doesn't work, just compile a new one. ## If the cached model doesn't work, just compile a new one.
@ -201,6 +204,8 @@ get_prophet_stan_model <- function(model) {
#' trend. #' trend.
#' #'
#' @return Stan model. #' @return Stan model.
#'
#' @keywords internal
compile_stan_model <- function(model) { compile_stan_model <- function(model) {
fn <- paste('stan/prophet', model, 'growth.stan', sep = '_') fn <- paste('stan/prophet', model, 'growth.stan', sep = '_')
@ -212,14 +217,15 @@ compile_stan_model <- function(model) {
} }
#' Convert date vector #' Convert date vector
#' #'
#' Convert the date to POSIXct object #' Convert the date to POSIXct object
#' #'
#' @param ds Date vector, can be consisted of characters #' @param ds Date vector, can be consisted of characters
#' @param tz string time zone #' @param tz string time zone
#' #'
#' @return vector of POSIXct object converted from date #' @return vector of POSIXct object converted from date
#' #'
#' @keywords internal
set_date <- function(ds = NULL, tz = "GMT") { set_date <- function(ds = NULL, tz = "GMT") {
if (length(ds) == 0) { if (length(ds) == 0) {
return(NULL) return(NULL)
@ -238,15 +244,16 @@ set_date <- function(ds = NULL, tz = "GMT") {
} }
#' Time difference between datetimes #' Time difference between datetimes
#' #'
#' Compute time difference of two POSIXct objects #' Compute time difference of two POSIXct objects
#' #'
#' @param ds1 POSIXct object #' @param ds1 POSIXct object
#' @param ds2 POSIXct object #' @param ds2 POSIXct object
#' @param units string units of difference, e.g. 'days' or 'secs'. #' @param units string units of difference, e.g. 'days' or 'secs'.
#' #'
#' @return numeric time difference #' @return numeric time difference
#' #'
#' @keywords internal
time_diff <- function(ds1, ds2, units = "days") { time_diff <- function(ds1, ds2, units = "days") {
return(as.numeric(difftime(ds1, ds2, units = units))) return(as.numeric(difftime(ds1, ds2, units = units)))
} }
@ -263,6 +270,7 @@ time_diff <- function(ds1, ds2, units = "days") {
#' #'
#' @return list with items 'df' and 'm'. #' @return list with items 'df' and 'm'.
#' #'
#' @keywords internal
setup_dataframe <- function(m, df, initialize_scales = FALSE) { setup_dataframe <- function(m, df, initialize_scales = FALSE) {
if (exists('y', where=df)) { if (exists('y', where=df)) {
df$y <- as.numeric(df$y) df$y <- as.numeric(df$y)
@ -310,6 +318,7 @@ setup_dataframe <- function(m, df, initialize_scales = FALSE) {
#' #'
#' @return m with changepoints set. #' @return m with changepoints set.
#' #'
#' @keywords internal
set_changepoints <- function(m) { set_changepoints <- function(m) {
if (!is.null(m$changepoints)) { if (!is.null(m$changepoints)) {
if (length(m$changepoints) > 0) { if (length(m$changepoints) > 0) {
@ -346,6 +355,7 @@ set_changepoints <- function(m) {
#' #'
#' @return array of indexes. #' @return array of indexes.
#' #'
#' @keywords internal
get_changepoint_matrix <- function(m) { get_changepoint_matrix <- function(m) {
A <- matrix(0, nrow(m$history), length(m$changepoints.t)) A <- matrix(0, nrow(m$history), length(m$changepoints.t))
for (i in 1:length(m$changepoints.t)) { for (i in 1:length(m$changepoints.t)) {
@ -362,6 +372,7 @@ get_changepoint_matrix <- function(m) {
#' #'
#' @return Matrix with seasonality features. #' @return Matrix with seasonality features.
#' #'
#' @keywords internal
fourier_series <- function(dates, period, series.order) { fourier_series <- function(dates, period, series.order) {
t <- time_diff(dates, set_date('1970-01-01 00:00:00')) t <- time_diff(dates, set_date('1970-01-01 00:00:00'))
features <- matrix(0, length(t), 2 * series.order) features <- matrix(0, length(t), 2 * series.order)
@ -382,6 +393,7 @@ fourier_series <- function(dates, period, series.order) {
#' #'
#' @return Dataframe with seasonality. #' @return Dataframe with seasonality.
#' #'
#' @keywords internal
make_seasonality_features <- function(dates, period, series.order, prefix) { make_seasonality_features <- function(dates, period, series.order, prefix) {
features <- fourier_series(dates, period, series.order) features <- fourier_series(dates, period, series.order)
colnames(features) <- paste(prefix, 1:ncol(features), sep = '_delim_') colnames(features) <- paste(prefix, 1:ncol(features), sep = '_delim_')
@ -396,6 +408,7 @@ make_seasonality_features <- function(dates, period, series.order, prefix) {
#' @return A dataframe with a column for each holiday. #' @return A dataframe with a column for each holiday.
#' #'
#' @importFrom dplyr "%>%" #' @importFrom dplyr "%>%"
#' @keywords internal
make_holiday_features <- function(m, dates) { make_holiday_features <- function(m, dates) {
scale.ratio <- m$holidays.prior.scale / m$seasonality.prior.scale scale.ratio <- m$holidays.prior.scale / m$seasonality.prior.scale
# Strip dates to be just days, for joining on holidays # Strip dates to be just days, for joining on holidays
@ -459,6 +472,7 @@ add_seasonality <- function(m, name, period, fourier.order) {
#' #'
#' @return Dataframe with seasonality. #' @return Dataframe with seasonality.
#' #'
#' @keywords internal
make_all_seasonality_features <- function(m, df) { make_all_seasonality_features <- function(m, df) {
seasonal.features <- data.frame(zeros = rep(0, nrow(df))) seasonal.features <- data.frame(zeros = rep(0, nrow(df)))
for (name in names(m$seasonalities)) { for (name in names(m$seasonalities)) {
@ -487,6 +501,7 @@ make_all_seasonality_features <- function(m, df) {
#' #'
#' @return Number of Fourier components, or 0 for disabled. #' @return Number of Fourier components, or 0 for disabled.
#' #'
#' @keywords internal
parse_seasonality_args <- function(m, name, arg, auto.disable, default.order) { parse_seasonality_args <- function(m, name, arg, auto.disable, default.order) {
if (arg == 'auto') { if (arg == 'auto') {
fourier.order <- 0 fourier.order <- 0
@ -521,6 +536,7 @@ parse_seasonality_args <- function(m, name, arg, auto.disable, default.order) {
#' #'
#' @return The prophet model with seasonalities set. #' @return The prophet model with seasonalities set.
#' #'
#' @keywords internal
set_auto_seasonalities <- function(m) { set_auto_seasonalities <- function(m) {
first <- min(m$history$ds) first <- min(m$history$ds)
last <- max(m$history$ds) last <- max(m$history$ds)
@ -562,6 +578,7 @@ set_auto_seasonalities <- function(m) {
#' @return A vector (k, m) with the rate (k) and offset (m) of the linear #' @return A vector (k, m) with the rate (k) and offset (m) of the linear
#' growth function. #' growth function.
#' #'
#' @keywords internal
linear_growth_init <- function(df) { linear_growth_init <- function(df) {
i0 <- which.min(df$ds) i0 <- which.min(df$ds)
i1 <- which.max(df$ds) i1 <- which.max(df$ds)
@ -585,6 +602,7 @@ linear_growth_init <- function(df) {
#' @return A vector (k, m) with the rate (k) and offset (m) of the logistic #' @return A vector (k, m) with the rate (k) and offset (m) of the logistic
#' growth function. #' growth function.
#' #'
#' @keywords internal
logistic_growth_init <- function(df) { logistic_growth_init <- function(df) {
i0 <- which.min(df$ds) i0 <- which.min(df$ds)
i1 <- which.max(df$ds) i1 <- which.max(df$ds)
@ -767,6 +785,7 @@ predict.prophet <- function(object, df = NULL, ...) {
#' #'
#' @return Vector y(t). #' @return Vector y(t).
#' #'
#' @keywords internal
piecewise_linear <- function(t, deltas, k, m, changepoint.ts) { piecewise_linear <- function(t, deltas, k, m, changepoint.ts) {
# Intercept changes # Intercept changes
gammas <- -changepoint.ts * deltas gammas <- -changepoint.ts * deltas
@ -793,6 +812,7 @@ piecewise_linear <- function(t, deltas, k, m, changepoint.ts) {
#' #'
#' @return Vector y(t). #' @return Vector y(t).
#' #'
#' @keywords internal
piecewise_logistic <- function(t, cap, deltas, k, m, changepoint.ts) { piecewise_logistic <- function(t, cap, deltas, k, m, changepoint.ts) {
# Compute offset changes # Compute offset changes
k.cum <- c(k, cumsum(deltas) + k) k.cum <- c(k, cumsum(deltas) + k)
@ -820,6 +840,7 @@ piecewise_logistic <- function(t, cap, deltas, k, m, changepoint.ts) {
#' #'
#' @return Vector with trend on prediction dates. #' @return Vector with trend on prediction dates.
#' #'
#' @keywords internal
predict_trend <- function(model, df) { predict_trend <- function(model, df) {
k <- mean(model$params$k, na.rm = TRUE) k <- mean(model$params$k, na.rm = TRUE)
param.m <- mean(model$params$m, na.rm = TRUE) param.m <- mean(model$params$m, na.rm = TRUE)
@ -843,6 +864,7 @@ predict_trend <- function(model, df) {
#' #'
#' @return Dataframe with seasonal components. #' @return Dataframe with seasonal components.
#' #'
#' @keywords internal
predict_seasonal_components <- function(m, df) { predict_seasonal_components <- function(m, df) {
seasonal.features <- make_all_seasonality_features(m, df) seasonal.features <- make_all_seasonality_features(m, df)
lower.p <- (1 - m$interval.width)/2 lower.p <- (1 - m$interval.width)/2
@ -888,6 +910,7 @@ predict_seasonal_components <- function(m, df) {
#' #'
#' @return List with posterior predictive samples for each component. #' @return List with posterior predictive samples for each component.
#' #'
#' @keywords internal
sample_posterior_predictive <- function(m, df) { sample_posterior_predictive <- function(m, df) {
# Sample trend, seasonality, and yhat from the extrapolation model. # Sample trend, seasonality, and yhat from the extrapolation model.
n.iterations <- length(m$params$k) n.iterations <- length(m$params$k)
@ -936,6 +959,7 @@ predictive_samples <- function(m, df) {
#' #'
#' @return Dataframe with uncertainty intervals. #' @return Dataframe with uncertainty intervals.
#' #'
#' @keywords internal
predict_uncertainty <- function(m, df) { predict_uncertainty <- function(m, df) {
sim.values <- sample_posterior_predictive(m, df) sim.values <- sample_posterior_predictive(m, df)
# Add uncertainty estimates # Add uncertainty estimates
@ -965,6 +989,7 @@ predict_uncertainty <- function(m, df) {
#' #'
#' @return List of trend, seasonality, and yhat, each a vector like df$t. #' @return List of trend, seasonality, and yhat, each a vector like df$t.
#' #'
#' @keywords internal
sample_model <- function(m, df, seasonal.features, iteration) { sample_model <- function(m, df, seasonal.features, iteration) {
trend <- sample_predictive_trend(m, df, iteration) trend <- sample_predictive_trend(m, df, iteration)
@ -987,6 +1012,7 @@ sample_model <- function(m, df, seasonal.features, iteration) {
#' #'
#' @return Vector of simulated trend over df$t. #' @return Vector of simulated trend over df$t.
#' #'
#' @keywords internal
sample_predictive_trend <- function(model, df, iteration) { sample_predictive_trend <- function(model, df, iteration) {
k <- model$params$k[iteration] k <- model$params$k[iteration]
param.m <- model$params$m[iteration] param.m <- model$params$m[iteration]
@ -1073,6 +1099,7 @@ make_future_dataframe <- function(m, periods, freq = 'day',
#' @param fcst Data frame returned by prophet predict. #' @param fcst Data frame returned by prophet predict.
#' #'
#' @importFrom dplyr "%>%" #' @importFrom dplyr "%>%"
#' @keywords internal
df_for_plotting <- function(m, fcst) { df_for_plotting <- function(m, fcst) {
# Make sure there is no y in fcst # Make sure there is no y in fcst
fcst$y <- NULL fcst$y <- NULL
@ -1198,6 +1225,8 @@ prophet_plot_components <- function(
#' figure, if available. #' figure, if available.
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
#'
#' @keywords internal
plot_trend <- function(df, uncertainty = TRUE, plot_cap = TRUE) { plot_trend <- function(df, uncertainty = TRUE, plot_cap = TRUE) {
df.t <- df[!is.na(df$trend),] df.t <- df[!is.na(df$trend),]
gg.trend <- ggplot2::ggplot(df.t, ggplot2::aes(x = ds, y = trend)) + gg.trend <- ggplot2::ggplot(df.t, ggplot2::aes(x = ds, y = trend)) +
@ -1225,6 +1254,8 @@ plot_trend <- function(df, uncertainty = TRUE, plot_cap = TRUE) {
#' @param uncertainty Boolean to plot uncertainty intervals. #' @param uncertainty Boolean to plot uncertainty intervals.
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
#'
#' @keywords internal
plot_holidays <- function(m, df, uncertainty = TRUE) { plot_holidays <- function(m, df, uncertainty = TRUE) {
holiday.comps <- unique(m$holidays$holiday) %>% as.character() holiday.comps <- unique(m$holidays$holiday) %>% as.character()
df.s <- data.frame(ds = df$ds, df.s <- data.frame(ds = df$ds,
@ -1258,6 +1289,8 @@ plot_holidays <- function(m, df, uncertainty = TRUE) {
#' to Monday, and so on. #' to Monday, and so on.
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
#'
#' @keywords internal
plot_weekly <- function(m, uncertainty = TRUE, weekly_start = 0) { plot_weekly <- function(m, uncertainty = TRUE, weekly_start = 0) {
# Compute weekly seasonality for a Sun-Sat sequence of dates. # Compute weekly seasonality for a Sun-Sat sequence of dates.
df.w <- data.frame( df.w <- data.frame(
@ -1291,6 +1324,8 @@ plot_weekly <- function(m, uncertainty = TRUE, weekly_start = 0) {
#' to Jan 2, and so on. #' to Jan 2, and so on.
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
#'
#' @keywords internal
plot_yearly <- function(m, uncertainty = TRUE, yearly_start = 0) { plot_yearly <- function(m, uncertainty = TRUE, yearly_start = 0) {
# Compute yearly seasonality for a Jan 1 - Dec 31 sequence of dates. # Compute yearly seasonality for a Jan 1 - Dec 31 sequence of dates.
df.y <- data.frame( df.y <- data.frame(
@ -1323,6 +1358,8 @@ plot_yearly <- function(m, uncertainty = TRUE, yearly_start = 0) {
#' @param uncertainty Boolean to plot uncertainty intervals. #' @param uncertainty Boolean to plot uncertainty intervals.
#' #'
#' @return A ggplot2 plot. #' @return A ggplot2 plot.
#'
#' @keywords internal
plot_seasonality <- function(m, name, uncertainty = TRUE) { plot_seasonality <- function(m, name, uncertainty = TRUE) {
# Compute seasonality from Jan 1 through a single period. # Compute seasonality from Jan 1 through a single period.
start <- set_date('2017-01-01') start <- set_date('2017-01-01')

View file

@ -16,3 +16,4 @@ Stan model.
\description{ \description{
Compile Stan model Compile Stan model
} }
\keyword{internal}

View file

@ -14,3 +14,4 @@ df_for_plotting(m, fcst)
\description{ \description{
Merge history and forecast for plotting. Merge history and forecast for plotting.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ Matrix with seasonality features.
\description{ \description{
Provides Fourier series components with the specified frequency and order. Provides Fourier series components with the specified frequency and order.
} }
\keyword{internal}

View file

@ -15,3 +15,4 @@ array of indexes.
\description{ \description{
Gets changepoint matrix for history dataframe. Gets changepoint matrix for history dataframe.
} }
\keyword{internal}

View file

@ -16,3 +16,4 @@ Stan model.
\description{ \description{
Load compiled Stan model Load compiled Stan model
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ Provides a strong initialization for linear growth by calculating the
growth and offset parameters that pass the function through the first and growth and offset parameters that pass the function through the first and
last points in the time series. last points in the time series.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ Provides a strong initialization for logistic growth by calculating the
growth and offset parameters that pass the function through the first and growth and offset parameters that pass the function through the first and
last points in the time series. last points in the time series.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ Dataframe with seasonality.
\description{ \description{
Dataframe with seasonality features. Dataframe with seasonality features.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ A dataframe with a column for each holiday.
\description{ \description{
Construct a matrix of holiday features. Construct a matrix of holiday features.
} }
\keyword{internal}

View file

@ -21,3 +21,4 @@ Dataframe with seasonality.
\description{ \description{
Data frame with seasonality features. Data frame with seasonality features.
} }
\keyword{internal}

View file

@ -24,3 +24,4 @@ Number of Fourier components, or 0 for disabled.
\description{ \description{
Get number of Fourier components for built-in seasonalities. Get number of Fourier components for built-in seasonalities.
} }
\keyword{internal}

View file

@ -23,3 +23,4 @@ Vector y(t).
\description{ \description{
Evaluate the piecewise linear function. Evaluate the piecewise linear function.
} }
\keyword{internal}

View file

@ -25,3 +25,4 @@ Vector y(t).
\description{ \description{
Evaluate the piecewise logistic function. Evaluate the piecewise logistic function.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ A ggplot2 plot.
\description{ \description{
Plot the holidays component of the forecast. Plot the holidays component of the forecast.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ A ggplot2 plot.
\description{ \description{
Plot a custom seasonal component. Plot a custom seasonal component.
} }
\keyword{internal}

View file

@ -20,3 +20,4 @@ A ggplot2 plot.
\description{ \description{
Plot the prophet trend. Plot the prophet trend.
} }
\keyword{internal}

View file

@ -21,3 +21,4 @@ A ggplot2 plot.
\description{ \description{
Plot the weekly component of the forecast. Plot the weekly component of the forecast.
} }
\keyword{internal}

View file

@ -21,3 +21,4 @@ A ggplot2 plot.
\description{ \description{
Plot the yearly component of the forecast. Plot the yearly component of the forecast.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ Dataframe with seasonal components.
\description{ \description{
Predict seasonality broken down into components. Predict seasonality broken down into components.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ Vector with trend on prediction dates.
\description{ \description{
Predict trend using the prophet model. Predict trend using the prophet model.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ Dataframe with uncertainty intervals.
\description{ \description{
Prophet uncertainty intervals. Prophet uncertainty intervals.
} }
\keyword{internal}

View file

@ -21,3 +21,4 @@ List of trend, seasonality, and yhat, each a vector like df$t.
\description{ \description{
Simulate observations from the extrapolated generative model. Simulate observations from the extrapolated generative model.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ List with posterior predictive samples for each component.
\description{ \description{
Prophet posterior predictive samples. Prophet posterior predictive samples.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ Vector of simulated trend over df$t.
\description{ \description{
Simulate the trend using the extrapolated generative model. Simulate the trend using the extrapolated generative model.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ spacing between dates in the history is <7 days.
Turns on daily seasonality if there is >=2 days of history, and the spacing Turns on daily seasonality if there is >=2 days of history, and the spacing
between dates in the history is <1 day. between dates in the history is <1 day.
} }
\keyword{internal}

View file

@ -20,3 +20,4 @@ Sets m$changepoints to the dates of changepoints. Either:
2) We are generating a grid of them. 2) We are generating a grid of them.
3) The user prefers no changepoints be used. 3) The user prefers no changepoints be used.
} }
\keyword{internal}

View file

@ -17,3 +17,4 @@ vector of POSIXct object converted from date
\description{ \description{
Convert the date to POSIXct object Convert the date to POSIXct object
} }
\keyword{internal}

View file

@ -21,3 +21,4 @@ Adds a time index and scales y. Creates auxillary columns 't', 't_ix',
'y_scaled', and 'cap_scaled'. These columns are used during both fitting 'y_scaled', and 'cap_scaled'. These columns are used during both fitting
and predicting. and predicting.
} }
\keyword{internal}

View file

@ -19,3 +19,4 @@ numeric time difference
\description{ \description{
Compute time difference of two POSIXct objects Compute time difference of two POSIXct objects
} }
\keyword{internal}

View file

@ -12,3 +12,4 @@ validate_inputs(m)
\description{ \description{
Validates the inputs to Prophet. Validates the inputs to Prophet.
} }
\keyword{internal}