These functions are used in conjunction with the determinantStructure
family of funtions to conveniently work with determinant structures.
detStructAddVarLabels(determinantStructure, varLabelDf, varNameCol = "varNames.cln", leftAnchorCol = "leftAnchors", rightAnchorCol = "rightAnchors", subQuestionCol = "subQuestions", questionTextCol = "questionText") detStructAddVarNames(determinantStructure, names) detStructComputeProducts(determinantStructure, dat, append = TRUE) detStructComputeScales(determinantStructure, dat, append = TRUE, separator = "_")
determinantStructure | The |
---|---|
varLabelDf | The variable label dataframe as generated by |
varNameCol | The name of the column of the |
leftAnchorCol | The name of the column of the |
rightAnchorCol | The name of the column of the |
subQuestionCol | The name of the column of the |
questionTextCol | The name of the column of the |
names | A character vector with the variable names. These are matched against the
regular expressions as specified in the |
dat | The dataframe containing the data; the variables names specified in
|
append | Whether to only return the products or scales, or whether to append these to the dataframe and return the entire dataframe. |
separator | The separator to use when constructing the scale variables names. |
This family of functions will be explained more in detail in a forthcoming paper.
detStructAddVarLabels
and detStructAddVarNames
just change the
determinantStructure
object; detStructComputeProducts
and detStructComputeScales
return either the dataframe with the
new variables appended (if append
= TRUE
) or just a
dataframe with the new variables (if append
= FALSE
).
(Forthcoming)
### Generate a silly determinant structure detStruct <- determinantStructure('This makes no sense', list('mpg', behaviorRegEx = 'mpg'), determinantVar("Proximal determinant", "t", determinantVar("Determinant", "p", subdeterminants("Subdeterminants", "a")))); ### Add the variable names detStructAddVarNames(detStruct, names(mtcars));#> Error in detStructAddVarNames(detStruct, names(mtcars)): attempt to apply non-function### Add the determinant scale variable to the dataframe mtcarsPlus <- detStructComputeScales(detStruct, mtcars);#> Error in detStructComputeScales(detStruct, mtcars): The first argument must be a determint structure object!### Show its presence names(mtcarsPlus);#> Error in eval(expr, envir, enclos): object 'mtcarsPlus' not foundmean(mtcarsPlus$mpg_Determinant);#> Error in mean(mtcarsPlus$mpg_Determinant): object 'mtcarsPlus' not found