1% File src/library/stats/man/replications.Rd 2% Part of the R package, https://www.R-project.org 3% Copyright 1995-2014 R Core Team 4% Distributed under GPL 2 or later 5 6\name{replications} 7\title{Number of Replications of Terms} 8\usage{ 9replications(formula, data = NULL, na.action) 10} 11\alias{replications} 12\arguments{ 13 \item{formula}{a formula or a terms object or a data frame.} 14 \item{data}{a data frame used to find the objects in \code{formula}.} 15 \item{na.action}{function for handling missing values. Defaults to 16 a \code{na.action} attribute of \code{data}, then 17 a setting of the option \code{na.action}, or \code{na.fail} if that 18 is not set.} 19} 20\description{ 21 Returns a vector or a list of the number of replicates for 22 each term in the formula. 23} 24\details{ 25 If \code{formula} is a data frame and \code{data} is missing, 26 \code{formula} is used for \code{data} with the formula \code{~ .}. 27 28 Any character vectors in the formula are coerced to factors. 29} 30\value{ 31 A vector or list with one entry for each term in the formula giving 32 the number(s) of replications for each level. If all levels are 33 balanced (have the same number of replications) the result is a 34 vector, otherwise it is a list with a component for each terms, 35 as a vector, matrix or array as required. 36 37 A test for balance is \code{!is.list(replications(formula,data))}. 38} 39\references{ 40 Chambers, J. M., Freeny, A and Heiberger, R. M. (1992) 41 \emph{Analysis of variance; designed experiments.} 42 Chapter 5 of \emph{Statistical Models in S} 43 eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. 44} 45\author{ 46 The design was inspired by the S function of the same name described 47 in Chambers \emph{et al} (1992). 48} 49 50\seealso{\code{\link{model.tables}}} 51 52\examples{ 53## From Venables and Ripley (2002) p.165. 54N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0) 55P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0) 56K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0) 57yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5, 5855.0, 62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0) 59 60npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P), 61 K = factor(K), yield = yield) 62replications(~ . - yield, npk) 63} 64\keyword{models} 65