Package {DoExp}


Type: Package
Title: Design of Experiments with Hasse Diagrams and Anatomy Tables
Version: 0.1.0
Depends: R (≥ 4.1.0)
Description: Constructs Hasse diagrams and anatomy tables from structural formulas and experimental data sets. Hasse diagrams may display sources of variation and their degrees of freedom for general experimental structures. For orthogonal designs, the package can also compute core matrices associated with quadratic forms for sums of squares and contributions to the expected mean squares. Anatomy tables display the degrees of freedom and A-efficiencies associated with the sources of variation.
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: dplyr, ggplot2, knitr, psych, purrr, rlang, stringr, tibble, utils
Suggests: dae, patchwork, rmarkdown
NeedsCompilation: no
Packaged: 2026-10-14 22:32:07 UTC; Leo Peressim
Author: Leonardo Peressim ORCID iD [aut, cre], Renata Sermarini ORCID iD [aut]
Maintainer: Leonardo Peressim <leonardoperessim@usp.br>
Repository: CRAN
Date/Publication: 2026-10-24 09:30:08 UTC

DoExp: Design of Experiments with Hasse Diagrams and Anatomy Tables

Description

Constructs Hasse diagrams and anatomy tables from structural formulas and experimental data sets. Hasse diagrams may display sources of variation and their degrees of freedom for general experimental structures. For orthogonal designs, the package can also compute core matrices associated with quadratic forms for sums of squares and contributions to the expected mean squares. Anatomy tables display the degrees of freedom and A-efficiencies associated with the sources of variation.

Author(s)

Maintainer: Leonardo Peressim leonardoperessim@usp.br (ORCID)

Authors:


Hassediagramdf

Description

Returns the Hasse diagram with: source of variation, degrees of freedom, matrices of the quadratic forms for sums of squares and the contributions to the expectations of mean squares,from structural formulas.

Usage

Hassediagramdf(
  sform = NULL,
  data = NULL,
  rightcolor = "red",
  titlehd = "Hasse diagram",
  subtitlehd = "Levels & Degrees of freedom"
)

Arguments

sform

a structural formula as a character.

data

data.frame containing the variables named in structural the formulas.

rightcolor

the color of everything to the right of the dot in the Hasse diagram. Default is "red".

titlehd

The graph title. Can be NULL. Default: "Hasse diagram".

subtitlehd

The graph subtitle. Can be NULL. Default: "Levels & Degrees of freedom".

Value

an object of class ggplot with Hasse diagrams for deegrees of freedom.

Examples

if (requireNamespace("dae", quietly = TRUE)) {
  blocks <- dae::fac.gen(list(
    Blocks = 4,
    A = 2,
    C = 3
  ))

  blocks$Plots <- rep(1:6, times = 4)

  unitsdf <- Hassediagramdf(
    sform = "Blocks/Plots",
    data = blocks,
    rightcolor = "red",
    titlehd = "Hasse diagram",
    subtitlehd = "Levels & Degrees of freedom"
  )

  trtdf <- Hassediagramdf(
    sform = "A*C",
    data = blocks,
    rightcolor = "blue",
    titlehd = "Hasse diagram",
    subtitlehd = "Levels & Degrees of freedom"
  )

  unitsdf
  trtdf
}

atable

Description

Returns the Anatomy Table with degrees of freedom and the a-effiency for each source of variation for the ANOVA model, from the structural formulas of units and tratments and a data.frame.

Usage

atable(units = NULL, trt = NULL, data = NULL)

Arguments

units

a structural formula of units as a character.

trt

a structural formula of treatments as a character.

data

data.frame containing the variables named in the structural formulas.

Value

an object of class knitr_kable containing an formatted representation of the input table.

Examples

