R/regression.h.R

Defines functions regression

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

regressionOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
    "regressionOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            ind = NULL,
            modelTerms = NULL, ...) {

            super$initialize(
                package='jmvbaseR',
                name='regression',
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep,
                default=NULL)
            private$..ind <- jmvcore::OptionVariables$new(
                "ind",
                ind,
                default=NULL)
            private$..modelTerms <- jmvcore::OptionTerms$new(
                "modelTerms",
                modelTerms,
                default=NULL)

            self$.addOption(private$..dep)
            self$.addOption(private$..ind)
            self$.addOption(private$..modelTerms)
        }),
    active = list(
        dep = function() private$..dep$value,
        ind = function() private$..ind$value,
        modelTerms = function() private$..modelTerms$value),
    private = list(
        ..dep = NA,
        ..ind = NA,
        ..modelTerms = NA)
)

regressionResults <- if (requireNamespace('jmvcore')) R6::R6Class(
    inherit = jmvcore::Group,
    active = list(),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Linear Regression")}))

regressionBase <- if (requireNamespace('jmvcore')) R6::R6Class(
    "regressionBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = 'jmvbaseR',
                name = 'regression',
                version = c(1,0,0),
                options = options,
                results = regressionResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE)
        }))

#' Linear Regression
#'
#' 
#' @param data the data set as a data frame
#' @param dep a string specifying the dependent variable in \code{data}
#' @param ind a vector of strings specifying the independent variables in
#'   \code{data}
#' @param modelTerms a list of string vectors specifying the model terms
#' @return A results object containing:
#' \tabular{llllll}{
#' }
#'
#' @export
regression <- function(
    data,
    dep = NULL,
    ind = NULL,
    modelTerms = NULL) {

    if ( ! requireNamespace('jmvcore'))
        stop('regression requires jmvcore to be installed (restart may be required)')

    options <- regressionOptions$new(
        dep = dep,
        ind = ind,
        modelTerms = modelTerms)

    results <- regressionResults$new(
        options = options)

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

    analysis$run()

    analysis$results
}
jamovi/jmvbaseR documentation built on May 18, 2019, 12:23 p.m.