-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into strengejacke/issue441
- Loading branch information
Showing
39 changed files
with
1,995 additions
and
734 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,5 @@ references.bib | |
^hextools/. | ||
^WIP/. | ||
^CRAN-SUBMISSION$ | ||
^LICENSE$ | ||
docs | ||
^.dev$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: datawizard | ||
Title: Easy Data Wrangling and Statistical Transformations | ||
Version: 0.8.0.5 | ||
Version: 0.8.0.13 | ||
Authors@R: c( | ||
person("Indrajeet", "Patil", , "[email protected]", role = "aut", | ||
comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")), | ||
|
@@ -27,13 +27,13 @@ Description: A lightweight package to assist in key steps involved in any data | |
(3) compute statistical summaries of data properties and distributions. | ||
It is also the data wrangling backend for packages in 'easystats' ecosystem. | ||
References: Patil et al. (2022) <doi:10.21105/joss.04684>. | ||
License: GPL (>= 3) | ||
License: MIT + file LICENSE | ||
URL: https://easystats.github.io/datawizard/ | ||
BugReports: https://github.com/easystats/datawizard/issues | ||
Depends: | ||
R (>= 3.6) | ||
Imports: | ||
insight (>= 0.19.1), | ||
insight (>= 0.19.3.2), | ||
stats, | ||
utils | ||
Suggests: | ||
|
@@ -43,6 +43,7 @@ Suggests: | |
data.table, | ||
dplyr (>= 1.0), | ||
effectsize, | ||
emmeans, | ||
gamm4, | ||
ggplot2, | ||
gt, | ||
|
@@ -77,3 +78,4 @@ Config/Needs/website: | |
rstudio/bslib, | ||
r-lib/pkgdown, | ||
easystats/easystatstemplate | ||
Remotes: easystats/insight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2023 datawizard authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#' Deviation Contrast Matrix | ||
#' | ||
#' Build a deviation contrast matrix, a type of _effects contrast_ matrix. | ||
#' | ||
#' @inheritParams stats::contr.sum | ||
#' | ||
#' @details | ||
#' In effects coding, unlike treatment/dummy coding | ||
#' ([stats::contr.treatment()]), each contrast sums to 0. In regressions models, | ||
#' this results in an intercept that represents the (unweighted) average of the | ||
#' group means. In ANOVA settings, this also guarantees that lower order effects | ||
#' represent _main_ effects (and not _simple_ or _conditional_ effects, as is | ||
#' the case when using R's default [stats::contr.treatment()]). | ||
#' \cr\cr | ||
#' Deviation coding (`contr.deviation`) is a type of effects coding. With | ||
#' deviation coding, the coefficients for factor variables are interpreted as | ||
#' the difference of each factor level from the base level (this is the same | ||
#' interpretation as with treatment/dummy coding). For example, for a factor | ||
#' `group` with levels "A", "B", and "C", with `contr.devation`, the intercept | ||
#' represents the overall mean (average of the group means for the 3 groups), | ||
#' and the coefficients `groupB` and `groupC` represent the differences between | ||
#' the A group mean and the B and C group means, respectively. | ||
#' \cr\cr | ||
#' Sum coding ([stats::contr.sum()]) is another type of effects coding. With sum | ||
#' coding, the coefficients for factor variables are interpreted as the | ||
#' difference of each factor level from **the grand (across-groups) mean**. For | ||
#' example, for a factor `group` with levels "A", "B", and "C", with | ||
#' `contr.sum`, the intercept represents the overall mean (average of the group | ||
#' means for the 3 groups), and the coefficients `group1` and `group2` represent | ||
#' the differences the | ||
#' **A** and **B** group means from the overall mean, respectively. | ||
#' | ||
#' @seealso [stats::contr.sum()] | ||
#' | ||
#' @examples | ||
#' if (FALSE) { | ||
#' data("mtcars") | ||
#' | ||
#' mtcars <- data_modify(mtcars, cyl = factor(cyl)) | ||
#' | ||
#' c.treatment <- cbind(Intercept = 1, contrasts(mtcars$cyl)) | ||
#' solve(c.treatment) | ||
#' #> 4 6 8 | ||
#' #> Intercept 1 0 0 # mean of the 1st level | ||
#' #> 6 -1 1 0 # 2nd level - 1st level | ||
#' #> 8 -1 0 1 # 3rd level - 1st level | ||
#' | ||
#' contrasts(mtcars$cyl) <- contr.sum | ||
#' c.sum <- cbind(Intercept = 1, contrasts(mtcars$cyl)) | ||
#' solve(c.sum) | ||
#' #> 4 6 8 | ||
#' #> Intercept 0.333 0.333 0.333 # overall mean | ||
#' #> 0.667 -0.333 -0.333 # deviation of 1st from overall mean | ||
#' #> -0.333 0.667 -0.333 # deviation of 2nd from overall mean | ||
#' | ||
#' | ||
#' contrasts(mtcars$cyl) <- contr.deviation | ||
#' c.deviation <- cbind(Intercept = 1, contrasts(mtcars$cyl)) | ||
#' solve(c.deviation) | ||
#' #> 4 6 8 | ||
#' #> Intercept 0.333 0.333 0.333 # overall mean | ||
#' #> 6 -1.000 1.000 0.000 # 2nd level - 1st level | ||
#' #> 8 -1.000 0.000 1.000 # 3rd level - 1st level | ||
#' | ||
#' ## With Interactions ----------------------------------------- | ||
#' mtcars <- data_modify(mtcars, am = C(am, contr = contr.deviation)) | ||
#' mtcars <- data_arrange(mtcars, select = c("cyl", "am")) | ||
#' | ||
#' mm <- unique(model.matrix(~ cyl * am, data = mtcars)) | ||
#' rownames(mm) <- c( | ||
#' "cyl4.am0", "cyl4.am1", "cyl6.am0", | ||
#' "cyl6.am1", "cyl8.am0", "cyl8.am1" | ||
#' ) | ||
#' | ||
#' solve(mm) | ||
#' #> cyl4.am0 cyl4.am1 cyl6.am0 cyl6.am1 cyl8.am0 cyl8.am1 | ||
#' #> (Intercept) 0.167 0.167 0.167 0.167 0.167 0.167 # overall mean | ||
#' #> cyl6 -0.500 -0.500 0.500 0.500 0.000 0.000 # cyl MAIN eff: 2nd - 1st | ||
#' #> cyl8 -0.500 -0.500 0.000 0.000 0.500 0.500 # cyl MAIN eff: 2nd - 1st | ||
#' #> am1 -0.333 0.333 -0.333 0.333 -0.333 0.333 # am MAIN eff | ||
#' #> cyl6:am1 1.000 -1.000 -1.000 1.000 0.000 0.000 | ||
#' #> cyl8:am1 1.000 -1.000 0.000 0.000 -1.000 1.000 | ||
#' } | ||
#' | ||
#' @export | ||
contr.deviation <- function(n, base = 1, | ||
contrasts = TRUE, | ||
sparse = FALSE) { | ||
cont <- stats::contr.treatment(n, | ||
base = base, | ||
contrasts = contrasts, | ||
sparse = sparse | ||
) | ||
if (contrasts) { | ||
n <- nrow(cont) | ||
cont <- cont - 1 / n | ||
} | ||
cont | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.