Skip to content

Commit

Permalink
Use geom_rangeframe and themeJaspRaw (#52)
Browse files Browse the repository at this point in the history
* Use themeJaspRaw()

* Use styler on R files

* Implement comments
  • Loading branch information
koenderks committed Oct 7, 2021
1 parent ac5cf04 commit 66a0e60
Show file tree
Hide file tree
Showing 14 changed files with 903 additions and 856 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: jaspBain
Type: Package
Title: Bain Module for JASP
Version: 1.1.0
Date: 2020-04-08
Version: 0.16
Date: 2021-10-03
Author: Herbert Hoijtink, Joris Mulder & Xin Gu
Website: www.informative-hypotheses.sites.uu.nl/software/bain/
Maintainer: Koen Derks <k.derks@nyenrode.nl>
Expand Down
1,158 changes: 597 additions & 561 deletions R/bainCommon.R

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions R/bainancovabayesian.R
Expand Up @@ -22,31 +22,31 @@ BainAncovaBayesian <- function(jaspResults, dataset, options, ...) {

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type)
# Read the data set

# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current data allow for analysis
.bainDataReady(dataList[["dataset"]], options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("dependent", "fixedFactors", "covariates", "model", "seed", "fraction"))

# Create a legend containing the order constrained hypotheses
.bainLegend(dataList[["dataset"]], options, type, jaspResults, position = 0)

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the Bayes factor matrix
.bainBfMatrix(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the descriptive statistics (coefficients) table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)
# Create the descriptive plot(s)

# Create the descriptive plot(s)
.bainDescriptivePlots(dataList[["dataset"]], options, bainContainer, ready, type, position = 5)
}
20 changes: 10 additions & 10 deletions R/bainanovabayesian.R
Expand Up @@ -22,31 +22,31 @@ BainAnovaBayesian <- function(jaspResults, dataset, options, ...) {

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type)

# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current data allow for analysis
.bainDataReady(dataList[["dataset"]], options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("dependent", "fixedFactors", "model", "seed", "fraction"))

# Create a legend containing the order constrained hypotheses
.bainLegend(dataList[["dataset"]], options, type, jaspResults, position = 0)

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the Bayes factor matrix
.bainBfMatrix(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the descriptive statistics table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)

# Create the descriptive plot(s)
.bainDescriptivePlots(dataList[["dataset"]], options, bainContainer, ready, type, position = 5)
}
}
18 changes: 9 additions & 9 deletions R/bainregressionlinearbayesian.R
Expand Up @@ -16,34 +16,34 @@
#

BainRegressionLinearBayesian <- function(jaspResults, dataset, options, ...) {

# What type of Bain analysis is being conducted?
type <- "regression"

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type)

# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current data allow for analysis
.bainDataReady(dataset, options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("dependent", "covariates", "model", "seed", "fraction", "standardized"))

# Create a legend containing the order constrained hypotheses
.bainLegend(dataList[["dataset"]], options, type, jaspResults, position = 0)

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the Bayes factor matrix
.bainBfMatrix(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the descriptive statistics (coefficients) table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)
}
71 changes: 39 additions & 32 deletions R/bainsembayesian.R
Expand Up @@ -16,36 +16,36 @@
#

BainSemBayesian <- function(jaspResults, dataset, options, ...) {

# What type of Bain analysis is being conducted?
type <- "sem"
# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type, dataList[["dataset"]])

# Check if current data allow for analysis
.bainDataReady(dataList[["dataset"]], options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("syntax", "model", "seed", "fraction", "standardized", "fixedFactors", "factorStandardisation"))

# Create a legend containing the order constrained hypotheses
.bainLegend(dataList[["dataset"]], options, type, jaspResults, position = 0)

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the Bayes factor matrix
.bainBfMatrix(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the descriptive statistics (coefficients) table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)

# Create the path diagram plot
.bainSemPathDiagram(dataList[["dataset"]], options, bainContainer, ready, jaspResults, position = 5)
}
Expand All @@ -54,26 +54,30 @@ BainSemBayesian <- function(jaspResults, dataset, options, ...) {
vv <- availablevars
# This regex will isolate all manifest variables in the SEM model
# Model:
# A =~ Ab + Al + Af + An + Ar + Ac
# B =~ Bb + Bl + Bf + Bn + Br + Bc
# A =~ Ab + Al + Af + An + Ar + Ac
# B =~ Bb + Bl + Bf + Bn + Br + Bc
# Returns:
# Ab, Al, Af, An, Ar, Ac, Bb, Bl, Bf, Bn, Br, Bc
findpattern <- paste0("(?<=[\\s\\+\\^\\=\\~\\<\\*\\>\\:\\%\\|\\+]|^)\\Q",
vv,
"\\E(?=[\\s\\+\\^\\=\\~\\<\\*\\>\\:\\%\\|\\+]|$)")
findpattern <- paste0(
"(?<=[\\s\\+\\^\\=\\~\\<\\*\\>\\:\\%\\|\\+]|^)\\Q",
vv,
"\\E(?=[\\s\\+\\^\\=\\~\\<\\*\\>\\:\\%\\|\\+]|$)"
)
return(vv[vapply(findpattern,
function(p) stringr::str_detect(syntax, p),
FUN.VALUE = TRUE,
USE.NAMES = FALSE)])
function(p) stringr::str_detect(syntax, p),
FUN.VALUE = TRUE,
USE.NAMES = FALSE
)])
}