if (requireNamespace("dae", quietly = TRUE)) {
  blocks <- dae::fac.gen(list(
    Blocks = 4,
    A = 2,
    C = 3
  ))

  blocks$Plots <- rep(1:6, times = 4)

  anatomytableCBD <- atable(
    units = "Blocks/Plots",
    trt = "A*C",
    data = blocks
  )

  BIBD <- data.frame(
    Blocks = factor(gl(10, 3)),
    Plots = factor(rep(1:3, times = 10)),
    Treat = factor(c(
      1, 2, 3, 1, 2, 4, 1, 2, 5, 1,
      3, 4, 1, 3, 5, 1, 4, 5, 2, 3,
      4, 2, 3, 5, 2, 4, 5, 3, 4, 5
    ))
  )

  anatomytableBIBD <- atable(
    units = "Blocks/Plots",
    trt = "Treat",
    data = BIBD
  )
}

objectHasse

Description

Returns the Hasse diagram with: source of variation, degrees of freedom, matrices of the quadratic forms for sums of squares and the contributions to the expectations of mean squares,from structural formulas.

Usage

objectHasse(
  sform = NULL,
  data = NULL,
  type = NULL,
  random = NULL,
  advancedrandom = NULL
)

Arguments

sform

a structural formula as a character.

data

data.frame containing the variables named in structural the formulas.

type

indicates whether the factors are unit factors or treatment factors. For unit factors: "unit", "units", "unrandomized", or "recipient". For treatment factors: "treatment", "trt", "randomized", or "allocated".

random

a vector containing the variables related to the random factors. All factors for which the stated factors are marginal will be assumed to be random.

advancedrandom

a vector containing the variables related to the random. factors. Here the factor for which the stated factors are marginal will not be assumed to be random.

Value

An object of class object_hasse containing a structured list with the information required to construct Hasse diagrams using plotHasse()

Examples

if (requireNamespace("dae", quietly = TRUE)) {
  blocks <- dae::fac.gen(list(
    Blocks = 4,
    A = 2,
    C = 3
  ))

  blocks$Plots <- rep(1:6, times = 4)

  units <- objectHasse(
    sform = "Blocks/Plots",
    data = blocks,
    type = "units",
    random = NULL,
    advancedrandom = NULL
  )

  treatments <- objectHasse(
    sform = "A*C",
    data = blocks,
    type = "trt",
    random = c("A"),
    advancedrandom = NULL
  )
}

plotHasse

Description

Returns the Hasse diagram with: source of variation, degrees of freedom, matrices of the quadratic forms for sums of squares and the contributions to the expectations of mean squares,from structural formulas.

Usage

plotHasse(
  diagram = NULL,
  which = NULL,
  titlehd = "Hasse diagram",
  subtitlehd = "",
  leftcolor = "blue",
  rightcolor = "red"
)

Arguments

diagram

an object from objectHasse with informations for ploting.

which

a character to select which graph will be generated. Choose between: "sv", "df", "M", and "EMS".

titlehd

The graph title. Can be NULL. Default: "Hasse diagram".

subtitlehd

The graph subtitle. Can be NULL. Default: NULL.

leftcolor

the color of everything to the left of the dot in the Hasse diagram. Default is "blue".

rightcolor

the color of everything to the right of the dot in the Hasse diagram. Default is "red".

Value

An object of class ggplot containing Hasse diagrams based on sources of variation, degrees of freedom, core matrices of quadratic forms, or expected mean squares.

Examples

if (requireNamespace("dae", quietly = TRUE)) {
  blocks <- dae::fac.gen(list(
    Blocks = 4,
    A = 2,
    C = 3
  ))

  blocks$Plots <- rep(1:6, times = 4)

  units <- objectHasse(
    sform = "Blocks/Plots",
    data = blocks,
    type = "units",
    random = NULL,
    advancedrandom = NULL
  )

  treatments <- objectHasse(
    sform = "A*C",
    data = blocks,
    type = "trt",
    random = c("A"),
    advancedrandom = NULL
  )

  svunits <- plotHasse(diagram = units, which = "sv")
  svtrt   <- plotHasse(diagram = treatments, which = "sv")

svunits
svtrt
}