P. 1


|Views: 102|Likes:

More info:

Published by: Vijay kumar Gupta .C on Oct 25, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less






As a more complete, if a little pedestrian, example of a function, consider fnding the ef-
ciency factors for a block design. (Some aspects of this problem have already been discussed in
Section 5.3 [Index matrices], page 19.)

A block design is defned by two factors, say blocks (b levels) and varieties (v levels). If R
and K are the v by v and b by b replications and block size matrices, respectively, and N is the
b by v incidence matrix, then the efciency factors are defned as the eigenvalues of the matrix

E = Iv−R−1/2

N K−1


= Iv−A A,

where A = K−1/2


. One way to write the function is given below.

> bdeff <- function(blocks, varieties) {
blocks <- as.factor(blocks)

# minor safety move

b <- length(levels(blocks))
varieties <- as.factor(varieties)

# minor safety move

v <- length(levels(varieties))
K <- as.vector(table(blocks))

# remove dim attr

R <- as.vector(table(varieties))

# remove dim attr

N <- table(blocks, varieties)
A <- 1/sqrt(K) * N * rep(1/sqrt(R), rep(b, v))
sv <- svd(A)
list(eff=1 - sv$d^2, blockcv=sv$u, varietycv=sv$v)

Chapter 10: Writing your own functions



It is numerically slightly better to work with the singular value decomposition on this occasion
rather than the eigenvalue routines.

The result of the function is a list giving not only the efciency factors as the frst component,
but also the block and variety canonical contrasts, since sometimes these give additional useful
qualitative information.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->