Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: jmv
Type: Package
Title: The 'jamovi' Analyses
Version: 2.2.3
Version: 2.3
Date: 2021-11-18
Author: Ravi Selker, Jonathon Love, Damian Dropmann, Victor Moreno
Maintainer: Jonathon Love <jon@thon.cc>
Expand All @@ -15,7 +15,7 @@ License: GPL (>= 2)
Depends:
R (>= 3.2)
Imports:
jmvcore (>= 1.8),
jmvcore (>= 2.3),
R6,
car (>= 3.0.0),
multcomp,
Expand Down Expand Up @@ -43,5 +43,5 @@ Suggests:
knitr,
rmarkdown
Encoding: UTF-8
RoxygenNote: 7.1.0
RoxygenNote: 6.1.1
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(ttestOneS)
export(ttestPS)
import(ggplot2)
import(jmvcore)
importFrom(jmvcore,.)
importFrom(jmvcore,matchSet)
importFrom(stats,aggregate.data.frame)
importFrom(stats,complete.cases)
Expand Down
91 changes: 52 additions & 39 deletions R/ancova.b.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#' @import ggplot2
#' @importFrom jmvcore matchSet
#' @importFrom jmvcore .
ancovaClass <- R6::R6Class(
"ancovaClass",
inherit=ancovaBase,
Expand Down Expand Up @@ -44,10 +45,11 @@ ancovaClass <- R6::R6Class(

data <- self$finalData

errorMessage <- .("Column '{name}' contains unused levels (possible only when rows with missing values are excluded)")
for (name in colnames(data)) {
column <- data[[name]]
if (is.factor(column) && any(table(column) == 0))
reject("Column '{}' contains unused levels (possibly only when rows with missing values are excluded)", name=name)
reject(errorMessage, name=name)
}

dataB64 <- lapply(data, function(x) {
Expand Down Expand Up @@ -77,6 +79,9 @@ ancovaClass <- R6::R6Class(
factors <- self$options$factors
modelTerms <- private$.modelTerms()

singularErrorMessage <- .("Singular fit encountered; one or more predictor variables are a linear combination of other predictor variables.")
perfectFitErrorMessage <- .("Residual sum of squares and/or degrees of freedom is zero, indicating a perfect fit")

suppressWarnings({

base::options(contrasts = c("contr.sum","contr.poly"))
Expand Down Expand Up @@ -105,7 +110,7 @@ ancovaClass <- R6::R6Class(
if (isError(results)) {
message <- extractErrorMessage(results)
if (message == 'there are aliased coefficients in the model')
singular <- 'Singular fit encountered; one or more predictor variables are a linear combination of other predictor variables'
singular <- singularErrorMessage
results <- try(car::Anova(private$.model, type=2, singular.ok=TRUE), silent=TRUE)
}

Expand All @@ -119,7 +124,7 @@ ancovaClass <- R6::R6Class(
if (isError(results)) {
message <- extractErrorMessage(results)
if (message == 'there are aliased coefficients in the model')
singular <- 'Singular fit encountered; one or more predictor variables are a linear combination of other predictor variables'
singular <- singularErrorMessage
results <- try({
r <- car::Anova(private$.model, type=3, singular.ok=TRUE, silent=TRUE)
r <- r[-1,]
Expand All @@ -130,11 +135,11 @@ ancovaClass <- R6::R6Class(
if (isError(results)) {
message <- extractErrorMessage(results)
if (message == 'residual df = 0')
reject('Residual sum of squares and/or degrees of freedom is zero, indicating a perfect fit')
reject(perfectFitErrorMessage)
}

if (results['Residuals', 'Sum Sq'] == 0 || results['Residuals', 'Df'] == 0)
reject('Residual sum of squares and/or degrees of freedom is zero, indicating a perfect fit')
reject(perfectFitErrorMessage)

}) # suppressWarnings

Expand All @@ -148,7 +153,7 @@ ancovaClass <- R6::R6Class(
table <- self$results$main

if (self$options$modelTest) {
table$addRow(rowKey='.', list(name='Overall model'))
table$addRow(rowKey='.', list(name=.('Overall model')))
table$addFormat(rowKey='.', col=1, format=Cell.BEGIN_END_GROUP)
}

Expand All @@ -168,7 +173,7 @@ ancovaClass <- R6::R6Class(
table$addFormat(rowKey='...', col=1, format=Cell.BEGIN_END_GROUP)
}

table$addRow(rowKey='', list(name='Residuals'))
table$addRow(rowKey='', list(name=.('Residuals')))
table$addFormat(rowKey='', col=1, format=Cell.BEGIN_END_GROUP)

if (self$options$ss == '1') {
Expand Down Expand Up @@ -209,36 +214,38 @@ ancovaClass <- R6::R6Class(
tables <- self$results$postHoc

postHocRows <- list()
postHocTableTitle <- .('Post Hoc Comparisons - {term}')

for (ph in phTerms) {

table <- tables$get(key=ph)

table$setTitle(paste0('Post Hoc Comparisons - ', stringifyTerm(ph)))
table$setTitle(jmvcore::format(postHocTableTitle, term=stringifyTerm(ph)))

for (i in seq_along(ph))
table$addColumn(name=paste0(ph[i],'1'), title=ph[i], type='text', superTitle='Comparison', combineBelow=TRUE)
table$addColumn(name=paste0(ph[i],'1'), title=ph[i], type='text', superTitle=.('Comparison'), combineBelow=TRUE)

table$addColumn(name='sep', title='', type='text', content='-', superTitle='Comparison', format='narrow')
table$addColumn(name='sep', title='', type='text', content='-', superTitle=.('Comparison'), format='narrow')

for (i in seq_along(ph))
table$addColumn(name=paste0(ph[i],'2'), title=ph[i], type='text', superTitle='Comparison')
table$addColumn(name=paste0(ph[i],'2'), title=ph[i], type='text', superTitle=.('Comparison'))

table$addColumn(name='md', title=.('Mean Difference'), type='number')
table$addColumn(name='se', title=.('SE'), type='number')
table$addColumn(name='df', title=.('df'), type='number')
table$addColumn(name='t', title=.('t'), type='number')

table$addColumn(name='md', title='Mean Difference', type='number')
table$addColumn(name='se', title='SE', type='number')
table$addColumn(name='df', title='df', type='number')
table$addColumn(name='t', title='t', type='number')
table$addColumn(name='pnone', title=.('p'), type='number', format='zto,pvalue', visible="(postHocCorr:none)")
table$addColumn(name='ptukey', title=.('p<sub>tukey</sub>'), type='number', format='zto,pvalue', visible="(postHocCorr:tukey)")
table$addColumn(name='pscheffe', title=.('p<sub>scheffe</sub>'), type='number', format='zto,pvalue', visible="(postHocCorr:scheffe)")
table$addColumn(name='pbonferroni', title=.('p<sub>bonferroni</sub>'), type='number', format='zto,pvalue', visible="(postHocCorr:bonf)")
table$addColumn(name='pholm', title=.('p<sub>holm</sub>'), type='number', format='zto,pvalue', visible="(postHocCorr:holm)")

table$addColumn(name='pnone', title='p', type='number', format='zto,pvalue', visible="(postHocCorr:none)")
table$addColumn(name='ptukey', title='p<sub>tukey</sub>', type='number', format='zto,pvalue', visible="(postHocCorr:tukey)")
table$addColumn(name='pscheffe', title='p<sub>scheffe</sub>', type='number', format='zto,pvalue', visible="(postHocCorr:scheffe)")
table$addColumn(name='pbonferroni', title='p<sub>bonferroni</sub>', type='number', format='zto,pvalue', visible="(postHocCorr:bonf)")
table$addColumn(name='pholm', title='p<sub>holm</sub>', type='number', format='zto,pvalue', visible="(postHocCorr:holm)")

ciTitleES <- paste0(self$options$postHocEsCiWidth, '% Confidence Interval')
table$addColumn(name='d', title='Cohen\'s d', type='number', visible="(postHocES:d)")
table$addColumn(name='dlower', title='Lower', type='number', visible="(postHocES:d && postHocEsCi)", superTitle=ciTitleES)
table$addColumn(name='dupper', title='Upper', type='number', visible="(postHocES:d && postHocEsCi)", superTitle=ciTitleES)
ciTitleES <- jmvcore::format(.('{ciWidth}% Confidence Interval'), ciWidth=self$options$postHocEsCiWidth)
table$addColumn(name='d', title=.("Cohen's d"), type='number', visible="(postHocES:d)")
table$addColumn(name='dlower', title=.('Lower'), type='number', visible="(postHocES:d && postHocEsCi)", superTitle=ciTitleES)
table$addColumn(name='dupper', title=.('Upper'), type='number', visible="(postHocES:d && postHocEsCi)", superTitle=ciTitleES)

combin <- expand.grid(bsLevels[rev(ph)])
combin <- sapply(combin, as.character, simplify = 'matrix')
Expand Down Expand Up @@ -276,7 +283,7 @@ ancovaClass <- R6::R6Class(
table$addFormat(rowNo=i, col=1, Cell.END_GROUP)
}

table$setNote('note', 'Comparisons are based on estimated marginal means')
table$setNote('note', .('Comparisons are based on estimated marginal means'))
}
private$.postHocRows <- postHocRows
},
Expand Down Expand Up @@ -305,6 +312,9 @@ ancovaClass <- R6::R6Class(
emMeans <- self$options$emMeans
group <- self$results$emm

emMeansTableTitle <- .('Estimated Marginal Means - {term}')
ciWidthTitle <- jmvcore::format(.('{ciWidth}% Confidence Interval'), ciWidth=self$options$ciWidthEmm)

for (j in seq_along(emMeans)) {

emm <- emMeans[[j]]
Expand All @@ -314,18 +324,18 @@ ancovaClass <- R6::R6Class(
emmGroup <- group$get(key=j)

table <- emmGroup$emmTable
table$setTitle(paste0('Estimated Marginal Means - ', jmvcore::stringifyTerm(emm)))
table$setTitle(jmvcore::format(emMeansTableTitle, term=jmvcore::stringifyTerm(emm)))

nLevels <- numeric(length(emm))
for (k in rev(seq_along(emm))) {
table$addColumn(name=emm[k], title=emm[k], type='text', combineBelow=TRUE)
nLevels[k] <- length(levels(self$data[[ emm[k] ]]))
}

table$addColumn(name='mean', title='Mean', type='number')
table$addColumn(name='se', title='SE', type='number')
table$addColumn(name='lower', title='Lower', type='number', superTitle=paste0(self$options$ciWidthEmm, '% Confidence Interval'))
table$addColumn(name='upper', title='Upper', type='number', superTitle=paste0(self$options$ciWidthEmm, '% Confidence Interval'))
table$addColumn(name='mean', title=.('Mean'), type='number')
table$addColumn(name='se', title=.('SE'), type='number')
table$addColumn(name='lower', title=.('Lower'), type='number', superTitle=ciWidthTitle)
table$addColumn(name='upper', title=.('Upper'), type='number', superTitle=ciWidthTitle)

nRows <- prod(nLevels)

Expand Down Expand Up @@ -647,8 +657,8 @@ ancovaClass <- R6::R6Class(
return(ggplot(data=df, aes(y=y, x=x)) +
geom_abline(slope=1, intercept=0, colour=theme$color[1]) +
geom_point(aes(x=x,y=y), size=2, colour=theme$color[1]) +
xlab("Theoretical Quantiles") +
ylab("Standardized Residuals") +
xlab(.("Theoretical Quantiles")) +
ylab(.("Standardized Residuals")) +
ggtheme)
},
.prepareEmmPlots = function(data) {
Expand Down Expand Up @@ -824,7 +834,10 @@ ancovaClass <- R6::R6Class(

} else if (type == 'polynomial') {

names <- c('linear', 'quadratic', 'cubic', 'quartic', 'quintic', 'sextic', 'septic', 'octic')
names <- c(
.('linear'), .('quadratic'), .('cubic'), .('quartic'),
.('quintic'), .('sextic'), .('septic'), .('octic')
)

for (i in seq_len(nLevels-1)) {
if (i <= length(names)) {
Expand Down Expand Up @@ -996,16 +1009,16 @@ ancovaClass <- R6::R6Class(
factors <- self$options$factors

if (is.factor(data[[dep]]))
reject('Dependent variable must be numeric')
reject(.('Dependent variable must be numeric'))

for (factorName in factors) {
lvls <- base::levels(data[[factorName]])
if (length(lvls) == 1)
reject("Factor '{}' contains only a single level", factorName=factorName)
else if (length(lvls) == 0)
reject("Factor '{}' contains no data", factorName=factorName)
if (length(lvls) == 1) {
reject(.("Factor '{factorName}' contains only a single level"), factorName=factorName)
} else if (length(lvls) == 0) {
reject(.("Factor '{factorName}' contains no data"), factorName=factorName)
}
}

}),
#### Active bindings ----
active=list(
Expand Down
12 changes: 4 additions & 8 deletions R/anova.b.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

#' @importFrom jmvcore .
anovaClass <- R6::R6Class(
"anovaClass",
inherit = ancovaClass,
private = list(
.init=function() {
super$.init()
self$results$setTitle('ANOVA')

if ( ! is.null(self$options$dep))
self$results$main$setTitle(paste0('ANOVA - ', self$options$dep))
else
self$results$main$setTitle('ANOVA - \u2026')

self$results$residsOV$setDescription('Residuals from ANOVA')
self$results$setTitle(.('ANOVA'))
self$results$main$setTitle(self$options$eval('`ANOVA - ${dep}`'))
self$results$residsOV$setDescription(.('Residuals from ANOVA'))
}
),
public = list(
Expand Down
30 changes: 18 additions & 12 deletions R/anovaonew.b.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#' @importFrom jmvcore .
anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
"anovaOneWClass",
inherit = anovaOneWBase,
Expand Down Expand Up @@ -50,8 +51,8 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
if (self$options$miss != 'listwise')
dataA <- na.omit(dataA)

welch <- oneway.test(dep ~ group, data=dataA, var.equal=FALSE)
fisher <- oneway.test(dep ~ group, data=dataA, var.equal=TRUE)
welch <- stats::oneway.test(dep ~ group, data=dataA, var.equal=FALSE)
fisher <- stats::oneway.test(dep ~ group, data=dataA, var.equal=TRUE)
residuals <- rstandard(lm(dep ~ group, data=dataA))

desc <- tapply(dataA$dep, dataA$group, function (x) {
Expand Down Expand Up @@ -87,9 +88,9 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
table <- self$results$anova

if (self$options$fishers && !self$options$welchs)
table$setTitle("One-Way ANOVA (Fisher's)")
table$setTitle(.("One-Way ANOVA (Fisher's)"))
else if (self$options$welchs && !self$options$fishers)
table$setTitle("One-Way ANOVA (Welch's)")
table$setTitle(.("One-Way ANOVA (Welch's)"))

},
.initDescTable = function() {
Expand Down Expand Up @@ -136,15 +137,17 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
return()

levels <- levels(self$data[[group]])
gamesHowellTableTitle <- .('Games-Howell Post-Hoc Test \u2013 {dep}')
tukeyTableTitle <- .('Tukey Post-Hoc Test \u2013 {dep}')

for (i in seq_along(deps)) {

table <- tables[[i]]

if (self$options$phMethod == 'gamesHowell')
table$setTitle(paste0('Games-Howell Post-Hoc Test \u2013 ', deps[i]))
table$setTitle(jmvcore::format(gamesHowellTableTitle, dep=deps[i]))
else if (self$options$phMethod == 'tukey')
table$setTitle(paste0('Tukey Post-Hoc Test \u2013 ', deps[i]))
table$setTitle(jmvcore::format(tukeyTableTitle, dep=deps[i]))

for (j in seq_along(levels)) {

Expand Down Expand Up @@ -247,6 +250,9 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
},
.populateShapiroWilkTable = function(results) {

tooFewSamplesMessage <- .('Too few samples to compute statistic (N < {n})')
tooManySamplesMessage <- .('Too many samples to compute statistic (N > {n})')

table <- self$results$assump$norm

for (dep in self$options$deps) {
Expand All @@ -260,13 +266,13 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(

row[['w']] <- NaN
row[['p']] <- ''
footnote <- 'Too few samples to compute statistic (N < 3)'
footnote <- jmvcore::format(tooFewSamplesMessage, n=3)

} else if (length(r) > 5000) {

row[['w']] <- NaN
row[['p']] <- ''
footnote <- 'Too many samples to compute statistic (N > 5000)'
footnote <- jmvcore::format(tooManySamplesMessage, n=5000)

} else {

Expand Down Expand Up @@ -361,8 +367,8 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(

groupName <- self$options$group

ciw <- 95
errorType <- paste0('Mean (', ciw, '% CI)')
ciLegendTitle<- .("Mean ({ciWidth}% CI)")
errorType <- jmvcore::format(ciLegendTitle, ciWidth=95)

p <- ggplot2::ggplot(data=image$state$df, ggplot2::aes(x=levels, y=mean)) +
ggplot2::geom_errorbar(ggplot2::aes(ymin=mean-ci, ymax=mean+ci, width=.1), size=.8, color=theme$color[2]) +
Expand Down Expand Up @@ -399,8 +405,8 @@ anovaOneWClass <- if (requireNamespace('jmvcore')) R6::R6Class(
p <- ggplot2::ggplot(data=image$state, ggplot2::aes(y=y, x=x)) +
ggplot2::geom_abline(slope=1, intercept=0, colour=theme$color[1]) +
ggplot2::geom_point(size=2, colour=theme$color[1]) +
ggplot2::xlab("Theoretical Quantiles") +
ggplot2::ylab("Standardized Residuals") +
ggplot2::xlab(.("Theoretical Quantiles")) +
ggplot2::ylab(.("Standardized Residuals")) +
ggtheme

return(p)
Expand Down
Loading