R/prophet.h.R

Defines functions prophet

Documented in prophet

# This file is automatically generated, you probably don't want to edit this

prophetOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "prophetOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            covs = NULL,
            method = "loess",
            plot1 = TRUE,
            plot2 = FALSE,
            periods = 365,
            unit = "day",
            width = 500,
            height = 500,
            width1 = 500,
            height1 = 500, ...) {

            super$initialize(
                package="snowCluster",
                name="prophet",
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep,
                suggested=list(
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..covs <- jmvcore::OptionVariables$new(
                "covs",
                covs,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..method <- jmvcore::OptionList$new(
                "method",
                method,
                options=list(
                    "lm",
                    "glm",
                    "loess"),
                default="loess")
            private$..plot1 <- jmvcore::OptionBool$new(
                "plot1",
                plot1,
                default=TRUE)
            private$..plot2 <- jmvcore::OptionBool$new(
                "plot2",
                plot2,
                default=FALSE)
            private$..periods <- jmvcore::OptionInteger$new(
                "periods",
                periods,
                min=1,
                default=365)
            private$..unit <- jmvcore::OptionList$new(
                "unit",
                unit,
                options=list(
                    "hour",
                    "day",
                    "week",
                    "month",
                    "quarter",
                    "year"),
                default="day")
            private$..width <- jmvcore::OptionInteger$new(
                "width",
                width,
                default=500)
            private$..height <- jmvcore::OptionInteger$new(
                "height",
                height,
                default=500)
            private$..width1 <- jmvcore::OptionInteger$new(
                "width1",
                width1,
                default=500)
            private$..height1 <- jmvcore::OptionInteger$new(
                "height1",
                height1,
                default=500)

            self$.addOption(private$..dep)
            self$.addOption(private$..covs)
            self$.addOption(private$..method)
            self$.addOption(private$..plot1)
            self$.addOption(private$..plot2)
            self$.addOption(private$..periods)
            self$.addOption(private$..unit)
            self$.addOption(private$..width)
            self$.addOption(private$..height)
            self$.addOption(private$..width1)
            self$.addOption(private$..height1)
        }),
    active = list(
        dep = function() private$..dep$value,
        covs = function() private$..covs$value,
        method = function() private$..method$value,
        plot1 = function() private$..plot1$value,
        plot2 = function() private$..plot2$value,
        periods = function() private$..periods$value,
        unit = function() private$..unit$value,
        width = function() private$..width$value,
        height = function() private$..height$value,
        width1 = function() private$..width1$value,
        height1 = function() private$..height1$value),
    private = list(
        ..dep = NA,
        ..covs = NA,
        ..method = NA,
        ..plot1 = NA,
        ..plot2 = NA,
        ..periods = NA,
        ..unit = NA,
        ..width = NA,
        ..height = NA,
        ..width1 = NA,
        ..height1 = NA)
)

prophetResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "prophetResults",
    inherit = jmvcore::Group,
    active = list(
        instructions = function() private$.items[["instructions"]],
        text = function() private$.items[["text"]],
        plot1 = function() private$.items[["plot1"]],
        plot2 = function() private$.items[["plot2"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Prophet with Multiple Variables",
                refs="snowCluster")
            self$add(jmvcore::Html$new(
                options=options,
                name="instructions",
                title="Instructions",
                visible=TRUE))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text",
                title=""))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot1",
                title="Forecast of multiple variables",
                visible="(plot1)",
                refs="prophet",
                renderFun=".plot1",
                clearWith=list(
                    "dep",
                    "covs",
                    "periods",
                    "unit",
                    "width",
                    "height")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2",
                title="Smooth line plot",
                visible="(plot2)",
                refs="prophet",
                renderFun=".plot2",
                clearWith=list(
                    "dep",
                    "covs",
                    "method",
                    "periods",
                    "unit",
                    "width1",
                    "height1")))}))

prophetBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "prophetBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = "snowCluster",
                name = "prophet",
                version = c(1,0,0),
                options = options,
                results = prophetResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE,
                weightsSupport = 'auto')
        }))

#' Prophet with Multiple Variables
#'
#' 
#' @param data .
#' @param dep .
#' @param covs .
#' @param method .
#' @param plot1 .
#' @param plot2 .
#' @param periods .
#' @param unit .
#' @param width .
#' @param height .
#' @param width1 .
#' @param height1 .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$instructions} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$text} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$plot1} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
prophet <- function(
    data,
    dep,
    covs,
    method = "loess",
    plot1 = TRUE,
    plot2 = FALSE,
    periods = 365,
    unit = "day",
    width = 500,
    height = 500,
    width1 = 500,
    height1 = 500) {

    if ( ! requireNamespace("jmvcore", quietly=TRUE))
        stop("prophet requires jmvcore to be installed (restart may be required)")

    if ( ! missing(dep)) dep <- jmvcore::resolveQuo(jmvcore::enquo(dep))
    if ( ! missing(covs)) covs <- jmvcore::resolveQuo(jmvcore::enquo(covs))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(dep), dep, NULL),
            `if`( ! missing(covs), covs, NULL))

    for (v in dep) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])

    options <- prophetOptions$new(
        dep = dep,
        covs = covs,
        method = method,
        plot1 = plot1,
        plot2 = plot2,
        periods = periods,
        unit = unit,
        width = width,
        height = height,
        width1 = width1,
        height1 = height1)

    analysis <- prophetClass$new(
        options = options,
        data = data)

    analysis$run()

    analysis$results
}
hyunsooseol/snowCluster documentation built on April 5, 2025, 2:06 a.m.