Skip to content

Commit

Permalink
tests, version, docs, news
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Aug 8, 2023
1 parent e91ec00 commit d4f149d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
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.4
Version: 0.8.0.5
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# datawizard (devel)

NEW FUNCTIONS

* `contr.deviation()` for sum-deviation contrast coding of factors.

CHANGES

* `recode_into()` gains an `overwrite` argument to skip overwriting already
Expand Down
7 changes: 3 additions & 4 deletions R/contrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' \dontrun{
#' data("mtcars")
#'
#' mtcars$cyl <- factor(mtcars$cyl)
#' mtcars <- data_modify(mtcars, cyl = factor(cyl))
#'
#' c.treatment <- cbind(Intercept = 1, contrasts(mtcars$cyl))
#' solve(c.treatment)
Expand All @@ -50,10 +50,9 @@
#' #> 8 -1.000 0.000 1.000 # 3rd level - 1st level
#'
#' ## With Interactions -----------------------------------------
#' mtcars$am <- factor(mtcars$am)
#' contrasts(mtcars$am) <- contr.deviation
#' mtcars <- data_modify(mtcars, am = factor(am))
#' mtcars <- data_arrange(mtcars, select = c("cyl", "am"))
#'
#' mtcars <- mtcars[order(mtcars$cyl, mtcars$am),]
#' mm <- unique(model.matrix(~ cyl * am, data = mtcars))
#' rownames(mm) <- c("cyl4.am0", "cyl4.am1", "cyl6.am0",
#' "cyl6.am1", "cyl8.am0", "cyl8.am1")
Expand Down
7 changes: 3 additions & 4 deletions man/contr.deviation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-contr.deviation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("contr.deviation", {
c.treatment <- solve(cbind(Intercept = 1, contr.treatment(3)))
c.sum <- solve(cbind(Intercept = 1, contr.sum(3)))
c.deviation <- solve(cbind(Intercept = 1, contr.deviation(3)))

expect_equal(c.deviation[1,], c.sum[1,])
expect_equal(c.deviation[-1,], c.treatment[-1,])
})

0 comments on commit d4f149d

Please sign in to comment.