diff --git a/DHARMa/DESCRIPTION b/DHARMa/DESCRIPTION index 439ed20..ec9954c 100644 --- a/DHARMa/DESCRIPTION +++ b/DHARMa/DESCRIPTION @@ -2,7 +2,7 @@ Package: DHARMa Title: Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models Version: 0.4.7 Date: 2024-10-16 -Authors@R: c(person("Florian", "Hartig", email = "florian.hartig@biologie.uni-regensburg.de", role = c("aut", "cre"), comment=c(ORCID="0000-0002-6255-9059")), person("Lukas", "Lohse", role = "ctb")) +Authors@R: c(person("Florian", "Hartig", email = "florian.hartig@biologie.uni-regensburg.de", role = c("aut", "cre"), comment=c(ORCID="0000-0002-6255-9059")), person("Lukas", "Lohse", role = "ctb"), person("Melina", "de Souza leite", role = "ctb")) Description: The 'DHARMa' package uses a simulation-based approach to create readily interpretable scaled (quantile) residuals for fitted (generalized) linear mixed models. Currently supported are linear and generalized linear (mixed) models from 'lme4' diff --git a/DHARMa/DHARMa.Rproj b/DHARMa/DHARMa.Rproj index cba1b6b..4b56c89 100644 --- a/DHARMa/DHARMa.Rproj +++ b/DHARMa/DHARMa.Rproj @@ -18,4 +18,4 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace +PackageRoxygenize: rd,collate,namespace,vignette diff --git a/DHARMa/vignettes/DHARMa.Rmd b/DHARMa/vignettes/DHARMa.Rmd index 6755381..c584eca 100644 --- a/DHARMa/vignettes/DHARMa.Rmd +++ b/DHARMa/vignettes/DHARMa.Rmd @@ -3,12 +3,14 @@ title: "DHARMa: residual diagnostics for hierarchical (multi-level/mixed) regres author: "Florian Hartig, Theoretical Ecology, University of Regensburg [website](https://www.uni-regensburg.de/biologie-vorklinische-medizin/theoretische-oekologie/mitarbeiter/hartig/)" date: "`r Sys.Date()`" output: - rmarkdown::html_vignette: - toc: true pdf_document: toc: true -vignette: | - %\VignetteIndexEntry{Vignette for the DHARMa package} \usepackage[utf8]{inputenc} %\VignetteEngine{knitr::rmarkdown} + rmarkdown::html_vignette: + toc: true +vignette: > + %\VignetteIndexEntry{Vignette for the DHARMa package} + \usepackage[utf8]{inputenc} + %\VignetteEngine{knitr::rmarkdown} abstract: "The 'DHARMa' package uses a simulation-based approach to create readily interpretable scaled (quantile) residuals for fitted generalized linear (mixed) models. Currently supported are linear and generalized linear (mixed) models from diff --git a/DHARMa/vignettes/DHARMaForBayesians.R b/DHARMa/vignettes/DHARMaForBayesians.R new file mode 100644 index 0000000..f9b0a4a --- /dev/null +++ b/DHARMa/vignettes/DHARMaForBayesians.R @@ -0,0 +1,78 @@ +## ----global_options, include=FALSE-------------------------------------------- +knitr::opts_chunk$set(fig.width=8.5, fig.height=5.5, fig.align='center', warning=FALSE, message=FALSE) + +## ----echo = F, message = F---------------------------------------------------- +library(DHARMa) +set.seed(123) + +## ----eval = F----------------------------------------------------------------- +# library(rjags) +# library(BayesianTools) +# +# set.seed(123) +# +# dat <- DHARMa::createData(200, overdispersion = 0.2) +# +# Data = as.list(dat) +# Data$nobs = nrow(dat) +# Data$nGroups = length(unique(dat$group)) +# +# modelCode = "model{ +# +# for(i in 1:nobs){ +# observedResponse[i] ~ dpois(lambda[i]) # poisson error distribution +# lambda[i] <- exp(eta[i]) # inverse link function +# eta[i] <- intercept + env*Environment1[i] # linear predictor +# } +# +# intercept ~ dnorm(0,0.0001) +# env ~ dnorm(0,0.0001) +# +# # Posterior predictive simulations +# for (i in 1:nobs) { +# observedResponseSim[i]~dpois(lambda[i]) +# } +# +# }" +# +# jagsModel <- jags.model(file= textConnection(modelCode), data=Data, n.chains = 3) +# para.names <- c("intercept","env", "lambda", "observedResponseSim") +# Samples <- coda.samples(jagsModel, variable.names = para.names, n.iter = 5000) +# +# x = BayesianTools::getSample(Samples) +# +# colnames(x) # problem: all the variables are in one array - this is better in STAN, where this is a list - have to extract the right columns by hand +# posteriorPredDistr = x[,3:202] # this is the uncertainty of the mean prediction (lambda) +# posteriorPredSim = x[,203:402] # these are the simulations +# +# sim = createDHARMa(simulatedResponse = t(posteriorPredSim), observedResponse = dat$observedResponse, fittedPredictedResponse = apply(posteriorPredDistr, 2, median), integerResponse = T) +# plot(sim) + +## ----eval=F------------------------------------------------------------------- +# # Posterior predictive simulations +# for (i in 1:nobs) { +# observedResponseSim[i]~dpois(lambda[i]) +# } + +## ----eval = F----------------------------------------------------------------- +# for(i in 1:nobs){ +# observedResponse[i] ~ dpois(lambda[i]) # poisson error distribution +# lambda[i] <- exp(eta[i]) # inverse link function +# eta[i] <- intercept + env*Environment1[i] + RE[group[i]] # linear predictor +# } +# +# for(j in 1:nGroups){ +# RE[j] ~ dnorm(0,tauRE) +# } + +## ----eval=F------------------------------------------------------------------- +# for(j in 1:nGroups){ +# RESim[j] ~ dnorm(0,tauRE) +# } +# +# for (i in 1:nobs) { +# observedResponseSim[i] ~ dpois(lambdaSim[i]) +# lambdaSim[i] <- exp(etaSim[i]) +# etaSim[i] <- intercept + env*Environment1[i] + RESim[group[i]] +# } +