diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 3d025704..8a2855fb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,16 +1,10 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - main - - master - - GitAction - + branches: [main, master, GitAction] pull_request: - branches: - - main - - master + branches: [main, master] name: R-CMD-check @@ -24,85 +18,44 @@ jobs: fail-fast: false matrix: config: + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - - {os: windows-latest, r: 'oldrel'} - - # - {os: macOS-latest, r: 'devel'} - - {os: macOS-latest, r: 'release'} - - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: windows-latest, r: 'devel'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - - - uses: actions/checkout@v3 - - - uses: r-lib/actions/setup-r@v2 - with: - r-version: ${{ matrix.config.r }} + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 - + - uses: r-lib/actions/setup-tinytex@v2 - run: tlmgr --version - - name: Query dependencies - run: | - setwd("DHARMa") - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), "../.github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), "../.github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - cd DHARMa - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true - - name: Install dependencies - run: | - setwd("DHARMa") - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check_II - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - CI: true - run: | - rcmdcheck::rcmdcheck("DHARMa", args = c("--no-multiarch", "--no-manual"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - CI: true - run: | - rcmdcheck::rcmdcheck("DHARMa", args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + working-directory: DHARMa + # second check with different rcmdcheck arguments. + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + working-directory: DHARMa + args: 'c("--no-multiarch", "--no-manual")' - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true + working-directory: DHARMa diff --git a/DHARMa/R/DHARMa.R b/DHARMa/R/DHARMa.R index dd6366d7..a996325b 100644 --- a/DHARMa/R/DHARMa.R +++ b/DHARMa/R/DHARMa.R @@ -95,7 +95,7 @@ outliers <- function(object, lowerQuantile = 0, upperQuantile = 1, return = c("i #' @note Either scaled residuals or (simulatedResponse AND observed response) have to be provided #' @example inst/examples/createDharmaHelp.R #' @export -createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedResponse = NULL, integerResponse = F, seed = 123, method = c("PIT", "traditional"), rotation = NULL){ +createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedResponse = NULL, integerResponse = FALSE, seed = 123, method = c("PIT", "traditional"), rotation = NULL){ randomState <-getRandomState(seed) on.exit({randomState$restoreCurrent()}) @@ -142,7 +142,7 @@ createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedR #' @return an object of class DHARMa #' @keywords internal ensureDHARMa <- function(simulationOutput, - convert = F){ + convert = FALSE){ if(inherits(simulationOutput, "DHARMa")){ return(simulationOutput) @@ -152,8 +152,8 @@ ensureDHARMa <- function(simulationOutput, else { if (class(simulationOutput)[1] %in% getPossibleModels()){ - if (convert == "Model" | convert == T) return(simulateResiduals(simulationOutput)) - } else if(is.vector(simulationOutput, mode = "numeric") & convert == T) { + if (convert == "Model" | convert == TRUE) return(simulateResiduals(simulationOutput)) + } else if(is.vector(simulationOutput, mode = "numeric") & convert == TRUE) { out = list() out$scaledResiduals = simulationOutput out$nObs = length(out$scaledResiduals) diff --git a/DHARMa/R/createData.R b/DHARMa/R/createData.R index ca01094b..85b7fb53 100644 --- a/DHARMa/R/createData.R +++ b/DHARMa/R/createData.R @@ -20,7 +20,7 @@ #' @param hasNA should an NA be added to the environmental predictor (for test purposes) #' @export #' @example /inst/examples/createDataHelp.R -createData <- function(sampleSize = 100, intercept = 0, fixedEffects = 1, quadraticFixedEffects = NULL, numGroups = 10, randomEffectVariance = 1, overdispersion = 0, family = poisson(), scale = 1, cor = 0, roundPoissonVariance = NULL, pZeroInflation = 0, binomialTrials = 1, temporalAutocorrelation = 0, spatialAutocorrelation =0, factorResponse = F, replicates=1, hasNA = F){ +createData <- function(sampleSize = 100, intercept = 0, fixedEffects = 1, quadraticFixedEffects = NULL, numGroups = 10, randomEffectVariance = 1, overdispersion = 0, family = poisson(), scale = 1, cor = 0, roundPoissonVariance = NULL, pZeroInflation = 0, binomialTrials = 1, temporalAutocorrelation = 0, spatialAutocorrelation =0, factorResponse = FALSE, replicates=1, hasNA = FALSE){ nPredictors = length(fixedEffects) diff --git a/DHARMa/R/plots.R b/DHARMa/R/plots.R index 0c77d533..64690888 100644 --- a/DHARMa/R/plots.R +++ b/DHARMa/R/plots.R @@ -4,7 +4,7 @@ #' #' @param x an object of class DHARMa with simulated residuals created by \code{\link{simulateResiduals}} #' @param ... further options for \code{\link{plotResiduals}}. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plot.DHARMa, but can be changed when using plotResiduals. -#' @param title The title for both panels (plotted via mtext, outer = T) +#' @param title The title for both panels (plotted via mtext, outer = TRUE) #' #' @details The function creates a plot with two panels. The left panel is a uniform qq plot (calling \code{\link{plotQQunif}}), and the right panel shows residuals against predicted values (calling \code{\link{plotResiduals}}), with outliers highlighted in red. #' @@ -31,7 +31,7 @@ plot.DHARMa <- function(x, title = "DHARMa residual", ...){ plotQQunif(x) plotResiduals(x, ...) - mtext(title, outer = T) + mtext(title, outer = TRUE) } @@ -57,7 +57,7 @@ hist.DHARMa <- function(x, cex.main = 1, ...){ - x = ensureDHARMa(x, convert = T) + x = ensureDHARMa(x, convert = TRUE) val = x$scaledResiduals val[val == 0] = -0.01 @@ -97,7 +97,7 @@ plotSimulatedResiduals <- function(simulationOutput, ...){ #' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}} #' @example inst/examples/plotsHelp.R #' @export -plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, testDispersion = T, ...){ +plotQQunif <- function(simulationOutput, testUniformity = TRUE, testOutliers = TRUE, testDispersion = TRUE, ...){ a <- list(...) a$pch = checkDots("pch", 2, ...) @@ -114,7 +114,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t do.call(gap::qqunif, append(list(simulationOutput$scaledResiduals), a)) if(testUniformity == TRUE){ - temp = testUniformity(simulationOutput, plot = F) + temp = testUniformity(simulationOutput, plot = FALSE) legend("topleft", c(paste("KS test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), @@ -123,7 +123,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t } if(testOutliers == TRUE){ - temp = testOutliers(simulationOutput, plot = F) + temp = testOutliers(simulationOutput, plot = FALSE) legend("bottomright", c(paste("Outlier test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), @@ -132,7 +132,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t } if(testDispersion == TRUE){ - temp = testDispersion(simulationOutput, plot = F) + temp = testDispersion(simulationOutput, plot = FALSE) legend("center", c(paste("Dispersion test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), @@ -175,7 +175,7 @@ plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, t #' @seealso \code{\link{plotQQunif}}, \code{\link{testQuantiles}}, \code{\link{testOutliers}} #' @example inst/examples/plotsHelp.R #' @export -plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = T, asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), absoluteDeviation = FALSE, ...){ +plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = TRUE, asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), absoluteDeviation = FALSE, ...){ ##### Checks ##### @@ -185,12 +185,12 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = a$ylab = checkDots("ylab", yAxis , ...) a$xlab = checkDots("xlab", ifelse(is.null(form), "Model predictions", gsub(".*[$]","",deparse(substitute(form)))), ...) - if(rank == T) a$xlab = paste(a$xlab, "(rank transformed)") + if(rank == TRUE) a$xlab = paste(a$xlab, "(rank transformed)") - simulationOutput = ensureDHARMa(simulationOutput, convert = T) + simulationOutput = ensureDHARMa(simulationOutput, convert = TRUE) res = simulationOutput$scaledResiduals - if(absoluteDeviation == T){ + if(absoluteDeviation == TRUE){ res = 2 * abs(res - 0.5) } @@ -202,7 +202,7 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = if(!is.factor(pred)){ - if (rank == T){ + if (rank == TRUE){ pred = rank(pred, ties.method = "average") pred = pred / max(pred) a$xlim = checkDots("xlim", c(0,1), ...) @@ -256,16 +256,16 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = out = NULL if(is.numeric(pred)){ - if(quantreg == F){ + if(quantreg == FALSE){ title(main = main, cex.main = 1) abline(h = quantiles, col = "black", lwd = 0.5, lty = 2) try({ lines(smooth.spline(pred, res, df = 10), lty = 2, lwd = 2, col = "red") abline(h = 0.5, col = "red", lwd = 2) - }, silent = T) + }, silent = TRUE) }else{ - out = testQuantiles(res, pred, quantiles = quantiles, plot = F) + out = testQuantiles(res, pred, quantiles = quantiles, plot = FALSE) if(any(out$pvals < 0.05, na.rm = TRUE)){ @@ -293,7 +293,7 @@ plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = abline(h = quantiles[i], col = lineCol, lwd = 0.5, lty = 2) polygon(c(out$predictions$pred, rev(out$predictions$pred)), c(out$predictions[,2*i] - out$predictions[,2*i+1], rev(out$predictions[,2*i] + out$predictions[,2*i+1])), - col = "#00000020", border = F) + col = "#00000020", border = FALSE) lines(out$predictions$pred, out$predictions[,2*i], col = lineCol, lwd = 2) } @@ -358,7 +358,7 @@ plotConventionalResiduals <- function(fittedModel){ plot(predict(fittedModel), resid(fittedModel, type = "deviance"), main = "Deviance" , ylab = "Residual", xlab = "Predicted") plot(predict(fittedModel), resid(fittedModel, type = "pearson") , main = "Pearson", ylab = "Residual", xlab = "Predicted") plot(predict(fittedModel), resid(fittedModel, type = "response") , main = "Raw residuals" , ylab = "Residual", xlab = "Predicted") - mtext("Conventional residual plots", outer = T) + mtext("Conventional residual plots", outer = TRUE) } @@ -366,7 +366,7 @@ plotConventionalResiduals <- function(fittedModel){ # # -# if(quantreg == F){ +# if(quantreg == FALSE){ # # lines(smooth.spline(simulationOutput$fittedPredictedResponse, simulationOutput$scaledResiduals, df = 10), lty = 2, lwd = 2, col = "red") # diff --git a/DHARMa/R/random.R b/DHARMa/R/random.R index 014848f7..5c19f7b7 100644 --- a/DHARMa/R/random.R +++ b/DHARMa/R/random.R @@ -22,7 +22,7 @@ getRandomState <- function(seed = NULL){ current = mget(".Random.seed", envir = .GlobalEnv, ifnotfound = list(NULL))[[1]] - if(!is.null(seed) && is.logical(seed) && seed == F){ + if(!is.null(seed) && is.logical(seed) && seed == FALSE){ restoreCurrent <- function(){} }else{ restoreCurrent <- function(){ diff --git a/DHARMa/R/runBenchmarks.R b/DHARMa/R/runBenchmarks.R index d8343179..bbf31b8f 100644 --- a/DHARMa/R/runBenchmarks.R +++ b/DHARMa/R/runBenchmarks.R @@ -15,7 +15,7 @@ #' @author Florian Hartig #' @seealso \code{\link{plot.DHARMaBenchmark}} #' @example inst/examples/runBenchmarksHelp.R -runBenchmarks <- function(calculateStatistics, controlValues = NULL, nRep = 10, alpha = 0.05, parallel = FALSE, exportGlobal = F, ...){ +runBenchmarks <- function(calculateStatistics, controlValues = NULL, nRep = 10, alpha = 0.05, parallel = FALSE, exportGlobal = FALSE, ...){ start_time <- Sys.time() @@ -60,7 +60,7 @@ runBenchmarks <- function(calculateStatistics, controlValues = NULL, nRep = 10, # doesn't see to work properly loadedPackages = (.packages()) parExectuer = function(x = NULL, control = NULL) calculateStatistics(control) - if (exportGlobal == T) parallel::clusterExport(cl = cl, varlist = ls(envir = .GlobalEnv)) + if (exportGlobal == TRUE) parallel::clusterExport(cl = cl, varlist = ls(envir = .GlobalEnv)) parallel::clusterExport(cl = cl, c("parExectuer", "calculateStatistics", "loadedPackages"), envir = environment()) parallel::clusterEvalQ(cl, {for(p in loadedPackages) library(p, character.only=TRUE)}) @@ -141,11 +141,11 @@ runBenchmarks <- function(calculateStatistics, controlValues = NULL, nRep = 10, plot.DHARMaBenchmark <- function(x, ...){ if(length(x$controlValues)== 1){ - boxplot(x$simulations[,1:x$nSummaries], col = "grey", ylim = c(-0.3,1), horizontal = T, las = 2, xaxt='n', main = "p distribution", ...) + boxplot(x$simulations[,1:x$nSummaries], col = "grey", ylim = c(-0.3,1), horizontal = TRUE, las = 2, xaxt='n', main = "p distribution", ...) abline(v = 0) abline(v = c(0.25, 0.5, 0.75), lty = 2) text(-0.2, 1:x$nSummaries, labels = x$summaries$propSignificant[-1]) - # barplot(as.matrix(x$summaries$propSignificant[-1]), horiz = T, add = T, offset = -0.2, names.arg = "test", width = 0.5, space = 1.4) + # barplot(as.matrix(x$summaries$propSignificant[-1]), horiz = TRUE, add = TRUE, offset = -0.2, names.arg = "test", width = 0.5, space = 1.4) }else{ res = x$summaries$propSignificant @@ -157,7 +157,7 @@ plot.DHARMaBenchmark <- function(x, ...){ polygon(c(res$controlValues, rev(res$controlValues)), c(CIs[1,], rev(CIs[2,])), - col = "#00000020", border = F) + col = "#00000020", border = FALSE) lines(res$controlValues, res[,i+1], col = i, lty = i, lwd = 2) } legend("bottomright", colnames(res[,-1]), col = 1:x$nSummaries, lty = 1:x$nSummaries, lwd = 2) @@ -170,7 +170,7 @@ plot.DHARMaBenchmark <- function(x, ...){ plotMultipleHist <- function(x){ lin = ncol(x) - histList <- lapply(x, hist, breaks = seq(0,1,0.02), plot = F) + histList <- lapply(x, hist, breaks = seq(0,1,0.02), plot = FALSE) plot(NULL, xlim = c(0,1), ylim = c(0, lin), yaxt = 'n', ylab = NULL, xlab = "p-value") abline(h= 0) @@ -198,18 +198,18 @@ plotMultipleHist <- function(x){ #' @param main title for the plot #' @param ... additional arguments to hist #' @author Florian Hartig -testPDistribution <- function(x, plot = T, main = "p distribution \n expected is flat at 1", ...){ +testPDistribution <- function(x, plot = TRUE, main = "p distribution \n expected is flat at 1", ...){ out = suppressWarnings(ks.test(x, 'punif')) - hist(x, xlim = c(0,1), breaks = 20, freq = F, main = main, ...) + hist(x, xlim = c(0,1), breaks = 20, freq = FALSE, main = main, ...) abline(h=1, col = "red") return(out) } -# if(plot == T){ +# if(plot == TRUE){ # oldpar <- par(mfrow = c(4,4)) # hist(out, breaks = 50, col = "red", main = paste("mean of", nSim, "simulations")) -# for (i in 1:min(nSim, 15)) hist(out[i,], breaks = 50, freq = F, main = i) +# for (i in 1:min(nSim, 15)) hist(out[i,], breaks = 50, freq = FALSE, main = i) # par(oldpar) # } @@ -250,7 +250,7 @@ generateGenerator <- function(mod){ #' @export benchmarkRuntime<- function(createModel, evaluationFunctions, n){ m = length(evaluationFunctions) - models = replicate(n, createModel(), simplify = F) + models = replicate(n, createModel(), simplify = FALSE) runtimes = rep(NA, m) for (i in 1:m){ diff --git a/DHARMa/R/simulateLRT.R b/DHARMa/R/simulateLRT.R index 144182a1..6612513c 100644 --- a/DHARMa/R/simulateLRT.R +++ b/DHARMa/R/simulateLRT.R @@ -32,7 +32,7 @@ #' #' @example inst/examples/simulateLRTHelp.R #' @export -simulateLRT<-function(m0, m1, n = 250, seed = 123, plot = T, suppressWarnings = T, saveModels = F, ...){ +simulateLRT<-function(m0, m1, n = 250, seed = 123, plot = TRUE, suppressWarnings = TRUE, saveModels = FALSE, ...){ ######## general assertions and startup calculations ########## # identical to simulateResiduals @@ -64,7 +64,7 @@ simulateLRT<-function(m0, m1, n = 250, seed = 123, plot = T, suppressWarnings = out$simulatedLR = rep(NA, n) - if(saveModels == T) out$saveModels == list() + if(saveModels == TRUE) out$saveModels == list() for (i in 1:n){ @@ -76,7 +76,7 @@ simulateLRT<-function(m0, m1, n = 250, seed = 123, plot = T, suppressWarnings = # if (i==3) stop("x") # Note: also set silent = T for production - if(suppressWarnings == T){ + if(suppressWarnings == TRUE){ invisible(capture.output(suppressWarnings(suppressMessages({ refittedM0 = getRefit(m0, simObserved) refittedM1 = getRefit(m1, simObserved) @@ -87,7 +87,7 @@ simulateLRT<-function(m0, m1, n = 250, seed = 123, plot = T, suppressWarnings = refittedM1 = getRefit(m1, simObserved) } - if(saveModels == T) out$saveModels[[i]] = list(refittedM0 = refittedM0, refittedM1 = refittedM1) + if(saveModels == TRUE) out$saveModels[[i]] = list(refittedM0 = refittedM0, refittedM1 = refittedM1) out$simulatedLR[i] = logLik(refittedM1) - logLik(refittedM0) diff --git a/DHARMa/R/simulateResiduals.R b/DHARMa/R/simulateResiduals.R index 6a05e0e5..3ef1af96 100644 --- a/DHARMa/R/simulateResiduals.R +++ b/DHARMa/R/simulateResiduals.R @@ -9,7 +9,7 @@ #' @param plot if TRUE, \code{\link{plotResiduals}} will be directly run after the residuals have been calculated #' @param ... parameters to pass on to the simulate function of the model object. An important use of this is to specify whether simulations should be conditional on the current random effect estimates, e.g. via re.form. Note that not all models support syntax to specify conditional or unconditional simulations. See also details and \code{\link{getSimulations}} #' @param seed the random seed to be used within DHARMa. The default setting, recommended for most users, is keep the random seed on a fixed value 123. This means that you will always get the same randomization and thus the same result when running the same code. NULL = no new seed is set, but previous random state will be restored after simulation. FALSE = no seed is set, and random state will not be restored. The latter two options are only recommended for simulation experiments. See vignette for details. -#' @param method for refit = F, the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. Refit = T will always use "traditional", respectively of the value of method. For details, see \code{\link{getQuantile}} +#' @param method for refit = FALSE, the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. Refit = T will always use "traditional", respectively of the value of method. For details, see \code{\link{getQuantile}} #' @param rotation optional rotation of the residual space prior to calculating the quantile residuals. The main purpose of this is to account for residual covariance as created by temporal or spatial residual autocorrelation. See details below, section *residual auto-correlation* ass well as the help of [getQuantile] and, for a practical example, [testTemporalAutocorrelation]. #' #' @details There are a number of important considerations when simulating from a more complex (hierarchical) model: @@ -41,7 +41,7 @@ #' @example inst/examples/simulateResidualsHelp.R #' @import stats #' @export -simulateResiduals <- function(fittedModel, n = 250, refit = F, integerResponse = NULL, plot = F, seed = 123, method = c("PIT", "traditional"), rotation = NULL, ...){ +simulateResiduals <- function(fittedModel, n = 250, refit = FALSE, integerResponse = NULL, plot = FALSE, seed = 123, method = c("PIT", "traditional"), rotation = NULL, ...){ ######## general assertions and startup calculations ########## @@ -174,14 +174,14 @@ simulateResiduals <- function(fittedModel, n = 250, refit = F, integerResponse = #' @keywords internal checkSimulations <- function(simulatedResponse, nObs, nSim){ - if(!inherits(simulatedResponse, "matrix")) securityAssertion("Simulation from the model produced wrong class", stop = T) + if(!inherits(simulatedResponse, "matrix")) securityAssertion("Simulation from the model produced wrong class", stop = TRUE) - if(any(dim(simulatedResponse) != c(nObs, nSim) )) securityAssertion("Simulation from the model do not have the same dimension as nObs.", stop = F) + if(any(dim(simulatedResponse) != c(nObs, nSim) )) securityAssertion("Simulation from the model do not have the same dimension as nObs.", stop = FALSE) if(any(!is.finite(simulatedResponse))) message("Simulations from your fitted model produce infinite values. Consider if this is sensible") - if(any(is.nan(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NaN values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = T) - if(any(is.na(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NA values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = T) + if(any(is.nan(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NaN values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = TRUE) + if(any(is.na(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NA values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = TRUE) } @@ -233,7 +233,7 @@ recalculateResiduals <- function(simulationOutput, group = NULL, aggregateBy = s out$observedResponse = aggregateByGroup(simulationOutput$observedResponse) out$fittedPredictedResponse = aggregateByGroup(simulationOutput$fittedPredictedResponse) - if (simulationOutput$refit == F){ + if (simulationOutput$refit == FALSE){ out$simulatedResponse = apply(simulationOutput$simulatedResponse, 2, aggregateByGroup) out$scaledResiduals = getQuantile(simulations = out$simulatedResponse , observed = out$observedResponse, integerResponse = simulationOutput$integerResponse, method = method, rotation = rotation) diff --git a/DHARMa/R/tests.R b/DHARMa/R/tests.R index 56704733..29af63b3 100644 --- a/DHARMa/R/tests.R +++ b/DHARMa/R/tests.R @@ -5,12 +5,12 @@ #' This function is a wrapper for the various test functions implemented in DHARMa. Currently, this function calls the \code{\link{testUniformity}} and the \code{\link{testDispersion}} functions. All other tests (see list below) have to be called by hand. #' #' @param simulationOutput an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case. -#' @param plot if T, plots functions of the tests are called +#' @param plot if TRUE, plots functions of the tests are called #' @author Florian Hartig #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @example inst/examples/testsHelp.R #' @export -testResiduals <- function(simulationOutput, plot = T){ +testResiduals <- function(simulationOutput, plot = TRUE){ opar = par(mfrow = c(1,3)) on.exit(par(opar)) @@ -42,13 +42,13 @@ testSimulatedResiduals <- function(simulationOutput){ #' #' @param simulationOutput an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case. #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis. See \code{\link[stats]{ks.test}} for details -#' @param plot if T, plots calls \code{\link{plotQQunif}} as well +#' @param plot if TRUE, plots calls \code{\link{plotQQunif}} as well #' @details The function applies a \code{\link[stats]{ks.test}} for uniformity on the simulated residuals. #' @author Florian Hartig #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @example inst/examples/testsHelp.R #' @export -testUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = T){ +testUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = TRUE){ simulationOutput = ensureDHARMa(simulationOutput, convert = T) @@ -59,7 +59,7 @@ testUniformity<- function(simulationOutput, alternative = c("two.sided", "less", # Experimental -testBivariateUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = T){ +testBivariateUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = TRUE){ simulationOutput = ensureDHARMa(simulationOutput, convert = T) @@ -78,7 +78,7 @@ testBivariateUniformity<- function(simulationOutput, alternative = c("two.sided" #' @param simulationOutput an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case. #' @param predictor an optional predictor variable to be used, instead of the predicted response (default) #' @param quantiles the quantiles to be tested -#' @param plot if T, the function will create an additional plot +#' @param plot if TRUE, the function will create an additional plot #' @details The function fits quantile regressions (via package qgam) on the residuals, and compares their location to the expected location (because of the uniform distributionm, the expected location is 0.5 for the 0.5 quantile). #' #' A significant p-value for the splines means the fitted spline deviates from a flat line at the expected location (p-values of intercept and spline are combined via Benjamini & Hochberg adjustment to control the FDR) @@ -89,7 +89,7 @@ testBivariateUniformity<- function(simulationOutput, alternative = c("two.sided" #' @example inst/examples/testQuantilesHelp.R #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @export -testQuantiles <- function(simulationOutput, predictor = NULL, quantiles = c(0.25,0.5,0.75), plot = T){ +testQuantiles <- function(simulationOutput, predictor = NULL, quantiles = c(0.25,0.5,0.75), plot = TRUE){ if(plot == F){ @@ -152,7 +152,7 @@ testQuantiles <- function(simulationOutput, predictor = NULL, quantiles = c(0.25 #' @param margin whether to test for outliers only at the lower, only at the upper, or both sides (default) of the simulated data distribution #' @param type either default, bootstrap or binomial. See details #' @param nBoot number of boostrap replicates. Only used ot type = "bootstrap" -#' @param plot if T, the function will create an additional plot +#' @param plot if TRUE, the function will create an additional plot #' @details DHARMa residuals are created by simulating from the fitted model, and comparing the simulated values to the observed data. It can occur that all simulated values are higher or smaller than the observed data, in which case they get the residual value of 0 and 1, respectively. I refer to these values as simulation outliers, or simply outliers. #' #' Because no data was simulated in the range of the observed value, we don't know "how strongly" these values deviate from the model expectation, so the term "outlier" should be used with a grain of salt. It is not a judgment about the magnitude of the residual deviation, but simply a dichotomous sign that we are outside the simulated range. Moreover, the number of outliers will decrease as we increase the number of simulations. @@ -169,7 +169,7 @@ testQuantiles <- function(simulationOutput, predictor = NULL, quantiles = c(0.25 #' @author Florian Hartig #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @export -testOutliers <- function(simulationOutput, alternative = c("two.sided", "greater", "less"), margin = c("both", "upper", "lower"), type = c("default","bootstrap", "binomial"), nBoot = 100, plot = T){ +testOutliers <- function(simulationOutput, alternative = c("two.sided", "greater", "less"), margin = c("both", "upper", "lower"), type = c("default","bootstrap", "binomial"), nBoot = 100, plot = TRUE){ # check inputs alternative = match.arg(alternative) @@ -319,7 +319,7 @@ testOutliers <- function(simulationOutput, alternative = c("two.sided", "greater #' @param simulationOutput an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case. #' @param catPred a categorical predictor with the same dimensions as the residuals in simulationOutput #' @param quantiles whether to draw the quantile lines. -#' @param plot if T, the function will create an additional plot +#' @param plot if TRUE, the function will create an additional plot #' @details The function tests for two common problems: are residuals within each group distributed according to model assumptions, and is the variance between group heterogeneous. #' #' The test for within-group uniformity is performed via multipe KS-tests, with adjustment of p-values for multiple testing. If the plot is drawn, problematic groups are highlighted in red, and a corresponding message is displayed in the plot. @@ -330,7 +330,7 @@ testOutliers <- function(simulationOutput, alternative = c("two.sided", "greater #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @example inst/examples/testsHelp.R #' @export -testCategorical <- function(simulationOutput, catPred, quantiles = c(0.25, 0.5, 0.75), plot = T){ +testCategorical <- function(simulationOutput, catPred, quantiles = c(0.25, 0.5, 0.75), plot = TRUE){ simulationOutput = ensureDHARMa(simulationOutput, convert = T) @@ -624,7 +624,7 @@ testGeneric <- function(simulationOutput, summary, alternative = c("two.sided", #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}}, \code{\link{testCategorical}} #' @example inst/examples/testTemporalAutocorrelationHelp.R #' @export -testTemporalAutocorrelation <- function(simulationOutput, time, alternative = c("two.sided", "greater", "less"), plot = T){ +testTemporalAutocorrelation <- function(simulationOutput, time, alternative = c("two.sided", "greater", "less"), plot = TRUE){ simulationOutput = ensureDHARMa(simulationOutput, convert = T) @@ -700,7 +700,7 @@ testTemporalAutocorrelation <- function(simulationOutput, time, alternative = c( #' @import grDevices #' @example inst/examples/testSpatialAutocorrelationHelp.R #' @export -testSpatialAutocorrelation <- function(simulationOutput, x = NULL, y = NULL, distMat = NULL, alternative = c("two.sided", "greater", "less"), plot = T){ +testSpatialAutocorrelation <- function(simulationOutput, x = NULL, y = NULL, distMat = NULL, alternative = c("two.sided", "greater", "less"), plot = TRUE){ alternative <- match.arg(alternative) data.name = deparse(substitute(simulationOutput)) # needs to be before ensureDHARMa @@ -805,7 +805,7 @@ testPhylogeneticAutocorrelation <- function(simulationOutput, -getP <- function(simulated, observed, alternative, plot = F, ...){ +getP <- function(simulated, observed, alternative, plot = FALSE, ...){ if(alternative == "greater") p = mean(simulated >= observed) if(alternative == "less") p = mean(simulated <= observed) diff --git a/DHARMa/inst/examples/checkModelHelp.R b/DHARMa/inst/examples/checkModelHelp.R index 2e720212..1dae3ac0 100644 --- a/DHARMa/inst/examples/checkModelHelp.R +++ b/DHARMa/inst/examples/checkModelHelp.R @@ -1,5 +1,5 @@ -testData = createData(sampleSize = 200, overdispersion = 0.5, randomEffectVariance = 0.5, family = gaussian(), hasNA = T) +testData = createData(sampleSize = 200, overdispersion = 0.5, randomEffectVariance = 0.5, family = gaussian(), hasNA = TRUE) fittedModel <- lm(observedResponse ~ Environment1 , data = testData) res <- simulateResiduals(fittedModel) # throws NA message diff --git a/DHARMa/inst/examples/plotsHelp.R b/DHARMa/inst/examples/plotsHelp.R index 0eb0043d..07facf80 100644 --- a/DHARMa/inst/examples/plotsHelp.R +++ b/DHARMa/inst/examples/plotsHelp.R @@ -32,7 +32,7 @@ plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = T plotResiduals(simulationOutput, form = testData$Environment1, quantreg = FALSE) -# if pred is a factor, or if asFactor = T, will produce a boxplot +# if pred is a factor, or if asFactor = TRUE, will produce a boxplot plotResiduals(simulationOutput, form = testData$group) # to diagnose overdispersion and heteroskedasticity it can be useful to diff --git a/DHARMa/inst/examples/runBenchmarksHelp.R b/DHARMa/inst/examples/runBenchmarksHelp.R index dd119f48..0e073bb0 100644 --- a/DHARMa/inst/examples/runBenchmarksHelp.R +++ b/DHARMa/inst/examples/runBenchmarksHelp.R @@ -32,8 +32,8 @@ out = runBenchmarks(returnStatistics, controlValues = c(0,0.5,1), nRep = 10, par plot.DHARMaBenchmark <- function(x, ...){ if(length(x$controlValues)== 1){ - vioplot::vioplot(x$simulations[,x$nSummaries:1], las = 2, horizontal = T, side = "right", - areaEqual = F, + vioplot::vioplot(x$simulations[,x$nSummaries:1], las = 2, horizontal = TRUE, side = "right", + areaEqual = FALSE, main = "p distribution under H0", ylim = c(-0.15,1), ...) abline(v = 1, lty = 2) diff --git a/DHARMa/inst/examples/simulateLRTHelp.R b/DHARMa/inst/examples/simulateLRTHelp.R index 045fbda6..a39fe6da 100644 --- a/DHARMa/inst/examples/simulateLRTHelp.R +++ b/DHARMa/inst/examples/simulateLRTHelp.R @@ -15,7 +15,7 @@ m0 = glm(observedResponse ~ Environment1 , data = dat, family = "poisson") out = simulateLRT(m0, m1, n = 10) # To inspect warnings thrown during the refits: -out = simulateLRT(m0, m1, saveModels = T, suppressWarnings = F, n = 10) +out = simulateLRT(m0, m1, saveModels = TRUE, suppressWarnings = FALSE, n = 10) summary(out$saveModels[[2]]$refittedM1) # RE SD = 0, no problem # If there are warnings that seem problematic, # could try changing the optimizer or iterations diff --git a/DHARMa/inst/examples/testDispersionHelp.R b/DHARMa/inst/examples/testDispersionHelp.R index 1232ea1b..0efd8e75 100644 --- a/DHARMa/inst/examples/testDispersionHelp.R +++ b/DHARMa/inst/examples/testDispersionHelp.R @@ -22,7 +22,7 @@ testDispersion(simulationOutput) # of RE groups. In doubt, only test for overdispersion testDispersion(simulationOutput, type = "PearsonChisq", alternative = "greater") -# if refit = T, a different test on simulated Pearson residuals will calculated (see help) +# if refit = TRUE, a different test on simulated Pearson residuals will calculated (see help) simulationOutput2 <- simulateResiduals(fittedModel = fittedModel, refit = TRUE, seed = 12, n = 20) testDispersion(simulationOutput2) diff --git a/DHARMa/man/createDHARMa.Rd b/DHARMa/man/createDHARMa.Rd index 0386599c..4a5cb998 100644 --- a/DHARMa/man/createDHARMa.Rd +++ b/DHARMa/man/createDHARMa.Rd @@ -5,7 +5,7 @@ \title{Create a DHARMa object from hand-coded simulations or Bayesian posterior predictive simulations} \usage{ createDHARMa(simulatedResponse, observedResponse, - fittedPredictedResponse = NULL, integerResponse = F, seed = 123, + fittedPredictedResponse = NULL, integerResponse = FALSE, seed = 123, method = c("PIT", "traditional"), rotation = NULL) } \arguments{ diff --git a/DHARMa/man/createData.Rd b/DHARMa/man/createData.Rd index 7c96e5b0..b963b165 100644 --- a/DHARMa/man/createData.Rd +++ b/DHARMa/man/createData.Rd @@ -9,7 +9,7 @@ createData(sampleSize = 100, intercept = 0, fixedEffects = 1, overdispersion = 0, family = poisson(), scale = 1, cor = 0, roundPoissonVariance = NULL, pZeroInflation = 0, binomialTrials = 1, temporalAutocorrelation = 0, spatialAutocorrelation = 0, - factorResponse = F, replicates = 1, hasNA = F) + factorResponse = FALSE, replicates = 1, hasNA = FALSE) } \arguments{ \item{sampleSize}{sample size of the dataset} diff --git a/DHARMa/man/ensureDHARMa.Rd b/DHARMa/man/ensureDHARMa.Rd index 9e134610..c3c9b105 100644 --- a/DHARMa/man/ensureDHARMa.Rd +++ b/DHARMa/man/ensureDHARMa.Rd @@ -4,7 +4,7 @@ \alias{ensureDHARMa} \title{Ensures that an object is of class DHARMa} \usage{ -ensureDHARMa(simulationOutput, convert = F) +ensureDHARMa(simulationOutput, convert = FALSE) } \arguments{ \item{simulationOutput}{a DHARMa simulation output or an object that can be converted into a DHARMa simulation output} diff --git a/DHARMa/man/hist.DHARMa.Rd b/DHARMa/man/hist.DHARMa.Rd index e20a6734..baf83604 100644 --- a/DHARMa/man/hist.DHARMa.Rd +++ b/DHARMa/man/hist.DHARMa.Rd @@ -62,7 +62,7 @@ plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = T plotResiduals(simulationOutput, form = testData$Environment1, quantreg = FALSE) -# if pred is a factor, or if asFactor = T, will produce a boxplot +# if pred is a factor, or if asFactor = TRUE, will produce a boxplot plotResiduals(simulationOutput, form = testData$group) # to diagnose overdispersion and heteroskedasticity it can be useful to diff --git a/DHARMa/man/plot.DHARMa.Rd b/DHARMa/man/plot.DHARMa.Rd index 065ae9d9..89adb215 100644 --- a/DHARMa/man/plot.DHARMa.Rd +++ b/DHARMa/man/plot.DHARMa.Rd @@ -9,7 +9,7 @@ \arguments{ \item{x}{an object of class DHARMa with simulated residuals created by \code{\link{simulateResiduals}}} -\item{title}{The title for both panels (plotted via mtext, outer = T)} +\item{title}{The title for both panels (plotted via mtext, outer = TRUE)} \item{...}{further options for \code{\link{plotResiduals}}. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plot.DHARMa, but can be changed when using plotResiduals.} } @@ -64,7 +64,7 @@ plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = T plotResiduals(simulationOutput, form = testData$Environment1, quantreg = FALSE) -# if pred is a factor, or if asFactor = T, will produce a boxplot +# if pred is a factor, or if asFactor = TRUE, will produce a boxplot plotResiduals(simulationOutput, form = testData$group) # to diagnose overdispersion and heteroskedasticity it can be useful to diff --git a/DHARMa/man/plotQQunif.Rd b/DHARMa/man/plotQQunif.Rd index 4f1205af..81483648 100644 --- a/DHARMa/man/plotQQunif.Rd +++ b/DHARMa/man/plotQQunif.Rd @@ -4,8 +4,8 @@ \alias{plotQQunif} \title{Quantile-quantile plot for a uniform distribution} \usage{ -plotQQunif(simulationOutput, testUniformity = T, testOutliers = T, - testDispersion = T, ...) +plotQQunif(simulationOutput, testUniformity = TRUE, testOutliers = TRUE, + testDispersion = TRUE, ...) } \arguments{ \item{simulationOutput}{a DHARMa simulation output (class DHARMa)} @@ -59,7 +59,7 @@ plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = T plotResiduals(simulationOutput, form = testData$Environment1, quantreg = FALSE) -# if pred is a factor, or if asFactor = T, will produce a boxplot +# if pred is a factor, or if asFactor = TRUE, will produce a boxplot plotResiduals(simulationOutput, form = testData$group) # to diagnose overdispersion and heteroskedasticity it can be useful to diff --git a/DHARMa/man/plotResiduals.Rd b/DHARMa/man/plotResiduals.Rd index b2ffa7f3..45e9cf7a 100644 --- a/DHARMa/man/plotResiduals.Rd +++ b/DHARMa/man/plotResiduals.Rd @@ -4,9 +4,9 @@ \alias{plotResiduals} \title{Generic res ~ pred scatter plot with spline or quantile regression on top} \usage{ -plotResiduals(simulationOutput, form = NULL, quantreg = NULL, rank = T, - asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), - absoluteDeviation = FALSE, ...) +plotResiduals(simulationOutput, form = NULL, quantreg = NULL, + rank = TRUE, asFactor = NULL, smoothScatter = NULL, + quantiles = c(0.25, 0.5, 0.75), absoluteDeviation = FALSE, ...) } \arguments{ \item{simulationOutput}{on object, usually a DHARMa object, from which residual values can be extracted. Alternatively, a vector with residuals or a fitted model can be provided, which will then be transformed into a DHARMa object.} @@ -84,7 +84,7 @@ plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = T plotResiduals(simulationOutput, form = testData$Environment1, quantreg = FALSE) -# if pred is a factor, or if asFactor = T, will produce a boxplot +# if pred is a factor, or if asFactor = TRUE, will produce a boxplot plotResiduals(simulationOutput, form = testData$group) # to diagnose overdispersion and heteroskedasticity it can be useful to diff --git a/DHARMa/man/runBenchmarks.Rd b/DHARMa/man/runBenchmarks.Rd index 1ac1aa00..9775a204 100644 --- a/DHARMa/man/runBenchmarks.Rd +++ b/DHARMa/man/runBenchmarks.Rd @@ -5,7 +5,7 @@ \title{Benchmark calculations} \usage{ runBenchmarks(calculateStatistics, controlValues = NULL, nRep = 10, - alpha = 0.05, parallel = FALSE, exportGlobal = F, ...) + alpha = 0.05, parallel = FALSE, exportGlobal = FALSE, ...) } \arguments{ \item{calculateStatistics}{the statistics to be benchmarked. Should return one value, or a vector of values. If controlValues are given, must accept a parameter control} @@ -66,8 +66,8 @@ out = runBenchmarks(returnStatistics, controlValues = c(0,0.5,1), nRep = 10, par plot.DHARMaBenchmark <- function(x, ...){ if(length(x$controlValues)== 1){ - vioplot::vioplot(x$simulations[,x$nSummaries:1], las = 2, horizontal = T, side = "right", - areaEqual = F, + vioplot::vioplot(x$simulations[,x$nSummaries:1], las = 2, horizontal = TRUE, side = "right", + areaEqual = FALSE, main = "p distribution under H0", ylim = c(-0.15,1), ...) abline(v = 1, lty = 2) diff --git a/DHARMa/man/simulateLRT.Rd b/DHARMa/man/simulateLRT.Rd index f72321a8..b989505d 100644 --- a/DHARMa/man/simulateLRT.Rd +++ b/DHARMa/man/simulateLRT.Rd @@ -4,8 +4,8 @@ \alias{simulateLRT} \title{Simulated likelihood ratio tests for (generalized) linear mixed models} \usage{ -simulateLRT(m0, m1, n = 250, seed = 123, plot = T, - suppressWarnings = T, saveModels = F, ...) +simulateLRT(m0, m1, n = 250, seed = 123, plot = TRUE, + suppressWarnings = TRUE, saveModels = FALSE, ...) } \arguments{ \item{m0}{Null Model} @@ -65,7 +65,7 @@ m0 = glm(observedResponse ~ Environment1 , data = dat, family = "poisson") out = simulateLRT(m0, m1, n = 10) # To inspect warnings thrown during the refits: -out = simulateLRT(m0, m1, saveModels = T, suppressWarnings = F, n = 10) +out = simulateLRT(m0, m1, saveModels = TRUE, suppressWarnings = FALSE, n = 10) summary(out$saveModels[[2]]$refittedM1) # RE SD = 0, no problem # If there are warnings that seem problematic, # could try changing the optimizer or iterations diff --git a/DHARMa/man/simulateResiduals.Rd b/DHARMa/man/simulateResiduals.Rd index 105202c5..b08a261d 100644 --- a/DHARMa/man/simulateResiduals.Rd +++ b/DHARMa/man/simulateResiduals.Rd @@ -4,8 +4,8 @@ \alias{simulateResiduals} \title{Create simulated residuals} \usage{ -simulateResiduals(fittedModel, n = 250, refit = F, - integerResponse = NULL, plot = F, seed = 123, method = c("PIT", +simulateResiduals(fittedModel, n = 250, refit = FALSE, + integerResponse = NULL, plot = FALSE, seed = 123, method = c("PIT", "traditional"), rotation = NULL, ...) } \arguments{ @@ -21,7 +21,7 @@ simulateResiduals(fittedModel, n = 250, refit = F, \item{seed}{the random seed to be used within DHARMa. The default setting, recommended for most users, is keep the random seed on a fixed value 123. This means that you will always get the same randomization and thus the same result when running the same code. NULL = no new seed is set, but previous random state will be restored after simulation. FALSE = no seed is set, and random state will not be restored. The latter two options are only recommended for simulation experiments. See vignette for details.} -\item{method}{for refit = F, the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. Refit = T will always use "traditional", respectively of the value of method. For details, see \code{\link{getQuantile}}} +\item{method}{for refit = FALSE, the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. Refit = T will always use "traditional", respectively of the value of method. For details, see \code{\link{getQuantile}}} \item{rotation}{optional rotation of the residual space prior to calculating the quantile residuals. The main purpose of this is to account for residual covariance as created by temporal or spatial residual autocorrelation. See details below, section \emph{residual auto-correlation} ass well as the help of \link{getQuantile} and, for a practical example, \link{testTemporalAutocorrelation}.} diff --git a/DHARMa/man/testCategorical.Rd b/DHARMa/man/testCategorical.Rd index 4ed2d09c..5e0f8e45 100644 --- a/DHARMa/man/testCategorical.Rd +++ b/DHARMa/man/testCategorical.Rd @@ -5,7 +5,7 @@ \title{Test for categorical dependencies} \usage{ testCategorical(simulationOutput, catPred, quantiles = c(0.25, 0.5, 0.75), - plot = T) + plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} @@ -14,7 +14,7 @@ testCategorical(simulationOutput, catPred, quantiles = c(0.25, 0.5, 0.75), \item{quantiles}{whether to draw the quantile lines.} -\item{plot}{if T, the function will create an additional plot} +\item{plot}{if TRUE, the function will create an additional plot} } \description{ This function tests if there are probles in a res ~ group structure. It performs two tests: test for within-group uniformity, and test for between-group homogeneity of variances diff --git a/DHARMa/man/testDispersion.Rd b/DHARMa/man/testDispersion.Rd index cd136b5c..eed68114 100644 --- a/DHARMa/man/testDispersion.Rd +++ b/DHARMa/man/testDispersion.Rd @@ -70,7 +70,7 @@ testDispersion(simulationOutput) # of RE groups. In doubt, only test for overdispersion testDispersion(simulationOutput, type = "PearsonChisq", alternative = "greater") -# if refit = T, a different test on simulated Pearson residuals will calculated (see help) +# if refit = TRUE, a different test on simulated Pearson residuals will calculated (see help) simulationOutput2 <- simulateResiduals(fittedModel = fittedModel, refit = TRUE, seed = 12, n = 20) testDispersion(simulationOutput2) diff --git a/DHARMa/man/testOutliers.Rd b/DHARMa/man/testOutliers.Rd index 3a897585..0ae01825 100644 --- a/DHARMa/man/testOutliers.Rd +++ b/DHARMa/man/testOutliers.Rd @@ -6,7 +6,7 @@ \usage{ testOutliers(simulationOutput, alternative = c("two.sided", "greater", "less"), margin = c("both", "upper", "lower"), type = c("default", - "bootstrap", "binomial"), nBoot = 100, plot = T) + "bootstrap", "binomial"), nBoot = 100, plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} @@ -19,7 +19,7 @@ testOutliers(simulationOutput, alternative = c("two.sided", "greater", \item{nBoot}{number of boostrap replicates. Only used ot type = "bootstrap"} -\item{plot}{if T, the function will create an additional plot} +\item{plot}{if TRUE, the function will create an additional plot} } \description{ This function tests if the number of observations outside the simulatio envelope are larger or smaller than expected diff --git a/DHARMa/man/testPDistribution.Rd b/DHARMa/man/testPDistribution.Rd index 74b5fb74..9725a9ea 100644 --- a/DHARMa/man/testPDistribution.Rd +++ b/DHARMa/man/testPDistribution.Rd @@ -4,7 +4,7 @@ \alias{testPDistribution} \title{Plot distribution of p-values} \usage{ -testPDistribution(x, plot = T, +testPDistribution(x, plot = TRUE, main = "p distribution \\n expected is flat at 1", ...) } \arguments{ diff --git a/DHARMa/man/testQuantiles.Rd b/DHARMa/man/testQuantiles.Rd index 980f35b7..881ebbd1 100644 --- a/DHARMa/man/testQuantiles.Rd +++ b/DHARMa/man/testQuantiles.Rd @@ -5,7 +5,7 @@ \title{Test for quantiles} \usage{ testQuantiles(simulationOutput, predictor = NULL, quantiles = c(0.25, 0.5, - 0.75), plot = T) + 0.75), plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} @@ -14,7 +14,7 @@ testQuantiles(simulationOutput, predictor = NULL, quantiles = c(0.25, 0.5, \item{quantiles}{the quantiles to be tested} -\item{plot}{if T, the function will create an additional plot} +\item{plot}{if TRUE, the function will create an additional plot} } \description{ This function tests diff --git a/DHARMa/man/testResiduals.Rd b/DHARMa/man/testResiduals.Rd index 2b288aac..df7e31f1 100644 --- a/DHARMa/man/testResiduals.Rd +++ b/DHARMa/man/testResiduals.Rd @@ -4,12 +4,12 @@ \alias{testResiduals} \title{DHARMa general residual test} \usage{ -testResiduals(simulationOutput, plot = T) +testResiduals(simulationOutput, plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} -\item{plot}{if T, plots functions of the tests are called} +\item{plot}{if TRUE, plots functions of the tests are called} } \description{ Calls both uniformity and dispersion test diff --git a/DHARMa/man/testSpatialAutocorrelation.Rd b/DHARMa/man/testSpatialAutocorrelation.Rd index 2730f7c6..d33067b2 100644 --- a/DHARMa/man/testSpatialAutocorrelation.Rd +++ b/DHARMa/man/testSpatialAutocorrelation.Rd @@ -6,7 +6,7 @@ \usage{ testSpatialAutocorrelation(simulationOutput, x = NULL, y = NULL, distMat = NULL, alternative = c("two.sided", "greater", "less"), - plot = T) + plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} diff --git a/DHARMa/man/testTemporalAutocorrelation.Rd b/DHARMa/man/testTemporalAutocorrelation.Rd index e70c9d3c..4c4869bd 100644 --- a/DHARMa/man/testTemporalAutocorrelation.Rd +++ b/DHARMa/man/testTemporalAutocorrelation.Rd @@ -5,7 +5,7 @@ \title{Test for temporal autocorrelation} \usage{ testTemporalAutocorrelation(simulationOutput, time, - alternative = c("two.sided", "greater", "less"), plot = T) + alternative = c("two.sided", "greater", "less"), plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} diff --git a/DHARMa/man/testUniformity.Rd b/DHARMa/man/testUniformity.Rd index 36fe4754..9936e6bb 100644 --- a/DHARMa/man/testUniformity.Rd +++ b/DHARMa/man/testUniformity.Rd @@ -5,14 +5,14 @@ \title{Test for overall uniformity} \usage{ testUniformity(simulationOutput, alternative = c("two.sided", "less", - "greater"), plot = T) + "greater"), plot = TRUE) } \arguments{ \item{simulationOutput}{an object of class DHARMa, either created via \code{\link{simulateResiduals}} for supported models or by \code{\link{createDHARMa}} for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case.} \item{alternative}{a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis. See \code{\link[stats]{ks.test}} for details} -\item{plot}{if T, plots calls \code{\link{plotQQunif}} as well} +\item{plot}{if TRUE, plots calls \code{\link{plotQQunif}} as well} } \description{ This function tests the overall uniformity of the simulated residuals in a DHARMa object