Skip to contents

These functions facilitate the creation of standard experimental designs commonly used in agricultural studies for power analysis. Instead of supplying a data frame to mkdesign, users can specify key design characteristics to generate the design. Other design parameters are consistent with those in mkdesign.

Usage

designCRD(
  treatments,
  label,
  replicates,
  formula,
  beta = NULL,
  means = NULL,
  sigma2,
  template = FALSE,
  REML = TRUE
)

designRCBD(
  treatments,
  label,
  blocks,
  formula,
  beta = NULL,
  means = NULL,
  vcomp,
  sigma2,
  template = FALSE,
  REML = TRUE
)

designLSD(
  treatments,
  label,
  squares = 1,
  reuse = c("row", "col", "both"),
  formula,
  beta = NULL,
  means = NULL,
  vcomp,
  sigma2,
  template = FALSE,
  REML = TRUE
)

designCOD(
  treatments,
  label,
  squares = 1,
  formula,
  beta = NULL,
  means = NULL,
  vcomp,
  sigma2,
  template = FALSE,
  REML = TRUE
)

designSPD(
  trt.main,
  trt.sub,
  label,
  replicates,
  formula,
  beta = NULL,
  means = NULL,
  vcomp,
  sigma2,
  template = FALSE,
  REML = TRUE
)

Arguments

treatments

An integer-valued vector specifying the treatment structure, in which the length of the vector indicates the number of treatment factors, and each value represents the number of levels for each factor. A maximum of two factors is allowed, and they are arranged in a factorial design. For instance, treatments = n specifies one treatment factor with n levels, and treatments=c(2,3) creates a "2x3" factorial design of two treatment factors with 2 and 3 levels, respectively.

label

A optional list of strings specifying the names of treatment factors and factor levels. Each vector in the list represents a treatment factor, where the name of the vector specifies the name of the factor, and the values in the vector are the labels for that factor's levels. If not provided, factors and levels for one and two treatment factors are labeled as list(trt = c("1", "2", ...)) and list(facA = c("1", "2", ...), facB = c("1", "2", ...)), respectively.

replicates

The number of experimental units per treatment in a completely randomized design or the number of experimental units (main plots) per treatment of main plot factors.

formula

A right-hand-side formula specifying the model for testing treatment effects, with terms on the right of ~ , following lme4::lmer() syntax for random effects. If not specified, a default formula with main effects and all interactions is used internally.

beta

One of the optional inputs for fixed effects. A vector of model coefficients where factor variable coefficients correspond to dummy variables created using "contr.treatment".

means

One of the optional inputs for fixed effects. A vector of marginal or conditioned means (if factors have interactions). Regression coefficients are required for numerical variables. Either beta or means must be provided, and their values must strictly follow a specific order. A template can be created to indicate the required input values and their order. See mkdesign for more information.

sigma2

error variance.

template

Default is FALSE. If TRUE, a template for beta, means, and vcomp is generated to indicate the required input order.

REML

Specifies whether to use REML or ML estimates for variance-covariance parameters. Default is TRUE.

blocks

The number of blocks.

vcomp

A vector of variance-covariance components for random effects, if present. The values must follow a strict order. See mkdesign.

squares

The number of replicated squares. By default, 1, i.e., no replicated squares.

reuse

A character string specifying how to replicate squares when there are multiple squares. Options are: "row" for reusing row blocks, "col" for reusing column blocks, or "both" for reusing both row and column blocks to replicate a single square.

trt.main

An integer-valued vector specifying the treatment structure at main plot level for a split plot design, similar to treatments.

trt.sub

An integer-valued vector specifying the treatment structure at sub plot level for a split plot design, similar to treatments.

Value

a list with critical components for power analysis

Details

Each function creates a specific design as described below:

designCRD

Completely Randomized Design. By default, the model formula is ~ trt for one factor and ~ facA*facB for two factors, unless explicitly specified. If the label argument is provided, the formula is automatically updated with the specified treatment factor names.

designRCBD

Randomized Complete Block Design. The default model formula is ~ trt + (1|block) for one factor and ~ facA*facB + (1|block) for two factors. If label is provided, the fixed effect parts of the formula are automatically updated with the specified names. The label of block factor ("block") in the formula is not changeable.

designLSD

Latin Square Design. The default formula is ~ trt + (1|row) + (1|col) for one factor and ~ facA*facB + (1|row) + (1|col) for two factors. If label is provided, the fixed effect parts of the formula are automatically updated with the specified names. The labels of row ("row") and column ("col") block factors are not changeable.

designCOD

Crossover Design, which is a special case of LSD with time periods and individuals as blocks. Period blocks are reused when replicating squares. The default formula is ~ trt + (1|subject) + (1|period) for one factor and ~ facA*facB + (1|subject) + (1|period) for two factors. If label is provided, the fixed effect parts of the formula are automatically updated with the specified names. Note that "subject" and "period" are the labels for the two blocking factors and cannot be changed.

designSPD

Split Plot Design. The default formula includes the main effects of all treatment factors at both the main and sub-plot levels, their interactions, and the random effects of main plots: ~ . + (1|mainplot). If label is provided, the fixed effect parts of the formula are automatically updated with the specified names. The experimental unit at the main plot level (i.e., the block factor at the subplot level) is always denoted as "mainplot".

designCustom

Customized Design.

Examples

# Example 1: Evaluate the power of a CRD with one treatment factor

## Create a design object

crd <- designCRD(
  treatments = 4, # 4 levels of one treatment factor
  replicates = 12, # 12 units per level, 48 units totally
  means = c(30, 28, 33, 35), # means of the 4 levels
  sigma2 = 10 # error variance
)

## power of omnibus test
pwr.anova(crd)
#> Power of type III F-test
#>     NumDF DenDF sig.level power
#> trt     3    44      0.05 0.999

## power of contrast
pwr.contrast(crd, which = "trt", contrast = "pairwise") # pairwise comparisons
#>             effect df sig.level     power alternative
#> trt1 - trt2      2 44      0.05 0.3285822   two.sided
#> trt1 - trt3     -3 44      0.05 0.6228308   two.sided
#> trt1 - trt4     -5 44      0.05 0.9661638   two.sided
#> trt2 - trt3     -5 44      0.05 0.9661638   two.sided
#> trt2 - trt4     -7 44      0.05 0.9995822   two.sided
#> trt3 - trt4     -2 44      0.05 0.3285822   two.sided
pwr.contrast(crd, which = "trt", contrast = "poly") # polynomial contrasts
#>           effect df sig.level     power alternative
#> linear        20 44      0.05 0.9976700   two.sided
#> quadratic      4 44      0.05 0.5726028   two.sided
#> cubic        -10 44      0.05 0.6685119   two.sided

# More examples are available in the package vignette("pwr4exp")
# and on the package website: https://an-ethz.github.io/pwr4exp/