**0**wrote:

Hi

I am trying to specify a nested design for analysis with limma and having some difficulty.

For each subject in the study there are two tissue compartments measured. Within each tissue, there are three cell types. Measurements on each cell type within tissue have been replicated three times each.

It looks something like this:

```
factors <- list(rep=1:3,
cell_type=1:3,
tissue=c('C','T'),
subject=c('A','B','C'))
dat <- expand.grid(factors)[, rev(names(factors))]
head(dat, 20)
subject tissue cell_type rep
1 A N 1 1
2 A N 1 2
3 A N 1 3
4 A N 2 1
5 A N 2 2
6 A N 2 3
7 A N 3 1
8 A N 3 2
9 A N 3 3
10 A T 1 1
11 A T 1 2
12 A T 1 3
13 A T 2 1
14 A T 2 2
15 A T 2 3
16 A T 3 1
17 A T 3 2
18 A T 3 3
19 B N 1 1
20 B N 1 2
```

I think the most straightforward way to model this in limma is with the group means parameterization (section 9.7 of manual), grouping cells within tissue type, with subject as a random effect (block).

```
treat <- with(dat, paste(tissue, cell_type))
design <- model.matrix(0~treat)
corfit_main <- duplicateCorrelation(Y, design = design, block = dat$subject)
```

etc...

I think in this case, each replicate within treat gets treated as if it were independent? These are done on separate portions of the same sample (i.e. not the same RNA). Will the duplicateCorrelation for subject reasonably account for this correlation, or would it be more correct to block on the replicate (section 11.3; in which case it seems like a subject effect would be lost). Or subject could be included as a fixed effect, with blocking on replicate?

Any advice would be very much appreciated!