Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Package: hassediagram
Package: hassediagrams
Type: Package
Title: Hasse diagram of the layout structure and restricted layout structure
Title: Hasse Diagram of the Layout Structure and Restricted Layout Structure
Version: 1.0
Date: 2025-04-01
Date: 2025-05-19
Authors@R:
c(person(given = "Damianos", family = "Michaelides", role = c("aut", "cre"), email = "dm3g15@soton.ac.uk"),
person(given = "Simon", family = "Bate", role = c("aut"), email = "simon.t.bate@gsk.com"),
person(given = "Marion", family = "Chatfield", role = "aut"))
Maintainer: Damianos Michaelides <dm3g15@soton.ac.uk> and Simon Bate <simon.t.bate@gsk.com>
Description: Returns a Hasse diagram of the 'layout structure' <doi.org/10.1080/00224065.2016.11918173> or the 'restricted layout structure' <doi.org/10.1080/00224065.2016.11918174> of an experimental design.
Maintainer: Damianos Michaelides <dm3g15@soton.ac.uk>
Description: Returns a Hasse diagram of the 'layout structure' <doi:10.1080/00224065.2016.11918173> or the 'restricted layout structure' <doi:10.1080/00224065.2016.11918174> of an experimental design.
License: GPL-2
Encoding: UTF-8
URL: https://github.com/GSK-Biostatistics/hassediagram
BugReports: https://github.com/GSK-Biostatistics/hassediagram/issues
URL: https://github.com/GSK-Biostatistics/hassediagrams
BugReports: https://github.com/GSK-Biostatistics/hassediagrams/issues
Imports: igraph, methods, MASS, grDevices, graphics, stats
Depends: R (>= 3.5.0)
Suggests:
Expand Down
6 changes: 3 additions & 3 deletions R/hassediagram.R → R/hassediagrams.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' of an experimental design.
#'
#' @details
#' The package consists of three main functions: \code{\link[hassediagram]{hasselayout}},
#' \code{\link[hassediagram]{itemlist}}, and \code{\link[hassediagram]{hasserls}}.
#' The package consists of three main functions: \code{\link[hassediagrams]{hasselayout}},
#' \code{\link[hassediagrams]{itemlist}}, and \code{\link[hassediagrams]{hasserls}}.
#' The first function generates the Hasse diagram of the layout structure of an experimental design.
#' The latter two functions are used together to generate the Hasse diagram of the restricted layout
#' structure of an experimental design.
Expand Down Expand Up @@ -39,6 +39,6 @@
#' Williams, E.R., Matheson, A.C. and Harwood, C.E. (2002), Experimental design and analysis
#' for tree improvement. 2nd edition. CSIRO, Melbourne, Australia.
#'
#' @name hassediagram
#' @name hassediagrams
#' @keywords internal
"_PACKAGE"
10 changes: 6 additions & 4 deletions R/hasselayout.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @param pdf logical. If "Y" then a pdf file containing the Hasse diagram of the layout structure is generated. The default is "N", i.e., a pdf file is not generated.
#' @param example File name for the pdf output file containing the Hasse diagram. The default is set to "example".
#' @param outdir Location of the pdf output file if \code{pdf="Y"}. The default is set to \code{NULL} and in this case the pdf output file containing the Hasse diagram will be stored in the working directory of the user's R session.
#' @param hasse.font The name of the font family used for all text included in the Hasse diagram. Standard and safe font families to choose are "sans", "serif", and "mono". If the design's factor labels contain Unicode characters, or for consistency with Hasse diagrams of restricted layout structures using \link[hassediagram]{hasserls}, a Unicode friendly font family should be selected. For more details on Unicode friendly family options see the Details section in the \link[hassediagram]{hasserls} documentation. The default is "sans".
#' @param hasse.font The name of the font family used for all text included in the Hasse diagram. Standard and safe font families to choose are "sans", "serif", and "mono". If the design's factor labels contain Unicode characters, or for consistency with Hasse diagrams of restricted layout structures using \link[hassediagrams]{hasserls}, a Unicode friendly font family should be selected. For more details on Unicode friendly family options see the Details section in the \link[hassediagrams]{hasserls} documentation. The default is "sans".
#' @param produceBWPlot logical. If "Y" then the Hasse diagram will be generated in black and white format. The default is set to "N", i.e., a coloured version of the plot is produced.
#' @param structural.colour The colour of the structural lines that connect structural objects on the Hasse diagram. The default colour is "grey".
#' @param structural.width The width of the structural lines on the Hasse diagram. The default width is 2.
Expand All @@ -40,9 +40,9 @@
#'
#' Using the randomfacsid argument the factors that correspond to random effects can be highlighted by underlining them on the Hasse diagram. The vector should be equal to the number of variables/factors in the design and consist of fixed (entry = 0) or random (entry = 1) values.
#'
#' The \code{\link[hassediagram]{hasselayout}} function evaluates the design in order to identify if there are any confounded degrees of freedom across the design. It is not recommended to perform this evaluation for large designs due to the potential high computational cost. This can be controlled using the check.confound.df = "N" option.
#' The \code{\link[hassediagrams]{hasselayout}} function evaluates the design in order to identify if there are any confounded degrees of freedom across the design. It is not recommended to perform this evaluation for large designs due to the potential high computational cost. This can be controlled using the check.confound.df = "N" option.
#'
#' @return The function \code{\link[hassediagram]{hasselayout}} returns:
#' @return The function \code{\link[hassediagrams]{hasselayout}} returns:
#'
#' 1. The Hasse diagram of the layout structure (if \code{showLS="Y"}).
#'
Expand Down Expand Up @@ -81,7 +81,7 @@
#' @importFrom graphics par
#'
#' @examples
#'
#' \dontrun{
#' ## Examples using the package build-in data concrete, dental, human, analytical.
#'
#' ## A fractional factorial design for investigating asphalt concrete production
Expand Down Expand Up @@ -143,6 +143,8 @@
#' message("Examples using data from the 'dae' package
#' require 'dae' to be installed.")
#' }
#' }
#'
#'
hasselayout <- function(datadesign,
randomfacsid = NULL,
Expand Down
10 changes: 5 additions & 5 deletions R/hasserls.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#' @title Hasse diagram of the restricted layout structure
#' @description Returns a Hasse diagram of the restricted layout structure of an experimental design
#'
#' @param object An object of class \code{"rls"}. The function \code{\link[hassediagram]{itemlist}} generates the class \code{"rls"} object.
#' @param object An object of class \code{"rls"}. The function \code{\link[hassediagrams]{itemlist}} generates the class \code{"rls"} object.
#' Printing the "\code{"rls"} object will give a list of structural objects (that define the layout structure) to aid in
#' defining the randomisation objects in the restricted layout structure.
#' @param randomisation.objects This argument takes the format of the \code{TransferObject} item from the class \code{"rls"} object.
#' The first column contains the names of all the structural objects in the layout structure (automatically generated) and the
#' second column contains the corresponding randomisation objects in the restricted layout structure (manually generated).
#' To begin with, the function \code{\link[hassediagram]{itemlist}} should be run to generate the class \code{"rls"} object.
#' To begin with, the function \code{\link[hassediagrams]{itemlist}} should be run to generate the class \code{"rls"} object.
#' The user will then need to edit the second column of the \code{TransferObject} matrix to define the randomisation objects
#' that appear in the restricted layout structure. Structural objects that do not occur in the restricted layout structure must be
#' left as "NULL" in the second column. The names specified in the second column represent the labels of the randomisation objects
Expand Down Expand Up @@ -66,7 +66,7 @@
#' @param smaller.fontlabelmultiplier numeric. The small font multiplier is the multiplier for the font used for the labels of objects on the
#' Hasse diagram where there are five or more objects at that level of the diagram. The default is 1.
#'
#' @return The function \code{\link[hassediagram]{hasserls}} returns:
#' @return The function \code{\link[hassediagrams]{hasserls}} returns:
#' 1. The Hasse diagram of the restricted layout structure (if \code{showRLS = "Y"}).
#'
#' 2. The restricted layout structure table shows the relationships between the randomisation objects in the restricted layout structure
Expand All @@ -83,7 +83,7 @@
#' 4. If there are confounded degrees of freedom, a table of the structural objects and a description of the associated degrees of freedom is printed.
#'
#' @details
#' The \code{\link[hassediagram]{hasserls}} function generates the Hasse diagram of the restricted layout structure.
#' The \code{\link[hassediagrams]{hasserls}} function generates the Hasse diagram of the restricted layout structure.
#' The Hasse diagram consists of a set of randomisation objects, corresponding to the factors and generalised factors,
#' and the relationships between the objects (either crossed, nested, partially crossed or equivalent),
#' as defined by the structure of the experimental design and the randomisation performed, see Bate and Chatfield (2016b).
Expand All @@ -98,7 +98,7 @@
#'
#' The randomisation arrows that illustrate the randomisation performed can be included on the Hasse diagram.
#'
#' The \code{\link[hassediagram]{hasserls}} function evaluates the design in order to identify if there are any
#' The \code{\link[hassediagrams]{hasserls}} function evaluates the design in order to identify if there are any
#' confounded degrees of freedom across the design. It is not recommended to perform this evaluation for large designs,
#' due to the potential high computational cost. This can be controlled using the \code{check.confound.df = "N"} option.
#'
Expand Down
9 changes: 4 additions & 5 deletions R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,7 @@ strip.order.biglm.fun <- function (x) {


#' @noRd
sort.effectorder.fun <- function(x) {
#zzz^change
sort_effectorder_fun <- function(x) {
splitmatrixformat <- suppressWarnings(do.call(rbind, strsplit(x, "\\^")))
sorted.effects <- apply(t(apply(as.matrix(splitmatrixformat),1,sort)),1,unique)
sortedx <- rep("",length(x))
Expand Down Expand Up @@ -764,7 +763,7 @@ dfs.fun <- function(DStype, noall, feffects, ceffects.table.fb, adjm, outputlist
nonnested.rownames.tier.dfs[j] <- gsub("\\(","^",nonnested.rownames.tier.dfs[j])
nonnested.rownames.tier.dfs[j] <- gsub("\\)","",nonnested.rownames.tier.dfs[j])
}
tier.dfs[rownames(tier.dfs)[which(sort.effectorder.fun(nonnested.rownames.tier.dfs)%in% names(dropi))],i-1] <- dropi
tier.dfs[rownames(tier.dfs)[which(sort_effectorder_fun(nonnested.rownames.tier.dfs)%in% names(dropi))],i-1] <- dropi
}

#Puts column confoundedf = 0 if no confounded dfs, 1 if confounded dfs
Expand All @@ -787,7 +786,7 @@ dfs.fun <- function(DStype, noall, feffects, ceffects.table.fb, adjm, outputlist
coliname <- paste("term",i,sep="")
tier.dfs <- cbind(tier.dfs,rep(0,nrow(tier.dfs)))
colnames(tier.dfs)[ncol(tier.dfs)]<-coliname
posterms <- sort.effectorder.fun(nonnested.rownames.tier.dfs[1:i])
posterms <- sort_effectorder_fun(nonnested.rownames.tier.dfs[1:i])
modeli <- c("mean",posterms[c(xadjm[i+1,2:length(feffects[feffects<feffects[i+1]])]==1,T)])
model.testi <- model.effects.fun(modeli)

Expand All @@ -811,7 +810,7 @@ dfs.fun <- function(DStype, noall, feffects, ceffects.table.fb, adjm, outputlist
anovai.dfs[names(anovai.dfs) %in% names(anovai.df)] <- anovai.df
anovai.dfs

tier.dfs[rownames(tier.dfs)[which(sort.effectorder.fun(nonnested.rownames.tier.dfs)%in% names(anovai.dfs))],ncol(tier.dfs)] <- anovai.dfs
tier.dfs[rownames(tier.dfs)[which(sort_effectorder_fun(nonnested.rownames.tier.dfs)%in% names(anovai.dfs))],ncol(tier.dfs)] <- anovai.dfs
tier.dfs[i,length(tiers)+3] <- tier.dfs[i,ncol(tier.dfs)]
}
}
Expand Down
4 changes: 3 additions & 1 deletion R/itemlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @param datadesign A data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables/factors
#' in the experimental design. The dataframe should only include the variables/factors/columns that the user wants to evaluate in the
#' consecutive \code{\link[hassediagram]{hasserls}} function to generate the Hasse diagram of the restricted layout structure.
#' consecutive \code{\link[hassediagrams]{hasserls}} function to generate the Hasse diagram of the restricted layout structure.
#' @param randomfacsid An optional vector specifying whether the factors are defined as fixed (entry = 0) or random (entry = 1).
#' The default choice is \code{NULL} and the function automatically sets all entries to 0. The length of the vector should be equal to the number of variables/factors in the design, i.e., the length of the vector should be equal to the number of columns of the argument \code{datadesign}.
#'
Expand Down Expand Up @@ -52,6 +52,7 @@
#' Williams, E.R., Matheson, A.C. and Harwood, C.E. (2002), Experimental design and analysis for tree improvement. 2nd edition. CSIRO, Melbourne, Australia.
#'
#' @examples
#' \dontrun{
#' # Examples using built-in data: concrete, dental, human, analytical
#'
#' # Fractional factorial design for asphalt concrete production
Expand Down Expand Up @@ -79,6 +80,7 @@
#' BIBDWheat_objects <- itemlist(datadesign=BIBDWheat)
#' print(BIBDWheat_objects)
#' }
#' }
#'
#' @export
#'
Expand Down
4 changes: 2 additions & 2 deletions R/print_summary_rls.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#'
#' @return The functions return the structural objects of the Layout Structure
#' and a matrix that the users need to edit with the randomisation
#' objects to pass in the \code{\link[hassediagram]{hasserls}} function.
#' objects to pass in the \code{\link[hassediagrams]{hasserls}} function.
#'
#' @note For examples see \code{\link[hassediagram]{itemlist}} and \code{\link[hassediagram]{hasserls}}.
#' @note For examples see \code{\link[hassediagrams]{itemlist}} and \code{\link[hassediagrams]{hasserls}}.
#'
#' @author Damianos Michaelides, Simon Bate, and Marion Chatfield
#'
Expand Down
22 changes: 13 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: "hassediagram: generates the layout structure and restricted layout structure of experimental designs"
title: "hassediagrams: generates the layout structure and restricted layout structure of experimental designs"
author: "Damianos Michaelides, Simon Bate, Marion Chatfield"
output: github_document
---


## Overview

The `hassediagram` package provides tools to visualize the **structure of experimental designs** using Hasse diagrams. The package determines the structure of the design, summarised by the layout structure, and uses this structure to generate a Hasse diagram. This diagram describes the structure of the design and the relationships between the factors that define the design. By considering the randomisation performed, in conjunction with the layout structure, a list of randomisation objects can be identified, known as the restricted layout structure. The package can also be used to generate a Hasse Diagram of this restricted layout structure. Objects in the restricted layout structure can be used to identify the terms to include in the statistical model.
The `hassediagrams` package provides tools to visualize the **structure of experimental designs** using Hasse diagrams. The package determines the structure of the design, summarised by the layout structure, and uses this structure to generate a Hasse diagram. This diagram describes the structure of the design and the relationships between the factors that define the design. By considering the randomisation performed, in conjunction with the layout structure, a list of randomisation objects can be identified, known as the restricted layout structure. The package can also be used to generate a Hasse Diagram of this restricted layout structure. Objects in the restricted layout structure can be used to identify the terms to include in the statistical model.

The package is an implementation of the methodology described in Bate and Chatfield (2016a and 2016b).

Expand Down Expand Up @@ -38,26 +38,26 @@ Creates the Hasse diagram of the restricted layout structure. Inputs to the func

### Install from GitHub (Development Version)

The development version of `hassediagram` can be installed with:
The development version of `hassediagrams` can be installed with:

```r
# Install devtools (if not already installed)
install.packages("devtools")

# Install hassediagram from GitHub
devtools::install_github("GSK-Biostatistics/hassediagram")
# Install hassediagrams from GitHub
devtools::install_github("GSK-Biostatistics/hassediagrams")
```

### Install from CRAN (when made available)
```r
install.packages("hassediagram")
install.packages("hassediagrams")
```

## Usage

Load the package:
```r
library(hassediagram)
library(hassediagrams)
```

## Example: Generate Hasse Diagrams of the Layout Structure and Restricted Layout Structure
Expand Down Expand Up @@ -104,7 +104,7 @@ hasserls(object=concrete_objects, randomisation.objects=concrete_rls,
For an introduction to the methodology, check the package vignette:

```r
vignette("Introduction_to_hassediagram")
vignette("Introduction_to_hassediagrams")
```

and for an introduction to the package implementation visit the documentation.
Expand All @@ -114,4 +114,8 @@ and for an introduction to the package implementation visit the documentation.

This package is in a stable state and will only be updated for bug fixes.

The person responsible for monitoring this package is Simon Bate <simon.t.bate@gsk.co
The person responsible for monitoring this package is Simon Bate <simon.t.bate@gsk.com>.




16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
hassediagram: generates the layout structure and restricted layout
hassediagrams: generates the layout structure and restricted layout
structure of experimental designs
================
Damianos Michaelides, Simon Bate, Marion Chatfield

## Overview

The `hassediagram` package provides tools to visualize the **structure
The `hassediagrams` package provides tools to visualize the **structure
of experimental designs** using Hasse diagrams. The package determines
the structure of the design, summarised by the layout structure, and
uses this structure to generate a Hasse diagram. This diagram describes
Expand Down Expand Up @@ -53,28 +53,28 @@ that defines the randomisation arrows.

### Install from GitHub (Development Version)

The development version of `hassediagram` can be installed with:
The development version of `hassediagrams` can be installed with:

``` r
# Install devtools (if not already installed)
install.packages("devtools")

# Install hassediagram from GitHub
devtools::install_github("GSK-Biostatistics/hassediagram")
# Install hassediagrams from GitHub
devtools::install_github("GSK-Biostatistics/hassediagrams")
```

### Install from CRAN (when made available)

``` r
install.packages("hassediagram")
install.packages("hassediagrams")
```

## Usage

Load the package:

``` r
library(hassediagram)
library(hassediagrams)
```

## Example: Generate Hasse Diagrams of the Layout Structure and Restricted Layout Structure
Expand Down Expand Up @@ -115,7 +115,7 @@ hasserls(object=concrete_objects, randomisation.objects=concrete_rls,
For an introduction to the methodology, check the package vignette:

``` r
vignette("Introduction_to_hassediagram")
vignette("Introduction_to_hassediagrams")
```

and for an introduction to the package implementation visit the
Expand Down
File renamed without changes.
Loading