ascorbic: ascorbic data from Crowder and Hand

Description Usage Format Details Source References Examples

Description

A dataset containing ascorbic acid measures on 12 patients The data come from Table 3.3 in Crowder and Hand.

Usage

1

Format

A data frame with 84 observations on the following 7 variables.

patient

a factor with levels Pat.01 Pat.02Pat.03Pat.04Pat.05 Pat.06Pat.07Pat.08Pat.09 Pat.10Pat.11Pat.12

week

a numeric vector

occ

a factor with levels 1 2 3 4 5 6 7

phase.num

a numeric vector

Phase

a factor with levels post pre Rx

ascorbic.acid

a numeric vector

Occasion

a numeric vector

Details

The data were taken from Table 3.3 in Crowder and Hand (1991). The variable patient is a factor variable, which should be used in fitting the correct model. The variable phase.num is a numeric variable. The variable Phase is a factor variable, which should be used instead of phase.num for fitting the correct model. The variable Occasion is a numeric variable. The variable occ is a factor variable, which should be used instead of Occasion in fitting the correct model.

Source

Crowder MJ and Hand DJ (1990) Analysis of Repeated Measures, Chapman and Hall.

References

Crowder MJ and Hand DJ (1990) Analysis of Repeated Measures, Chapman and Hall.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
##
## ***** Get Simple BoxPlots with Points
##
data(ascorbic)
with(ascorbic, plot(ascorbic.acid ~ occ,
xlab = 'Occasions [occ]',
ylab = 'Ascorbic Acid [ascorbic.acid]',
main = 'Ascorbic Acid responses for 12
patients\nacross 7 Occasions'))
with(ascorbic,
points(ascorbic.acid ~ occ, pch = 16,
col = c('black', 'brown', 'blue', 'purple',
'red', 'green', 'orange', 'yellow', 'pink',
'turquoise', 'gray', 'violet')))
##
## ***** End Simple BoxPlots with Points
##
}
##
## ***** Plot groupedData data frame with nlme
##
## Create and plot ascorbic.gD.df,
## a groupedData data frame
##
library(nlme)
ascorbic.gD.df <-groupedData(ascorbic.acid ~ week | patient,
    data = ascorbic)

## plot ascorbic.gD.df
plot(ascorbic.gD.df, outer = ~ 1, key = FALSE,
ylab = 'Ascorbic Acid', xlab = 'week',
aspect = 0.6, main = 'Reaction of Patients to Rx')
##
## ***** End plot of groupedData data frame
##
##
## ***** Get ggplot
##
## Create ggplot2 plot object
library(ggplot2)
##
occ.p0 <- ggplot(ascorbic, aes(occ, ascorbic.acid))
## set.seed(11) ## for jittered points to stay fixed
occ.p1 <- occ.p0 +
geom_boxplot(stat = 'boxplot', outlier.shape = 3) +
labs(y = 'Ascorbic Acid', x = 'Occasion',
title = 'Ascorbic Acid Responses for 12 Patients
Across Occasions in 3 Phases')
occ.p1 ## basic boxplot
##
set.seed(11) ## for jittered points to stay fixed
occ.p2 <- occ.p1 +
geom_point(position = position_jitter(width = 0.2),
aes(colour = patient))
occ.p2 # add points color-coded by patient
##
set.seed(11) ## for jittered points to stay fixed
occ.p3 <- occ.p2 +
geom_vline(xintercept = c(2.5, 5.5), col = 'blue', lwd = 1.2,
linetype = 'longdash')
occ.p3 # add vertical lines to separate Phases
##
set.seed(11) ## for jittered points to stay fixed
occ.p4 <- occ.p3 +
annotate('text', x = 1.5, y = 1.6, label = 'pre Rx') +
annotate('text', x = 4, y = 0.3, label = 'Rx') +
annotate('text', x = 4, y = 0.2, label = '(treatment)') +
annotate('text', x = 6.5, y = 1.6, label = 'post Rx')
occ.p4 # label Phases
##
set.seed(11) ## for jittered points to stay fixed
occ.p5 <- occ.p4 +
annotate('text', x = 1.5, y = 1.7, label = 'Phase 1') +
annotate('text', x = 4, y = 0.4, label = 'Phase 2') +
annotate('text', x = 6.5, y = 1.7, label = 'Phase 3')
occ.p5 # further label Phases
##
## ***** End ggplot
##
##
## ***** Produce Traditional DotPlot
##
with(ascorbic,
plot(jitter(Occasion), ascorbic.acid,
ylab = 'Ascorbic Acid', ylim = c(0,5),
xlab = 'Occasions (occ)',
main = 'Ascorbic Acid - Occasions and Phases',
col = c('black', 'brown', 'blue', 'purple',
'red', 'green', 'orange', 'yellow', 'pink',
'turquoise', 'gray', 'violet'), pch = 16,
xaxt = 'n'))
##
## Note: jitter() takes a numeric value, not a factor.
## In data the 'ascorbic' data frame
## 'Occasion' is a numeric variable
## and 'occ' is a factor variable.
##
axis(side = 1, at = c(1:7),
labels = c(1:7), tick = TRUE, las = 2, cex.axis = .7)
abline(v = c(2.5, 5.5), lty = 1, col = 'blue', lwd = 1)
##
## Add text above data - ascorbic.acid
##
text(1.0, 4.4, "Phase 1: 'pre'",
  pos = 4, offset = 0, cex = 1.0)
text(3.4, 4.4, "Phase 2: 'Rx'",
  pos = 4, offset = 0, cex = 1.0)
text(5.8, 4.4, "Phase 3: 'post'",
  pos = 4, offset = 0, cex = 1.0)
## Add legend to the dot plot
##
legend.vec <- c('01', '02', '03', '04', '05', '06',
                '07', '08', '09', '10', '11', '12')
## Phase 1
legend(1.2, 3.8, legend = legend.vec[1:4],
col = c('black', 'brown', 'blue', 'purple'),
pch = 16, cex = .8, pt.cex = .8 )
## Phase 2
legend(3.8, 3.8, legend = legend.vec[5:8],
col = c('red', 'green', 'orange', 'yellow'),
pch = 16, cex = .8, pt.cex = .8 )
## Phase 3
legend(6.2, 3.8, legend = legend.vec[9:12],
col = c('pink', 'turquoise', 'gray', 'violet'),
pch = 16, cex = .8, pt.cex = .8)
##
## ***** End Traditional DotPlot
##

wgalvord/owprm documentation built on May 4, 2019, 5:22 a.m.