-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added function Transform (Reduce Skewness)
- Loading branch information
Showing
8 changed files
with
516 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
# This file is a generated template, your changes will not be overwritten | ||
|
||
jtTransformVarsClass <- if (requireNamespace('jmvcore', quietly=TRUE)) R6::R6Class( | ||
"jtTransformVarsClass", | ||
inherit = jtTransformVarsBase, | ||
private = list( | ||
.xfmDta = NULL, | ||
.inpDta = NULL, | ||
|
||
.init = function() { | ||
if (private$.chkVar()) { | ||
private$.xfmDta <- do.call(jmvReadWrite::transform_vars_omv, private$.crrArg()) | ||
# resize / prepare the output table (prpPvw in utils.R) | ||
prpPvw(crrTbl = self$results$pvwDta, dtaFrm = private$.xfmDta, colFst = private$.colFst()) | ||
} else { | ||
# reset the output table (rstPvw in utils.R) | ||
rstPvw(crrTbl = self$results$pvwDta) | ||
} | ||
}, | ||
|
||
.run = function() { | ||
# check whether there are at least two variables in varOrd and that the data set has at least one row | ||
if (private$.chkVar() && dim(self$data)[1] >= 1) { | ||
# if “Create” was pressed (btnCrt == TRUE), open a new jamovi session with the data | ||
if (self$options$btnCrt) { | ||
do.call(jmvReadWrite::transform_vars_omv, private$.crrArg()[-2]) | ||
# if not, show the variable list and how to use “Create” as general information | ||
# and create a preview of the data (crtInf and fllPvw in utils.R) | ||
} else { | ||
crtInf(crrInf = self$results$genInf, dtaFrm = private$.xfmDta, hlpMsg = hlpCrt) | ||
fllPvw(crrTbl = self$results$pvwDta, dtaFrm = private$.xfmDta) | ||
} | ||
} else { | ||
# show getting started as general information (crtInf in utils.R) | ||
crtInf(crrInf = self$results$genInf, hlpMsg = hlpXfV) | ||
} | ||
}, | ||
|
||
.chkVar = function() { | ||
(length(self$options$posSqr) >= 1 || length(self$options$negSqr) >= 1 || | ||
length(self$options$posLog) >= 1 || length(self$options$negLog) >= 1 || | ||
length(self$options$posInv) >= 1 || length(self$options$negInv) >= 1) | ||
}, | ||
|
||
.colFst = function() { | ||
c(setdiff(names(private$.xfmDta), names(private$.inpDta)), names(private$.inpDta)) | ||
}, | ||
|
||
.crrArg = function() { | ||
if (!is.null(self$data) && dim(self$data)[1] > 0) private$.inpDta <- self$data else private$.inpDta <- self$readDataset() | ||
crrXfm <- setNames(lapply(c("posSqr", "negSqr", "posLog", "negLog", "posInv", "negInv"), function(x) self$options[[x]]), | ||
c("posSqr", "negSqr", "posLog", "negLog", "posInv", "negInv")) | ||
list(dtaInp = private$.inpDta, fleOut = NULL, varXfm = crrXfm) | ||
} | ||
|
||
), | ||
|
||
public = list( | ||
|
||
asSource = function() { | ||
if (private$.chkVar()) fmtSrc("jmvReadWrite::arrange_cols_omv", private$.crrArg()[c(-1, -2)]) | ||
} | ||
|
||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
|
||
# This file is automatically generated, you probably don't want to edit this | ||
|
||
jtTransformVarsOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class( | ||
"jtTransformVarsOptions", | ||
inherit = jmvcore::Options, | ||
public = list( | ||
initialize = function( | ||
varAll = NULL, | ||
posSqr = NULL, | ||
negSqr = NULL, | ||
posLog = NULL, | ||
negLog = NULL, | ||
posInv = NULL, | ||
negInv = NULL, | ||
btnCrt = FALSE, ...) { | ||
|
||
super$initialize( | ||
package="jTransform", | ||
name="jtTransformVars", | ||
requiresData=TRUE, | ||
...) | ||
|
||
private$..varAll <- jmvcore::OptionVariables$new( | ||
"varAll", | ||
varAll, | ||
hidden=TRUE, | ||
permitted=list( | ||
"numeric", | ||
"factor", | ||
"id"), | ||
default=NULL) | ||
private$..posSqr <- jmvcore::OptionVariables$new( | ||
"posSqr", | ||
posSqr, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..negSqr <- jmvcore::OptionVariables$new( | ||
"negSqr", | ||
negSqr, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..posLog <- jmvcore::OptionVariables$new( | ||
"posLog", | ||
posLog, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..negLog <- jmvcore::OptionVariables$new( | ||
"negLog", | ||
negLog, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..posInv <- jmvcore::OptionVariables$new( | ||
"posInv", | ||
posInv, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..negInv <- jmvcore::OptionVariables$new( | ||
"negInv", | ||
negInv, | ||
suggested=list( | ||
"continuous"), | ||
permitted=list( | ||
"numeric")) | ||
private$..btnCrt <- jmvcore::OptionAction$new( | ||
"btnCrt", | ||
btnCrt, | ||
default=FALSE) | ||
|
||
self$.addOption(private$..varAll) | ||
self$.addOption(private$..posSqr) | ||
self$.addOption(private$..negSqr) | ||
self$.addOption(private$..posLog) | ||
self$.addOption(private$..negLog) | ||
self$.addOption(private$..posInv) | ||
self$.addOption(private$..negInv) | ||
self$.addOption(private$..btnCrt) | ||
}), | ||
active = list( | ||
varAll = function() private$..varAll$value, | ||
posSqr = function() private$..posSqr$value, | ||
negSqr = function() private$..negSqr$value, | ||
posLog = function() private$..posLog$value, | ||
negLog = function() private$..negLog$value, | ||
posInv = function() private$..posInv$value, | ||
negInv = function() private$..negInv$value, | ||
btnCrt = function() private$..btnCrt$value), | ||
private = list( | ||
..varAll = NA, | ||
..posSqr = NA, | ||
..negSqr = NA, | ||
..posLog = NA, | ||
..negLog = NA, | ||
..posInv = NA, | ||
..negInv = NA, | ||
..btnCrt = NA) | ||
) | ||
|
||
jtTransformVarsResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class( | ||
"jtTransformVarsResults", | ||
inherit = jmvcore::Group, | ||
active = list( | ||
genInf = function() private$.items[["genInf"]], | ||
pvwDta = function() private$.items[["pvwDta"]]), | ||
private = list(), | ||
public=list( | ||
initialize=function(options) { | ||
super$initialize( | ||
options=options, | ||
name="", | ||
title="Transform (Reduce Skewness)") | ||
self$add(jmvcore::Html$new( | ||
options=options, | ||
name="genInf", | ||
clearWith=list( | ||
"varOrd", | ||
"blnAll", | ||
"btnCrt"))) | ||
self$add(jmvcore::Table$new( | ||
options=options, | ||
name="pvwDta", | ||
title="Data Preview", | ||
refs=list( | ||
"jTransform", | ||
"jmvReadWrite"), | ||
clearWith=list( | ||
"varOrd", | ||
"blnAll"), | ||
rows=1, | ||
columns=list( | ||
list( | ||
`name`="fstCol", | ||
`title`=""))))})) | ||
|
||
jtTransformVarsBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class( | ||
"jtTransformVarsBase", | ||
inherit = jmvcore::Analysis, | ||
public = list( | ||
initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) { | ||
super$initialize( | ||
package = "jTransform", | ||
name = "jtTransformVars", | ||
version = c(1,0,0), | ||
options = options, | ||
results = jtTransformVarsResults$new(options=options), | ||
data = data, | ||
datasetId = datasetId, | ||
analysisId = analysisId, | ||
revision = revision, | ||
pause = NULL, | ||
completeWhenFilled = TRUE, | ||
requiresMissings = FALSE, | ||
weightsSupport = 'auto') | ||
})) | ||
|
||
#' Transform (Reduce Skewness) | ||
#' | ||
#' Create New (Computed) Variables, Aiming At Reducing Deviations From A | ||
#' Normal Distribution | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' # the function is a wrapper for jmvReadWrite::transform_vars_omv | ||
#' # please use that function when in R (or in Rj) | ||
#' # for more information: https://sjentsch.github.io/jmvReadWrite | ||
#'} | ||
#' @param data . | ||
#' @param varAll . | ||
#' @param posSqr . | ||
#' @param negSqr . | ||
#' @param posLog . | ||
#' @param negLog . | ||
#' @param posInv . | ||
#' @param negInv . | ||
#' @param btnCrt . | ||
#' @return A results object containing: | ||
#' \tabular{llllll}{ | ||
#' \code{results$genInf} \tab \tab \tab \tab \tab a html \cr | ||
#' \code{results$pvwDta} \tab \tab \tab \tab \tab a table \cr | ||
#' } | ||
#' | ||
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example: | ||
#' | ||
#' \code{results$pvwDta$asDF} | ||
#' | ||
#' \code{as.data.frame(results$pvwDta)} | ||
#' | ||
#' @export | ||
jtTransformVars <- function( | ||
data, | ||
varAll = NULL, | ||
posSqr, | ||
negSqr, | ||
posLog, | ||
negLog, | ||
posInv, | ||
negInv, | ||
btnCrt = FALSE) { | ||
|
||
if ( ! requireNamespace("jmvcore", quietly=TRUE)) | ||
stop("jtTransformVars requires jmvcore to be installed (restart may be required)") | ||
|
||
if ( ! missing(varAll)) varAll <- jmvcore::resolveQuo(jmvcore::enquo(varAll)) | ||
if ( ! missing(posSqr)) posSqr <- jmvcore::resolveQuo(jmvcore::enquo(posSqr)) | ||
if ( ! missing(negSqr)) negSqr <- jmvcore::resolveQuo(jmvcore::enquo(negSqr)) | ||
if ( ! missing(posLog)) posLog <- jmvcore::resolveQuo(jmvcore::enquo(posLog)) | ||
if ( ! missing(negLog)) negLog <- jmvcore::resolveQuo(jmvcore::enquo(negLog)) | ||
if ( ! missing(posInv)) posInv <- jmvcore::resolveQuo(jmvcore::enquo(posInv)) | ||
if ( ! missing(negInv)) negInv <- jmvcore::resolveQuo(jmvcore::enquo(negInv)) | ||
if (missing(data)) | ||
data <- jmvcore::marshalData( | ||
parent.frame(), | ||
`if`( ! missing(varAll), varAll, NULL), | ||
`if`( ! missing(posSqr), posSqr, NULL), | ||
`if`( ! missing(negSqr), negSqr, NULL), | ||
`if`( ! missing(posLog), posLog, NULL), | ||
`if`( ! missing(negLog), negLog, NULL), | ||
`if`( ! missing(posInv), posInv, NULL), | ||
`if`( ! missing(negInv), negInv, NULL)) | ||
|
||
|
||
options <- jtTransformVarsOptions$new( | ||
varAll = varAll, | ||
posSqr = posSqr, | ||
negSqr = negSqr, | ||
posLog = posLog, | ||
negLog = negLog, | ||
posInv = posInv, | ||
negInv = negInv, | ||
btnCrt = btnCrt) | ||
|
||
analysis <- jtTransformVarsClass$new( | ||
options = options, | ||
data = data) | ||
|
||
analysis$run() | ||
|
||
analysis$results | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.