Skip to content
Snippets Groups Projects
Commit 544594a3 authored by Walmes Marques Zeviani's avatar Walmes Marques Zeviani
Browse files

Add *.R to prepare datasets of chapter 10.

parent e4ffb417
No related branches found
No related tags found
No related merge requests found
##----------------------------------------------------------------------
## Data generation. Pimentel page 190.
## bib1 <- read.table("clipboard", header=TRUE, sep="\t")
## names(bib1) <- c("rept", "treat", "block", "y")
## bib1 <- transform(bib1, rept=factor(rept),
## block=factor(block), treat=factor(treat))
bib1 <-
structure(list(rept = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L), .Label = c("1", "2", "3", "4", "5", "6", "7"), class = "factor"),
treat = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 3L,
2L, 8L, 4L, 5L, 6L, 7L, 1L, 4L, 2L, 7L, 3L, 6L, 5L, 8L, 1L,
5L, 2L, 3L, 4L, 7L, 6L, 8L, 1L, 6L, 2L, 4L, 3L, 8L, 5L, 7L,
1L, 7L, 2L, 6L, 3L, 5L, 4L, 8L, 1L, 8L, 2L, 5L, 3L, 7L, 4L,
6L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8"), class = "factor"),
block = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L,
2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L,
1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L,
1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L,
4L), .Label = c("1", "2", "3", "4"), class = "factor"), y = c(20L,
18L, 15L, 16L, 14L, 15L, 16L, 18L, 24L, 18L, 25L, 19L, 13L,
16L, 12L, 16L, 23L, 17L, 26L, 18L, 15L, 17L, 13L, 16L, 21L,
13L, 23L, 16L, 10L, 12L, 13L, 11L, 28L, 14L, 27L, 18L, 18L,
15L, 16L, 17L, 22L, 17L, 24L, 16L, 18L, 14L, 15L, 17L, 23L,
15L, 21L, 13L, 15L, 12L, 13L, 16L)), .Names = c("rept", "treat",
"block", "y"), row.names = c(NA, -56L), class = "data.frame")
str(bib1)
bib <- bib1[with(bib1, order(rept, block, treat)), ]
save(bib1, file="../data/bib1.RData")
##----------------------------------------------------------------------
## Examples.
require(lattice)
xyplot(y~treat|rept, groups=block, data=bib1, type="b",
ylab="Y", xlab="Treatment")
xyplot(y~treat, data=bib1, jitter.x=TRUE,
ylab="Y", xlab="Treatment")
rm(list=ls())
load("../data/bib1.RData")
ls()
str(bib1)
##----------------------------------------------------------------------
## Data generation. Pimentel page 192.
## bib2 <- read.table("clipboard", header=TRUE, sep="\t")
## bib2$y <- as.numeric(sub(x=bib2$y, ",", "."))
## names(bib2) <- c("rept", "block", "treat", "y")
## bib2 <- transform(bib2, rept=factor(rept),
## block=factor(block), treat=factor(treat))
## dput(bib2)
bib2 <-
structure(list(rept = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), block = structure(c(1L,
1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 1L, 1L, 2L,
2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 1L, 1L, 2L, 2L, 3L,
3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L), .Label = c("1", "2", "3",
"4", "5", "6", "7"), class = "factor"), treat = structure(c(1L,
2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 1L, 1L, 3L, 3L,
5L, 5L, 7L, 7L, 2L, 2L, 4L, 4L, 6L, 6L, 1L, 1L, 4L, 4L, 7L, 7L,
3L, 3L, 6L, 6L, 2L, 2L, 5L, 5L, 1L), .Label = c("1", "2", "3",
"4", "5", "6", "7"), class = "factor"), y = c(3.5, 2.8, 3.2,
3.7, 3.5, 2.5, 2.8, 2.7, 3, 3.2, 2.4, 2.6, 3.1, 2.7, 3.8, 4,
3.6, 2.7, 2.3, 3, 2.8, 2.5, 2.6, 2.8, 2.3, 2.4, 2.8, 3.3, 3,
2.2, 2.7, 3.4, 3.2, 3.9, 3.3, 2.4, 2.8, 3.4, 2.9, 2.6, 2.3, 3.3
)), .Names = c("rept", "block", "treat", "y"), row.names = c(NA,
-42L), class = "data.frame")
str(bib2)
bib <- bib2[with(bib2, order(rept, block, treat)), ]
save(bib2, file="../data/bib2.RData")
##----------------------------------------------------------------------
## Examples.
require(lattice)
xyplot(y~treat|rept, groups=block, data=bib2, type="b",
ylab="Y", xlab="Treatment")
xyplot(y~treat, data=bib2, jitter.x=TRUE,
ylab="Y", xlab="Treatment")
rm(list=ls())
load("../data/bib2.RData")
ls()
str(bib2)
##----------------------------------------------------------------------
## Data generation. Pimentel page 185.
## bib3 <- read.table("clipboard", header=TRUE, sep="\t")
## names(bib3) <- c("block", "treat", "y")
## bib3 <- transform(bib3,
## block=factor(block), treat=factor(treat))
## dput(bib3)
bib3 <-
structure(list(block = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L,
8L, 9L, 9L, 9L, 10L, 10L, 10L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10"), class = "factor"), treat = structure(c(1L,
2L, 3L, 1L, 2L, 4L, 1L, 2L, 5L, 1L, 3L, 4L, 1L, 3L, 5L, 1L, 4L,
5L, 2L, 3L, 4L, 2L, 3L, 5L, 2L, 4L, 5L, 3L, 4L, 5L), .Label = c("1",
"2", "3", "4", "5"), class = "factor"), y = c(35L, 28L, 27L,
30L, 20L, 22L, 28L, 16L, 18L, 36L, 29L, 30L, 29L, 19L, 22L, 25L,
16L, 19L, 26L, 30L, 28L, 27L, 29L, 27L, 29L, 29L, 27L, 27L, 26L,
29L)), .Names = c("block", "treat", "y"), row.names = c(NA, -30L
), class = "data.frame")
bib <- bib3[with(bib3, order(block, treat)), ]
save(bib3, file="../data/bib3.RData")
##----------------------------------------------------------------------
## Examples.
require(lattice)
xyplot(y~treat|block, data=bib3,
ylab="Y",
xlab="Treatment")
g <- nlevels(bib3$treat)
a <- seq(0, by=(2*pi)/(g), length.out=g)
y <- sin(a)
x <- cos(a)
plot(y~x, asp=1, xlim=c(-1,1), ylim=c(-1,1))
for (b in levels(bib3$block)){
cbn <- combn(x=as.integer(bib3$treat[bib3$block==b]),
m=2)
segments(
x0=x[cbn[1,]], y0=y[cbn[1,]],
x1=x[cbn[2,]], y1=y[cbn[2,]], col=b)
}
rm(list=ls())
load("../data/bib3.RData")
ls()
str(bib3)
##----------------------------------------------------------------------
## Data generation. Pimentel page 198.
## bib3asin <- read.table("clipboard", header=TRUE, sep="\t")
## bib3asin[, 3] <- as.numeric(sub(x=bib3asin[, 3], ",", "."))
## names(bib3asin) <- c("block", "treat", "z")
## bib3asin <- transform(bib3asin,
## block=factor(block), treat=factor(treat))
## dput(bib3asin)
bib3asin <-
structure(list(block = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "11", "12", "13"), class = "factor"), treat = structure(c(1L,
2L, 1L, 3L, 4L, 1L, 2L, 1L, 6L, 3L, 5L, 4L, 2L, 2L, 8L, 7L, 4L,
8L, 3L, 3L, 5L, 10L, 7L, 9L, 5L, 6L, 4L, 12L, 11L, 6L, 9L, 9L,
5L, 6L, 11L, 8L, 10L, 7L, 7L, 10L, 13L, 12L, 12L, 11L, 13L, 11L,
8L, 13L, 10L, 12L, 13L, 9L), .Label = c("1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11", "12", "13"), class = "factor"),
z = c(52.7, 71.6, 58.9, 75, 71.6, 56.8, 75, 48.8, 63.4, 71.6,
75, 63.4, 71.6, 79.5, 56.8, 75, 65.9, 75, 65.9, 65.9, 68.6,
90, 63.4, 68.6, 61.1, 63.4, 63.4, 71.6, 75, 79.5, 71.6, 71.6,
65.9, 63.4, 90, 61.1, 75, 50.8, 61.1, 65.9, 65.9, 71.6, 79.5,
79.5, 65.9, 90, 61.1, 71.6, 58.9, 75, 79.5, 75)), .Names = c("block",
"treat", "z"), row.names = c(NA, -52L), class = "data.frame")
bib <- bib3asin[with(bib3asin, order(block, treat)), ]
save(bib3asin, file="../data/bib3asin.RData")
##----------------------------------------------------------------------
## Examples.
require(lattice)
xyplot(z~treat|block, data=bib3asin,
ylab="Arc sin of heathy plants fraction",
xlab="Treatment")
## Why not consider a beta distribution for p?
bib3asin$p <- sin(bib3asin$z*pi/180)^2
xyplot(p~treat|block, data=bib3asin,
ylab="Fraction of healthy plants",
xlab="Treatment")
g <- nlevels(bib3asin$treat)
a <- seq(0, by=(2*pi)/(g), length.out=g)
y <- sin(a)
x <- cos(a)
plot(y~x, asp=1, xlim=c(-1,1), ylim=c(-1,1))
for (b in levels(bib3asin$block)){
cbn <- combn(x=as.integer(bib3asin$treat[bib3asin$block==b]),
m=2)
segments(
x0=x[cbn[1,]], y0=y[cbn[1,]],
x1=x[cbn[2,]], y1=y[cbn[2,]], col=b)
}
rm(list=ls())
load("../data/bib3asin.RData")
ls()
str(bib3asin)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment