R/logregbin.h.R

Defines functions logRegBin

Documented in logRegBin

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

logRegBinOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "logRegBinOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            covs = NULL,
            factors = NULL,
            blocks = list(
                list()),
            refLevels = NULL,
            modelTest = FALSE,
            dev = TRUE,
            aic = TRUE,
            bic = FALSE,
            pseudoR2 = list(
                "r2mf"),
            omni = FALSE,
            ci = FALSE,
            ciWidth = 95,
            OR = FALSE,
            ciOR = FALSE,
            ciWidthOR = 95,
            emMeans = list(
                list()),
            ciEmm = TRUE,
            ciWidthEmm = 95,
            emmPlots = TRUE,
            emmTables = FALSE,
            emmWeights = TRUE,
            class = FALSE,
            acc = FALSE,
            spec = FALSE,
            sens = FALSE,
            auc = FALSE,
            rocPlot = FALSE,
            cutOff = 0.5,
            cutOffPlot = FALSE,
            collin = FALSE,
            boxTidwell = FALSE,
            cooks = FALSE, ...) {

            super$initialize(
                package="jmv",
                name="logRegBin",
                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"),
                default=NULL)
            private$..factors <- jmvcore::OptionVariables$new(
                "factors",
                factors,
                rejectUnusedLevels=TRUE,
                suggested=list(
                    "nominal"),
                permitted=list(
                    "factor"),
                default=NULL)
            private$..blocks <- jmvcore::OptionArray$new(
                "blocks",
                blocks,
                default=list(
                    list()),
                template=jmvcore::OptionTerms$new(
                    "blocks",
                    NULL))
            private$..refLevels <- jmvcore::OptionArray$new(
                "refLevels",
                refLevels,
                items="(factors)",
                default=NULL,
                template=jmvcore::OptionGroup$new(
                    "refLevels",
                    NULL,
                    elements=list(
                        jmvcore::OptionVariable$new(
                            "var",
                            NULL,
                            content="$key"),
                        jmvcore::OptionLevel$new(
                            "ref",
                            NULL))))
            private$..modelTest <- jmvcore::OptionBool$new(
                "modelTest",
                modelTest,
                default=FALSE)
            private$..dev <- jmvcore::OptionBool$new(
                "dev",
                dev,
                default=TRUE)
            private$..aic <- jmvcore::OptionBool$new(
                "aic",
                aic,
                default=TRUE)
            private$..bic <- jmvcore::OptionBool$new(
                "bic",
                bic,
                default=FALSE)
            private$..pseudoR2 <- jmvcore::OptionNMXList$new(
                "pseudoR2",
                pseudoR2,
                options=list(
                    "r2mf",
                    "r2cs",
                    "r2n",
                    "r2t"),
                default=list(
                    "r2mf"))
            private$..omni <- jmvcore::OptionBool$new(
                "omni",
                omni,
                default=FALSE)
            private$..ci <- jmvcore::OptionBool$new(
                "ci",
                ci,
                default=FALSE)
            private$..ciWidth <- jmvcore::OptionNumber$new(
                "ciWidth",
                ciWidth,
                min=50,
                max=99.9,
                default=95)
            private$..OR <- jmvcore::OptionBool$new(
                "OR",
                OR,
                default=FALSE)
            private$..ciOR <- jmvcore::OptionBool$new(
                "ciOR",
                ciOR,
                default=FALSE)
            private$..ciWidthOR <- jmvcore::OptionNumber$new(
                "ciWidthOR",
                ciWidthOR,
                min=50,
                max=99.9,
                default=95)
            private$..emMeans <- jmvcore::OptionArray$new(
                "emMeans",
                emMeans,
                default=list(
                    list()),
                template=jmvcore::OptionVariables$new(
                    "emMeans",
                    NULL))
            private$..ciEmm <- jmvcore::OptionBool$new(
                "ciEmm",
                ciEmm,
                default=TRUE)
            private$..ciWidthEmm <- jmvcore::OptionNumber$new(
                "ciWidthEmm",
                ciWidthEmm,
                min=50,
                max=99.9,
                default=95)
            private$..emmPlots <- jmvcore::OptionBool$new(
                "emmPlots",
                emmPlots,
                default=TRUE)
            private$..emmTables <- jmvcore::OptionBool$new(
                "emmTables",
                emmTables,
                default=FALSE)
            private$..emmWeights <- jmvcore::OptionBool$new(
                "emmWeights",
                emmWeights,
                default=TRUE)
            private$..class <- jmvcore::OptionBool$new(
                "class",
                class,
                default=FALSE)
            private$..acc <- jmvcore::OptionBool$new(
                "acc",
                acc,
                default=FALSE)
            private$..spec <- jmvcore::OptionBool$new(
                "spec",
                spec,
                default=FALSE)
            private$..sens <- jmvcore::OptionBool$new(
                "sens",
                sens,
                default=FALSE)
            private$..auc <- jmvcore::OptionBool$new(
                "auc",
                auc,
                default=FALSE)
            private$..rocPlot <- jmvcore::OptionBool$new(
                "rocPlot",
                rocPlot,
                default=FALSE)
            private$..cutOff <- jmvcore::OptionNumber$new(
                "cutOff",
                cutOff,
                min=0,
                max=1,
                default=0.5)
            private$..cutOffPlot <- jmvcore::OptionBool$new(
                "cutOffPlot",
                cutOffPlot,
                default=FALSE)
            private$..collin <- jmvcore::OptionBool$new(
                "collin",
                collin,
                default=FALSE)
            private$..boxTidwell <- jmvcore::OptionBool$new(
                "boxTidwell",
                boxTidwell,
                default=FALSE,
                hidden=TRUE)
            private$..cooks <- jmvcore::OptionBool$new(
                "cooks",
                cooks,
                default=FALSE,
                hidden=TRUE)
            private$..predictOV <- jmvcore::OptionOutput$new(
                "predictOV")
            private$..residsOV <- jmvcore::OptionOutput$new(
                "residsOV")
            private$..cooksOV <- jmvcore::OptionOutput$new(
                "cooksOV")

            self$.addOption(private$..dep)
            self$.addOption(private$..covs)
            self$.addOption(private$..factors)
            self$.addOption(private$..blocks)
            self$.addOption(private$..refLevels)
            self$.addOption(private$..modelTest)
            self$.addOption(private$..dev)
            self$.addOption(private$..aic)
            self$.addOption(private$..bic)
            self$.addOption(private$..pseudoR2)
            self$.addOption(private$..omni)
            self$.addOption(private$..ci)
            self$.addOption(private$..ciWidth)
            self$.addOption(private$..OR)
            self$.addOption(private$..ciOR)
            self$.addOption(private$..ciWidthOR)
            self$.addOption(private$..emMeans)
            self$.addOption(private$..ciEmm)
            self$.addOption(private$..ciWidthEmm)
            self$.addOption(private$..emmPlots)
            self$.addOption(private$..emmTables)
            self$.addOption(private$..emmWeights)
            self$.addOption(private$..class)
            self$.addOption(private$..acc)
            self$.addOption(private$..spec)
            self$.addOption(private$..sens)
            self$.addOption(private$..auc)
            self$.addOption(private$..rocPlot)
            self$.addOption(private$..cutOff)
            self$.addOption(private$..cutOffPlot)
            self$.addOption(private$..collin)
            self$.addOption(private$..boxTidwell)
            self$.addOption(private$..cooks)
            self$.addOption(private$..predictOV)
            self$.addOption(private$..residsOV)
            self$.addOption(private$..cooksOV)
        }),
    active = list(
        dep = function() private$..dep$value,
        covs = function() private$..covs$value,
        factors = function() private$..factors$value,
        blocks = function() private$..blocks$value,
        refLevels = function() private$..refLevels$value,
        modelTest = function() private$..modelTest$value,
        dev = function() private$..dev$value,
        aic = function() private$..aic$value,
        bic = function() private$..bic$value,
        pseudoR2 = function() private$..pseudoR2$value,
        omni = function() private$..omni$value,
        ci = function() private$..ci$value,
        ciWidth = function() private$..ciWidth$value,
        OR = function() private$..OR$value,
        ciOR = function() private$..ciOR$value,
        ciWidthOR = function() private$..ciWidthOR$value,
        emMeans = function() private$..emMeans$value,
        ciEmm = function() private$..ciEmm$value,
        ciWidthEmm = function() private$..ciWidthEmm$value,
        emmPlots = function() private$..emmPlots$value,
        emmTables = function() private$..emmTables$value,
        emmWeights = function() private$..emmWeights$value,
        class = function() private$..class$value,
        acc = function() private$..acc$value,
        spec = function() private$..spec$value,
        sens = function() private$..sens$value,
        auc = function() private$..auc$value,
        rocPlot = function() private$..rocPlot$value,
        cutOff = function() private$..cutOff$value,
        cutOffPlot = function() private$..cutOffPlot$value,
        collin = function() private$..collin$value,
        boxTidwell = function() private$..boxTidwell$value,
        cooks = function() private$..cooks$value,
        predictOV = function() private$..predictOV$value,
        residsOV = function() private$..residsOV$value,
        cooksOV = function() private$..cooksOV$value),
    private = list(
        ..dep = NA,
        ..covs = NA,
        ..factors = NA,
        ..blocks = NA,
        ..refLevels = NA,
        ..modelTest = NA,
        ..dev = NA,
        ..aic = NA,
        ..bic = NA,
        ..pseudoR2 = NA,
        ..omni = NA,
        ..ci = NA,
        ..ciWidth = NA,
        ..OR = NA,
        ..ciOR = NA,
        ..ciWidthOR = NA,
        ..emMeans = NA,
        ..ciEmm = NA,
        ..ciWidthEmm = NA,
        ..emmPlots = NA,
        ..emmTables = NA,
        ..emmWeights = NA,
        ..class = NA,
        ..acc = NA,
        ..spec = NA,
        ..sens = NA,
        ..auc = NA,
        ..rocPlot = NA,
        ..cutOff = NA,
        ..cutOffPlot = NA,
        ..collin = NA,
        ..boxTidwell = NA,
        ..cooks = NA,
        ..predictOV = NA,
        ..residsOV = NA,
        ..cooksOV = NA)
)

logRegBinResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "logRegBinResults",
    inherit = jmvcore::Group,
    active = list(
        modelFit = function() private$.items[["modelFit"]],
        modelComp = function() private$.items[["modelComp"]],
        models = function() private$.items[["models"]],
        predictOV = function() private$.items[["predictOV"]],
        residsOV = function() private$.items[["residsOV"]],
        cooksOV = function() private$.items[["cooksOV"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Binomial Logistic Regression")
            self$add(jmvcore::Table$new(
                options=options,
                name="modelFit",
                title="Model Fit Measures",
                clearWith=list(
                    "dep",
                    "blocks"),
                visible="(dev || aic || bic || pseudoR2:r2mf || pseudoR2:r2cs || pseudoR2:r2n || modelTest)",
                columns=list(
                    list(
                        `name`="model", 
                        `title`="Model", 
                        `type`="text"),
                    list(
                        `name`="dev", 
                        `title`="Deviance", 
                        `type`="number", 
                        `visible`="(dev)"),
                    list(
                        `name`="aic", 
                        `title`="AIC", 
                        `type`="number", 
                        `visible`="(aic)"),
                    list(
                        `name`="bic", 
                        `title`="BIC", 
                        `type`="number", 
                        `visible`="(bic)"),
                    list(
                        `name`="r2mf", 
                        `title`="R\u00B2<sub>McF</sub>", 
                        `type`="number", 
                        `visible`="(pseudoR2:r2mf)"),
                    list(
                        `name`="r2cs", 
                        `title`="R\u00B2<sub>CS</sub>", 
                        `type`="number", 
                        `visible`="(pseudoR2:r2cs)"),
                    list(
                        `name`="r2n", 
                        `title`="R\u00B2<sub>N</sub>", 
                        `type`="number", 
                        `visible`="(pseudoR2:r2n)"),
                    list(
                        `name`="r2t", 
                        `title`="R\u00B2<sub>T</sub>", 
                        `type`="number", 
                        `visible`="(pseudoR2:r2t)"),
                    list(
                        `name`="chi", 
                        `title`="\u03C7\u00B2", 
                        `type`="number", 
                        `superTitle`="Overall Model Test", 
                        `visible`="(modelTest)"),
                    list(
                        `name`="df", 
                        `title`="df", 
                        `type`="integer", 
                        `superTitle`="Overall Model Test", 
                        `visible`="(modelTest)"),
                    list(
                        `name`="p", 
                        `title`="p", 
                        `type`="number", 
                        `format`="zto,pvalue", 
                        `superTitle`="Overall Model Test", 
                        `visible`="(modelTest)"))))
            self$add(jmvcore::Table$new(
                options=options,
                name="modelComp",
                title="Model Comparisons",
                clearWith=list(
                    "dep",
                    "blocks"),
                columns=list(
                    list(
                        `name`="model1", 
                        `title`="Model", 
                        `content`=".", 
                        `type`="text", 
                        `superTitle`="Comparison"),
                    list(
                        `name`="sep", 
                        `title`="", 
                        `content`="-", 
                        `type`="text", 
                        `format`="narrow", 
                        `superTitle`="Comparison"),
                    list(
                        `name`="model2", 
                        `title`="Model", 
                        `content`=".", 
                        `type`="text", 
                        `superTitle`="Comparison"),
                    list(
                        `name`="chi", 
                        `title`="\u03C7\u00B2", 
                        `type`="number"),
                    list(
                        `name`="df", 
                        `title`="df", 
                        `type`="integer"),
                    list(
                        `name`="p", 
                        `title`="p", 
                        `type`="number", 
                        `format`="zto,pvalue"))))
            self$add(jmvcore::Array$new(
                options=options,
                name="models",
                title="Model Specific Results",
                layout="listSelect",
                hideHeadingOnlyChild=TRUE,
                clearWith=list(
                    "blocks"),
                template=R6::R6Class(
                    inherit = jmvcore::Group,
                    active = list(
                        lrt = function() private$.items[["lrt"]],
                        coef = function() private$.items[["coef"]],
                        dataSummary = function() private$.items[["dataSummary"]],
                        assump = function() private$.items[["assump"]],
                        emm = function() private$.items[["emm"]],
                        pred = function() private$.items[["pred"]]),
                    private = list(),
                    public=list(
                        initialize=function(options) {
                            super$initialize(
                                options=options,
                                name="undefined",
                                title="")
                            self$add(jmvcore::Table$new(
                                options=options,
                                name="lrt",
                                title="Omnibus Likelihood Ratio Tests",
                                clearWith=list(
                                    "dep",
                                    "blocks"),
                                visible="(omni)",
                                refs="car",
                                columns=list(
                                    list(
                                        `name`="term", 
                                        `title`="Predictor", 
                                        `type`="text"),
                                    list(
                                        `name`="chi", 
                                        `title`="\u03C7\u00B2", 
                                        `type`="number"),
                                    list(
                                        `name`="df", 
                                        `title`="df", 
                                        `type`="integer"),
                                    list(
                                        `name`="p", 
                                        `title`="p", 
                                        `type`="number", 
                                        `format`="zto,pvalue"))))
                            self$add(jmvcore::Table$new(
                                options=options,
                                name="coef",
                                title="`Model Coefficients - ${dep}`",
                                clearWith=list(
                                    "dep",
                                    "blocks",
                                    "refLevels"),
                                columns=list(
                                    list(
                                        `name`="term", 
                                        `title`="Predictor", 
                                        `type`="text"),
                                    list(
                                        `name`="est", 
                                        `title`="Estimate", 
                                        `type`="number"),
                                    list(
                                        `name`="lower", 
                                        `title`="Lower", 
                                        `type`="number", 
                                        `visible`="(ci)"),
                                    list(
                                        `name`="upper", 
                                        `title`="Upper", 
                                        `type`="number", 
                                        `visible`="(ci)"),
                                    list(
                                        `name`="se", 
                                        `title`="SE", 
                                        `type`="number"),
                                    list(
                                        `name`="z", 
                                        `title`="Z", 
                                        `type`="number"),
                                    list(
                                        `name`="p", 
                                        `title`="p", 
                                        `type`="number", 
                                        `format`="zto,pvalue"),
                                    list(
                                        `name`="odds", 
                                        `title`="Odds ratio", 
                                        `type`="number", 
                                        `visible`="(OR)"),
                                    list(
                                        `name`="oddsLower", 
                                        `title`="Lower", 
                                        `type`="number", 
                                        `visible`="(ciOR && OR)"),
                                    list(
                                        `name`="oddsUpper", 
                                        `title`="Upper", 
                                        `type`="number", 
                                        `visible`="(ciOR && OR)"))))
                            self$add(R6::R6Class(
                                inherit = jmvcore::Group,
                                active = list(
                                    cooks = function() private$.items[["cooks"]]),
                                private = list(),
                                public=list(
                                    initialize=function(options) {
                                        super$initialize(
                                            options=options,
                                            name="dataSummary",
                                            title="Data Summary")
                                        self$add(jmvcore::Table$new(
                                            options=options,
                                            name="cooks",
                                            title="Cook's Distance",
                                            rows=1,
                                            visible="(cooks)",
                                            clearWith=list(
                                                "dep",
                                                "blocks"),
                                            columns=list(
                                                list(
                                                    `name`="mean", 
                                                    `title`="Mean", 
                                                    `type`="number"),
                                                list(
                                                    `name`="median", 
                                                    `title`="Median", 
                                                    `type`="number"),
                                                list(
                                                    `name`="sd", 
                                                    `title`="SD", 
                                                    `type`="number"),
                                                list(
                                                    `name`="min", 
                                                    `title`="Min", 
                                                    `type`="number", 
                                                    `superTitle`="Range"),
                                                list(
                                                    `name`="max", 
                                                    `title`="Max", 
                                                    `type`="number", 
                                                    `superTitle`="Range"))))}))$new(options=options))
                            self$add(R6::R6Class(
                                inherit = jmvcore::Group,
                                active = list(
                                    collin = function() private$.items[["collin"]],
                                    boxTidwell = function() private$.items[["boxTidwell"]]),
                                private = list(),
                                public=list(
                                    initialize=function(options) {
                                        super$initialize(
                                            options=options,
                                            name="assump",
                                            title="Assumption Checks")
                                        self$add(jmvcore::Table$new(
                                            options=options,
                                            name="collin",
                                            title="Collinearity Statistics",
                                            visible="(collin)",
                                            refs="car",
                                            clearWith=list(
                                                "dep",
                                                "blocks"),
                                            columns=list(
                                                list(
                                                    `name`="term", 
                                                    `title`="", 
                                                    `type`="text"),
                                                list(
                                                    `name`="vif", 
                                                    `title`="VIF", 
                                                    `type`="number"),
                                                list(
                                                    `name`="tol", 
                                                    `title`="Tolerance", 
                                                    `type`="number"))))
                                        self$add(jmvcore::Table$new(
                                            options=options,
                                            name="boxTidwell",
                                            title="Box-Tidwell Test for Linearity of the Logit",
                                            visible="(boxTidwell)",
                                            columns=list(
                                                list(
                                                    `name`="term", 
                                                    `title`="Predictor", 
                                                    `type`="text"),
                                                list(
                                                    `name`="est", 
                                                    `title`="Estimate", 
                                                    `type`="number"),
                                                list(
                                                    `name`="se", 
                                                    `title`="SE", 
                                                    `type`="number"),
                                                list(
                                                    `name`="z", 
                                                    `title`="Z", 
                                                    `type`="number"),
                                                list(
                                                    `name`="p", 
                                                    `title`="p", 
                                                    `type`="number", 
                                                    `format`="zto,pvalue"))))}))$new(options=options))
                            self$add(jmvcore::Array$new(
                                options=options,
                                name="emm",
                                title="Estimated Marginal Means",
                                refs="emmeans",
                                clearWith=list(
                                    "dep",
                                    "blocks",
                                    "emMeans"),
                                template=R6::R6Class(
                                    inherit = jmvcore::Group,
                                    active = list(
                                        emmPlot = function() private$.items[["emmPlot"]],
                                        emmTable = function() private$.items[["emmTable"]]),
                                    private = list(),
                                    public=list(
                                        initialize=function(options) {
                                            super$initialize(
                                                options=options,
                                                name="undefined",
                                                title="")
                                            self$add(jmvcore::Image$new(
                                                options=options,
                                                name="emmPlot",
                                                title="",
                                                width=450,
                                                height=400,
                                                renderFun=".emmPlot",
                                                visible="(emmPlots)",
                                                clearWith=list(
                                                    "dep",
                                                    "blocks",
                                                    "cutOff",
                                                    "refLevels",
                                                    "ciEmm",
                                                    "ciWidthEmm",
                                                    "emmWeights")))
                                            self$add(jmvcore::Table$new(
                                                options=options,
                                                name="emmTable",
                                                title="",
                                                visible="(emmTables)",
                                                columns=list(),
                                                clearWith=list(
                                                    "dep",
                                                    "blocks",
                                                    "cutOff",
                                                    "refLevels",
                                                    "ciWidthEmm",
                                                    "emmWeights")))}))$new(options=options)))
                            self$add(R6::R6Class(
                                inherit = jmvcore::Group,
                                active = list(
                                    cutOffPlot = function() private$.items[["cutOffPlot"]],
                                    class = function() private$.items[["class"]],
                                    measures = function() private$.items[["measures"]],
                                    rocPlot = function() private$.items[["rocPlot"]]),
                                private = list(),
                                public=list(
                                    initialize=function(options) {
                                        super$initialize(
                                            options=options,
                                            name="pred",
                                            title="Prediction")
                                        self$add(jmvcore::Image$new(
                                            options=options,
                                            name="cutOffPlot",
                                            title="Cut-Off Plot",
                                            width=450,
                                            height=430,
                                            renderFun=".cutOffPlot",
                                            visible="(cutOffPlot)",
                                            clearWith=list(
                                                "dep",
                                                "blocks",
                                                "cutOff",
                                                "refLevels")))
                                        self$add(jmvcore::Table$new(
                                            options=options,
                                            name="class",
                                            title="Classification Table",
                                            clearWith=list(
                                                "dep",
                                                "blocks",
                                                "cutOff",
                                                "refLevels"),
                                            rows=1,
                                            visible="(class)",
                                            columns=list()))
                                        self$add(jmvcore::Table$new(
                                            options=options,
                                            name="measures",
                                            title="Predictive Measures",
                                            clearWith=list(
                                                "dep",
                                                "blocks",
                                                "cutOff",
                                                "refLevels"),
                                            rows=1,
                                            visible="(acc || spec || sens || auc)",
                                            columns=list(
                                                list(
                                                    `name`="accuracy", 
                                                    `title`="Accuracy", 
                                                    `type`="number", 
                                                    `visible`="(acc)"),
                                                list(
                                                    `name`="spec", 
                                                    `title`="Specificity", 
                                                    `type`="number", 
                                                    `visible`="(spec)"),
                                                list(
                                                    `name`="sens", 
                                                    `title`="Sensitivity", 
                                                    `type`="number", 
                                                    `visible`="(sens)"),
                                                list(
                                                    `name`="auc", 
                                                    `title`="AUC", 
                                                    `type`="number", 
                                                    `visible`="(auc)"))))
                                        self$add(jmvcore::Image$new(
                                            options=options,
                                            name="rocPlot",
                                            title="ROC Curve",
                                            width=450,
                                            height=400,
                                            renderFun=".rocPlot",
                                            visible="(rocPlot)",
                                            refs="ROCR",
                                            clearWith=list(
                                                "dep",
                                                "blocks",
                                                "refLevels")))}))$new(options=options))}))$new(options=options)))
            self$add(jmvcore::Output$new(
                options=options,
                name="predictOV",
                title="Predicted values",
                measureType="continuous",
                clearWith=list(
                    "dep",
                    "blocks",
                    "refLevels")))
            self$add(jmvcore::Output$new(
                options=options,
                name="residsOV",
                title="Residuals",
                measureType="continuous",
                clearWith=list(
                    "dep",
                    "blocks",
                    "refLevels")))
            self$add(jmvcore::Output$new(
                options=options,
                name="cooksOV",
                title="Cook's distance",
                measureType="continuous",
                clearWith=list(
                    "dep",
                    "blocks",
                    "refLevels")))}))

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

