[R-sig-ME] Analysis with standard deviations

Gang Chen gangchen6 at gmail.com
Sat Feb 7 00:21:24 CET 2009


Let me use the Machines data that comes with nlme package as an
example to describe the situation I'm facing:

> library(nlme)
> str(Machines)
Classes 'nffGroupedData', 'nfGroupedData', 'groupedData' and
'data.frame':      54 obs. of  3 variables:
 $ Worker : Ord.factor w/ 6 levels "6"<"2"<"4"<"1"<..: 4 4 4 2 2 2 5 5 5 3 ...
 $ Machine: Factor w/ 3 levels "A","B","C": 1 1 1 1 1 1 1 1 1 1 ...
 $ score  : num  52 52.8 53.1 51.8 52.8 53.1 60 60.2 58.4 51.1 ...

Suppose I want to model the data with the following

Y_ijk = a_j + b_i + b_ij + e_ijk, i (worker) = 1,...,6, j (machine) =
1,...,3, k (sample repetitions) = 1,...,3

> lme(score~Machine, data=Machines, random=~1|Worker/Machine)

And suppose I don't have the whole data set Machines. Instead what I
have are Y_ij. (dot here means the score average across the k index:
those repeated samples for each (i,j)), and its standard deviation. So
my real data is myMachines as below:

> tmp1 <- tapply(Machines$score, Machines[c("Worker", "Machine")], mean)   # mean
> tmp2 <- tapply(Machines$score, Machines[c("Worker", "Machine")], sd)        # standard deviation
> myMachines <- data.frame(expand.grid(dimnames(tmp1)), matrix(c(unlist(tmp1), unlist(tmp2)), byrow=FALSE,ncol=2))
> names(myMachines) <- c("Worker", "Machine", "myScore", "sd")

My question is, how can I analyze myMachines with lme or lmer? In
other words, is there a way to take the standard deviations into
consideration when modeling?

Thanks in advance,
Gang




More information about the R-sig-mixed-models mailing list