[R] very simple repeated measures, newbie questions
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sun Mar 26 17:07:50 CEST 2000
On Sun, 26 Mar 2000, Jonathan Baron wrote:
> Suppose I do a psychology experiment in which each of six
> subjects does several items in each of five fixed conditions, A,
> B, C, D, and E. The items are randomized separately for each
> subject, so I can ignore order. All I want to know is whether
> the five conditions differ. The data look like this. Each row
> is a subject, and each number is the score in the given
> condition.
>
> A B C D E
> 4 1 5 10 10
> 9 2 10 7 7
> 6 3 7 8 8
> 7 4 9 8 9
> 6 3 7 8 9
> 3 2 5 7 7
>
> Question 1: This is the simplest possible repeated measures
> design. It should yield F(4,24)=16.033 for the effect of
> condition. (The example is from the Systat manual, slightly
> changed.) How do I show this with R?
There are some choices, but the simplest would be
> score <- scan()
1: 4 1 5 10 10
6: 9 2 10 7 7
11: 6 3 7 8 8
16: 7 4 9 8 9
21: 6 3 7 8 9
26: 3 2 5 7 7
31:
Read 30 items
> condition <- rep(LETTERS[1:5], len=30)
> subject <- rep(1:6, rep(5,6))
> df <- data.frame(subject=factor(subject), condition, score)
> summary(aov(score ~ subject + condition, data=df))
Df Sum Sq Mean Sq F value Pr(>F)
subject 5 20.567 4.113 1.9618 0.1287
condition 4 134.467 33.617 16.0334 4.969e-06
Residuals 20 41.933 2.097
Technically, I think you might want a random-effects analysis,
> summary(aov(score ~ condition + Error(subject), data=df))
but with such a simple design they are the same analysis.
> Question 2: I would like a graph in which each line is a
> subject, and the abscissa is labeled A B C D E. Thus, one line
> would connect the points 4 1 5 10 10. Another would connect 9 2
> 10 7 7, and so on. (Systat calls this a parallel plot, and I
> have come to find it very useful for a first look at data.) Can
> this be done in R?
Yes. (I guess you'd like to know how?) Here is one way:
plot(c(1,5), range(score), type="n", xaxt="n", xlab="condition",
ylab="score")
axis(1, at=1:5, labels=LETTERS[1:5])
for(i in 1:6) lines(1:5, score[subject==i], type="o")
Perhaps a simpler one is
matplot(matrix(score, 5), type="l", xaxt="n")
axis(1, at=1:5, labels=LETTERS[1:5])
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list