.bainSemTranslateModel <- function(syntax, dataset) {
usedvars <- .bainSemGetUsedVars(syntax, colnames(dataset))
if (length(usedvars) == 0)
if (length(usedvars) == 0) {
return(syntax)
}
usedvars <- usedvars[order(nchar(usedvars), decreasing = TRUE)]
withSingleQuotes <- paste("\\b'", usedvars, "'\\b", sep="")
withDoubleQuotes <- paste('\\b"', usedvars, '"\\b', sep="")
withSingleQuotes <- paste("\\b'", usedvars, "'\\b", sep = "")
withDoubleQuotes <- paste('\\b"', usedvars, '"\\b', sep = "")
newNames <- usedvars
for (i in 1:length(usedvars)) {
syntax <- gsub(withDoubleQuotes[i], newNames[i], syntax)
Expand All @@ -88,10 +92,10 @@ BainSemBayesian <- function(jaspResults, dataset, options, ...) {
}

.bainSemPathDiagram <- function(dataset, options, bainContainer, ready, jaspResults, position) {

if (!is.null(bainContainer[["pathDiagram"]]) || !options[["pathDiagram"]])
if (!is.null(bainContainer[["pathDiagram"]]) || !options[["pathDiagram"]]) {
return()

}

if (options[["fixedFactors"]] == "") {
plot <- createJaspPlot(title = gettext("Path Diagram"), width = 600, height = 400)
plot$dependOn(options = c("pathDiagram", "seed", "pathDiagramEstimates", "pathDiagramLegend"))
Expand All @@ -106,13 +110,14 @@ BainSemBayesian <- function(jaspResults, dataset, options, ...) {
container[[paste0("pathDiagram", groups[i])]] <- plot
}
}
if (!ready || is.null(bainContainer[["lavaanResult"]]))

if (!ready || is.null(bainContainer[["lavaanResult"]])) {
return()

}

labels <- ifelse(options[["pathDiagramEstimates"]], "par", "name")
labels <- ifelse(options[["standardized"]], "stand", labels)

fit <- bainContainer[["lavaanResult"]]$object
po <- .bainlavToPlotObj(fit)
error <- try({
Expand All @@ -137,7 +142,7 @@ BainSemBayesian <- function(jaspResults, dataset, options, ...) {
ask = FALSE
))
})

if (isTryError(error)) {
plot$setError(gettextf("An error occurred while creating this plot:<br>%1$s.", jaspBase::.extractErrorMessage(error)))
} else {
Expand All @@ -156,10 +161,12 @@ BainSemBayesian <- function(jaspResults, dataset, options, ...) {
manifests <- semPlotMod@Vars$name[semPlotMod@Vars$manifest]
semPlotMod@Vars$name[semPlotMod@Vars$manifest] <- decodeColNames(manifests)
lhsAreManifest <- semPlotMod@Pars$lhs %in% manifests
if (any(lhsAreManifest))
if (any(lhsAreManifest)) {
semPlotMod@Pars$lhs[lhsAreManifest] <- decodeColNames(semPlotMod@Pars$lhs[lhsAreManifest])
}
rhsAreManifest <- semPlotMod@Pars$rhs %in% manifests
if (any(rhsAreManifest))
if (any(rhsAreManifest)) {
semPlotMod@Pars$rhs[rhsAreManifest] <- decodeColNames(semPlotMod@Pars$rhs[rhsAreManifest])
}
return(semPlotMod)
}
}
18 changes: 9 additions & 9 deletions R/bainttestbayesianindependentsamples.R
Expand Up @@ -19,28 +19,28 @@ BainTTestBayesianIndependentSamples <- function(jaspResults, dataset, options, .

# What type of Bain analysis is being conducted?
type <- "independentTTest"

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type)
# Read the data set

# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current data allow for analysis
.bainDataReady(dataList[["dataset"]], options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("groupingVariable", "seed", "fraction"))

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the descriptive statistics table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the descriptive plot(s)
.bainDescriptivePlots(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)
}
20 changes: 10 additions & 10 deletions R/bainttestbayesianonesample.R
Expand Up @@ -19,28 +19,28 @@ BainTTestBayesianOneSample <- function(jaspResults, dataset, options, ...) {

# What type of Bain analysis is being conducted?
type <- "onesampleTTest"

# Check if current options allow for analysis
ready <- .bainOptionsReady(options, type = "onesampleTTest")
# Read the data set

# Read the data set
dataList <- .bainReadDataset(options, type, dataset)

# Check if current data allow for analysis
.bainDataReady(dataset, options, type)

# Create a container for the results
bainContainer <- .bainGetContainer(jaspResults, deps = c("testValue", "seed", "fraction"))

# Create a table containing the main analysis results
.bainTestResultsTable(dataList[["dataset"]], options, bainContainer, dataList[["missing"]], ready, type, position = 1)

# Create the descriptive statistics table
.bainDescriptivesTable(dataList[["dataset"]], options, bainContainer, ready, type, position = 2)

# Create the posterior probability plots
.bainPosteriorProbabilityPlot(dataList[["dataset"]], options, bainContainer, ready, type, position = 3)

# Create the descriptive plot(s)
.bainDescriptivePlots(dataList[["dataset"]], options, bainContainer, ready, type, position = 4)
}
}

0 comments on commit 66a0e60

Please sign in to comment.