#' Binomial Logistic Regression
#'
#' Binomial Logistic Regression
#'
#' @examples
#' data('birthwt', package='MASS')
#'
#' dat <- data.frame(
#'             low = factor(birthwt$low),
#'             age = birthwt$age,
#'             bwt = birthwt$bwt)
#'
#' logRegBin(data = dat, dep = low,
#'           covs = vars(age, bwt),
#'           blocks = list(list("age", "bwt")),
#'           refLevels = list(list(var="low", ref="0")))
#'
#' #
#' #  BINOMIAL LOGISTIC REGRESSION
#' #
#' #  Model Fit Measures
#' #  ---------------------------------------
#' #    Model    Deviance    AIC     R²-McF
#' #  ---------------------------------------
#' #        1     4.97e-7    6.00     1.000
#' #  ---------------------------------------
#' #
#' #
#' #  MODEL SPECIFIC RESULTS
#' #
#' #  MODEL 1
#' #
#' #  Model Coefficients
#' #  ------------------------------------------------------------
#' #    Predictor    Estimate      SE          Z           p
#' #  ------------------------------------------------------------
#' #    Intercept    2974.73225    218237.2      0.0136    0.989
#' #    age            -0.00653       482.7    -1.35e-5    1.000
#' #    bwt            -1.18532        87.0     -0.0136    0.989
#' #  ------------------------------------------------------------
#' #    Note. Estimates represent the log odds of "low = 1"
#' #    vs. "low = 0"
#' #
#' #
#'
#' @param data the data as a data frame
#' @param dep a string naming the dependent variable from \code{data},
#'   variable must be a factor
#' @param covs a vector of strings naming the covariates from \code{data}
#' @param factors a vector of strings naming the fixed factors from
#'   \code{data}
#' @param blocks a list containing vectors of strings that name the predictors
#'   that are added to the model. The elements are added to the model according
#'   to their order in the list
#' @param refLevels a list of lists specifying reference levels of the
#'   dependent variable and all the factors
#' @param modelTest \code{TRUE} or \code{FALSE} (default), provide the model
#'   comparison between the models and the NULL model
#' @param dev \code{TRUE} (default) or \code{FALSE}, provide the deviance (or
#'   -2LogLikelihood) for the models
#' @param aic \code{TRUE} (default) or \code{FALSE}, provide Aikaike's
#'   Information Criterion (AIC) for the models
#' @param bic \code{TRUE} or \code{FALSE} (default), provide Bayesian
#'   Information Criterion (BIC) for the models
#' @param pseudoR2 one or more of \code{'r2mf'}, \code{'r2cs'}, or
#'   \code{'r2n'}; use McFadden's, Cox & Snell, and Nagelkerke pseudo-R²,
#'   respectively
#' @param omni \code{TRUE} or \code{FALSE} (default), provide the omnibus
#'   likelihood ratio tests for the predictors
#' @param ci \code{TRUE} or \code{FALSE} (default), provide a confidence
#'   interval for the model coefficient estimates
#' @param ciWidth a number between 50 and 99.9 (default: 95) specifying the
#'   confidence interval width
#' @param OR \code{TRUE} or \code{FALSE} (default), provide the exponential of
#'   the log-odds ratio estimate, or the odds ratio estimate
#' @param ciOR \code{TRUE} or \code{FALSE} (default), provide a confidence
#'   interval for the model coefficient odds ratio estimates
#' @param ciWidthOR a number between 50 and 99.9 (default: 95) specifying the
#'   confidence interval width
#' @param emMeans a list of lists specifying the variables for which the
#'   estimated marginal means need to be calculate. Supports up to three
#'   variables per term.
#' @param ciEmm \code{TRUE} (default) or \code{FALSE}, provide a confidence
#'   interval for the estimated marginal means
#' @param ciWidthEmm a number between 50 and 99.9 (default: 95) specifying the
#'   confidence interval width for the estimated marginal means
#' @param emmPlots \code{TRUE} (default) or \code{FALSE}, provide estimated
#'   marginal means plots
#' @param emmTables \code{TRUE} or \code{FALSE} (default), provide estimated
#'   marginal means tables
#' @param emmWeights \code{TRUE} (default) or \code{FALSE}, weigh each cell
#'   equally or weigh them according to the cell frequency
#' @param class \code{TRUE} or \code{FALSE} (default), provide a predicted
#'   classification table (or confusion matrix)
#' @param acc \code{TRUE} or \code{FALSE} (default), provide the predicted
#'   accuracy of outcomes grouped by the cut-off value
#' @param spec \code{TRUE} or \code{FALSE} (default), provide the predicted
#'   specificity of outcomes grouped by the cut-off value
#' @param sens \code{TRUE} or \code{FALSE} (default), provide the predicted
#'   sensitivity of outcomes grouped by the cut-off value
#' @param auc \code{TRUE} or \code{FALSE} (default), provide the rea under the
#'   ROC curve (AUC)
#' @param rocPlot \code{TRUE} or \code{FALSE} (default), provide a ROC curve
#'   plot
#' @param cutOff \code{TRUE} or \code{FALSE} (default), set a cut-off used for
#'   the predictions
#' @param cutOffPlot \code{TRUE} or \code{FALSE} (default), provide a cut-off
#'   plot
#' @param collin \code{TRUE} or \code{FALSE} (default), provide VIF and
#'   tolerence collinearity statistics
#' @param boxTidwell \code{TRUE} or \code{FALSE} (default), provide
#'   Box-Tidwell test for linearity of the logit
#' @param cooks \code{TRUE} or \code{FALSE} (default), provide summary
#'   statistics for the Cook's distance
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$modelFit} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$modelComp} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$models} \tab \tab \tab \tab \tab an array of model specific results \cr
#'   \code{results$predictOV} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$residsOV} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$cooksOV} \tab \tab \tab \tab \tab an output \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$modelFit$asDF}
#'
#' \code{as.data.frame(results$modelFit)}
#'
#' @export
logRegBin <- function(
    data,
    dep,
    covs = NULL,
    factors = NULL,
    blocks = list(
                list()),
    refLevels = NULL,
    modelTest = FALSE,
    dev = TRUE,
    aic = TRUE,
    bic = FALSE,
    pseudoR2 = list(
                "r2mf"),
    omni = FALSE,
    ci = FALSE,
    ciWidth = 95,
    OR = FALSE,
    ciOR = FALSE,
    ciWidthOR = 95,
    emMeans = list(
                list()),
    ciEmm = TRUE,
    ciWidthEmm = 95,
    emmPlots = TRUE,
    emmTables = FALSE,
    emmWeights = TRUE,
    class = FALSE,
    acc = FALSE,
    spec = FALSE,
    sens = FALSE,
    auc = FALSE,
    rocPlot = FALSE,
    cutOff = 0.5,
    cutOffPlot = FALSE,
    collin = FALSE,
    boxTidwell = FALSE,
    cooks = FALSE) {

    if ( ! requireNamespace("jmvcore", quietly=TRUE))
        stop("logRegBin 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(factors)) factors <- jmvcore::resolveQuo(jmvcore::enquo(factors))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(dep), dep, NULL),
            `if`( ! missing(covs), covs, NULL),
            `if`( ! missing(factors), factors, NULL))

    for (v in dep) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
    for (v in factors) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
    if (inherits(emMeans, "formula")) emMeans <- jmvcore::decomposeFormula(emMeans)

    options <- logRegBinOptions$new(
        dep = dep,
        covs = covs,
        factors = factors,
        blocks = blocks,
        refLevels = refLevels,
        modelTest = modelTest,
        dev = dev,
        aic = aic,
        bic = bic,
        pseudoR2 = pseudoR2,
        omni = omni,
        ci = ci,
        ciWidth = ciWidth,
        OR = OR,
        ciOR = ciOR,
        ciWidthOR = ciWidthOR,
        emMeans = emMeans,
        ciEmm = ciEmm,
        ciWidthEmm = ciWidthEmm,
        emmPlots = emmPlots,
        emmTables = emmTables,
        emmWeights = emmWeights,
        class = class,
        acc = acc,
        spec = spec,
        sens = sens,
        auc = auc,
        rocPlot = rocPlot,
        cutOff = cutOff,
        cutOffPlot = cutOffPlot,
        collin = collin,
        boxTidwell = boxTidwell,
        cooks = cooks)

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

    analysis$run()

    analysis$results
}

Try the jmv package in your browser

Any scripts or data that you put into this service are public.

jmv documentation built on June 22, 2024, 10:40 a.m.