I have a set of microarray data (one-channel custom Agilent) that I'm
trying to analyze for gene expression differences following an experiment:

Sponges were acutely exposed to combinations of oil and dispersant
treatments. There were 4 treatment groups: OD, OC, UD, UC, 6 sponge
colonies each fragmented 12 times, with three replicates = 72 samples total.

I found some examples from the limma user's guide and other materials, but
I'm still having trouble.
http://www.bioconductor.org/help/course-materials/2009/BioC2009/labs/limma/limma.pdf
https://stat.ethz.ch/pipermail/bioconductor/2012-January/043154.html
http://www.bioconductor.org/packages/2.12/bioc/vignettes/limma/inst/doc/usersguide.pdf

In coding my contrast and design matrices, I'm confused and wondering if
someone can help?

Details and code below.

Thank you in advance!

Lisa




This is the design matrix I set up:

> v<-c(0,1)
> mat<-cbind(c(rep(v[2],18),rep(v[1],54)),
+              c(rep(v[1],18),rep(v[2],18),rep(v[1],36)),
+              c(rep(v[1],36),rep(v[2],18),rep(v[1],18)),
+              c(rep(v[1],54),rep(v[2],18)),
+              c(rep(1:6,12)))
> colnames(mat)<-c("UC","UD","OC","OD","Colony")

> mat
      UC UD OC OD Colony
 [1,]  1  0  0  0      1
 [2,]  1  0  0  0      2
 [3,]  1  0  0  0      3
 [4,]  1  0  0  0      4
 [5,]  1  0  0  0      5
 [6,]  1  0  0  0      6
 [7,]  1  0  0  0      1
 [8,]  1  0  0  0      2
 [9,]  1  0  0  0      3
[10,]  1  0  0  0      4
[11,]  1  0  0  0      5
[12,]  1  0  0  0      6
[13,]  1  0  0  0      1
[14,]  1  0  0  0      2
[15,]  1  0  0  0      3
[16,]  1  0  0  0      4
[17,]  1  0  0  0      5
[18,]  1  0  0  0      6
[19,]  0  1  0  0      1
[20,]  0  1  0  0      2
[21,]  0  1  0  0      3
[22,]  0  1  0  0      4
[23,]  0  1  0  0      5
[24,]  0  1  0  0      6
[25,]  0  1  0  0      1
[26,]  0  1  0  0      2
[27,]  0  1  0  0      3
[28,]  0  1  0  0      4
[29,]  0  1  0  0      5
[30,]  0  1  0  0      6
[31,]  0  1  0  0      1
[32,]  0  1  0  0      2
[33,]  0  1  0  0      3
[34,]  0  1  0  0      4
[35,]  0  1  0  0      5
[36,]  0  1  0  0      6
[37,]  0  0  1  0      1
[38,]  0  0  1  0      2
[39,]  0  0  1  0      3
[40,]  0  0  1  0      4
[41,]  0  0  1  0      5
[42,]  0  0  1  0      6
[43,]  0  0  1  0      1
[44,]  0  0  1  0      2
[45,]  0  0  1  0      3
[46,]  0  0  1  0      4
[47,]  0  0  1  0      5
[48,]  0  0  1  0      6
[49,]  0  0  1  0      1
[50,]  0  0  1  0      2
[51,]  0  0  1  0      3
[52,]  0  0  1  0      4
[53,]  0  0  1  0      5
[54,]  0  0  1  0      6
[55,]  0  0  0  1      1
[56,]  0  0  0  1      2
[57,]  0  0  0  1      3
[58,]  0  0  0  1      4
[59,]  0  0  0  1      5
[60,]  0  0  0  1      6
[61,]  0  0  0  1      1
[62,]  0  0  0  1      2
[63,]  0  0  0  1      3
[64,]  0  0  0  1      4
[65,]  0  0  0  1      5
[66,]  0  0  0  1      6
[67,]  0  0  0  1      1
[68,]  0  0  0  1      2
[69,]  0  0  0  1      3
[70,]  0  0  0  1      4
[71,]  0  0  0  1      5
[72,]  0  0  0  1      6

What is the role of the contrast matrix?

When I set up model.matrix(), there are too many comparisons:

> design<-model.matrix(~factor(mat))
> design
    (Intercept) factor(mat)1 factor(mat)2 factor(mat)3 factor(mat)4
factor(mat)5 factor(mat)6
1             1            1            0            0
0            0            0
2             1            1            0            0
0            0            0
3             1            1            0            0
0            0            0
4             1            1            0            0
0            0            0
5             1            1            0            0
0            0            0
6             1            1            0            0
0            0            0
7             1            1            0            0
0            0            0
8             1            1            0            0
0            0            0
9             1            1            0            0
0            0            0
10            1            1            0            0
0            0            0
11            1            1            0            0
0            0            0
12            1            1            0            0
0            0            0
13            1            1            0            0
0            0            0
14            1            1            0            0
0            0            0
15            1            1            0            0
0            0            0
16            1            1            0            0
0            0            0
17            1            1            0            0
0            0            0
18            1            1            0            0
0            0            0
19            1            0            0            0
0            0            0
20            1            0            0            0
0            0            0
21            1            0            0            0
0            0            0
22            1            0            0            0
0            0            0
23            1            0            0            0
0            0            0
24            1            0            0            0
0            0            0
25            1            0            0            0
0            0            0
26            1            0            0            0
0            0            0
27            1            0            0            0
0            0            0
28            1            0            0            0
0            0            0
29            1            0            0            0
0            0            0
30            1            0            0            0
0            0            0
31            1            0            0            0
0            0            0
32            1            0            0            0
0            0            0
33            1            0            0            0
0            0            0
34            1            0            0            0
0            0            0
35            1            0            0            0
0            0            0
36            1            0            0            0
0            0            0
37            1            0            0            0
0            0            0
38            1            0            0            0
0            0            0
39            1            0            0            0
0            0            0
40            1            0            0            0
0            0            0
41            1            0            0            0
0            0            0
42            1            0            0            0
0            0            0
43            1            0            0            0
0            0            0
44            1            0            0            0
0            0            0
45            1            0            0            0
0            0            0
46            1            0            0            0
0            0            0
47            1            0            0            0
0            0            0
48            1            0            0            0
0            0            0
49            1            0            0            0
0            0            0
50            1            0            0            0
0            0            0
51            1            0            0            0
0            0            0
52            1            0            0            0
0            0            0
53            1            0            0            0
0            0            0
54            1            0            0            0
0            0            0
55            1            0            0            0
0            0            0
56            1            0            0            0
0            0            0
57            1            0            0            0
0            0            0
58            1            0            0            0
0            0            0
59            1            0            0            0
0            0            0
60            1            0            0            0
0            0            0
61            1            0            0            0
0            0            0
62            1            0            0            0
0            0            0
63            1            0            0            0
0            0            0
64            1            0            0            0
0            0            0
65            1            0            0            0
0            0            0
66            1            0            0            0
0            0            0
67            1            0            0            0
0            0            0
68            1            0            0            0
0            0            0
69            1            0            0            0
0            0            0
70            1            0            0            0
0            0            0
71            1            0            0            0
0            0            0
72            1            0            0            0
0            0            0
73            1            0            0            0
0            0            0
74            1            0            0            0
0            0            0
75            1            0            0            0
0            0            0
76            1            0            0            0
0            0            0
77            1            0            0            0
0            0            0
78            1            0            0            0
0            0            0
79            1            0            0            0
0            0            0
80            1            0            0            0
0            0            0
81            1            0            0            0
0            0            0
82            1            0            0            0
0            0            0
83            1            0            0            0
0            0            0
84            1            0            0            0
0            0            0
85            1            0            0            0
0            0            0
86            1            0            0            0
0            0            0
87            1            0            0            0
0            0            0
88            1            0            0            0
0            0            0
89            1            0            0            0
0            0            0
90            1            0            0            0
0            0            0
91            1            1            0            0
0            0            0
92            1            1            0            0
0            0            0
93            1            1            0            0
0            0            0
94            1            1            0            0
0            0            0
95            1            1            0            0
0            0            0
96            1            1            0            0
0            0            0
97            1            1            0            0
0            0            0
98            1            1            0            0
0            0            0
99            1            1            0            0
0            0            0
100           1            1            0            0
0            0            0
101           1            1            0            0
0            0            0
102           1            1            0            0
0            0            0
103           1            1            0            0
0            0            0
104           1            1            0            0
0            0            0
105           1            1            0            0
0            0            0
106           1            1            0            0
0            0            0
107           1            1            0            0
0            0            0
108           1            1            0            0
0            0            0
109           1            0            0            0
0            0            0
110           1            0            0            0
0            0            0
111           1            0            0            0
0            0            0
112           1            0            0            0
0            0            0
113           1            0            0            0
0            0            0
114           1            0            0            0
0            0            0
115           1            0            0            0
0            0            0
116           1            0            0            0
0            0            0
117           1            0            0            0
0            0            0
118           1            0            0            0
0            0            0
119           1            0            0            0
0            0            0
120           1            0            0            0
0            0            0
121           1            0            0            0
0            0            0
122           1            0            0            0
0            0            0
123           1            0            0            0
0            0            0
124           1            0            0            0
0            0            0
125           1            0            0            0
0            0            0
126           1            0            0            0
0            0            0
127           1            0            0            0
0            0            0
128           1            0            0            0
0            0            0
129           1            0            0            0
0            0            0
130           1            0            0            0
0            0            0
131           1            0            0            0
0            0            0
132           1            0            0            0
0            0            0
133           1            0            0            0
0            0            0
134           1            0            0            0
0            0            0
135           1            0            0            0
0            0            0
136           1            0            0            0
0            0            0
137           1            0            0            0
0            0            0
138           1            0            0            0
0            0            0
139           1            0            0            0
0            0            0
140           1            0            0            0
0            0            0
141           1            0            0            0
0            0            0
142           1            0            0            0
0            0            0
143           1            0            0            0
0            0            0
144           1            0            0            0
0            0            0
145           1            0            0            0
0            0            0
146           1            0            0            0
0            0            0
147           1            0            0            0
0            0            0
148           1            0            0            0
0            0            0
149           1            0            0            0
0            0            0
150           1            0            0            0
0            0            0
151           1            0            0            0
0            0            0
152           1            0            0            0
0            0            0
153           1            0            0            0
0            0            0
154           1            0            0            0
0            0            0
155           1            0            0            0
0            0            0
156           1            0            0            0
0            0            0
157           1            0            0            0
0            0            0
158           1            0            0            0
0            0            0
159           1            0            0            0
0            0            0
160           1            0            0            0
0            0            0
161           1            0            0            0
0            0            0
162           1            0            0            0
0            0            0
163           1            0            0            0
0            0            0
164           1            0            0            0
0            0            0
165           1            0            0            0
0            0            0
166           1            0            0            0
0            0            0
167           1            0            0            0
0            0            0
168           1            0            0            0
0            0            0
169           1            0            0            0
0            0            0
170           1            0            0            0
0            0            0
171           1            0            0            0
0            0            0
172           1            0            0            0
0            0            0
173           1            0            0            0
0            0            0
174           1            0            0            0
0            0            0
175           1            0            0            0
0            0            0
176           1            0            0            0
0            0            0
177           1            0            0            0
0            0            0
178           1            0            0            0
0            0            0
179           1            0            0            0
0            0            0
180           1            0            0            0
0            0            0
181           1            1            0            0
0            0            0
182           1            1            0            0
0            0            0
183           1            1            0            0
0            0            0
184           1            1            0            0
0            0            0
185           1            1            0            0
0            0            0
186           1            1            0            0
0            0            0
187           1            1            0            0
0            0            0
188           1            1            0            0
0            0            0
189           1            1            0            0
0            0            0
190           1            1            0            0
0            0            0
191           1            1            0            0
0            0            0
192           1            1            0            0
0            0            0
193           1            1            0            0
0            0            0
194           1            1            0            0
0            0            0
195           1            1            0            0
0            0            0
196           1            1            0            0
0            0            0
197           1            1            0            0
0            0            0
198           1            1            0            0
0            0            0
199           1            0            0            0
0            0            0
200           1            0            0            0
0            0            0
201           1            0            0            0
0            0            0
202           1            0            0            0
0            0            0
203           1            0            0            0
0            0            0
204           1            0            0            0
0            0            0
205           1            0            0            0
0            0            0
206           1            0            0            0
0            0            0
207           1            0            0            0
0            0            0
208           1            0            0            0
0            0            0
209           1            0            0            0
0            0            0
210           1            0            0            0
0            0            0
211           1            0            0            0
0            0            0
212           1            0            0            0
0            0            0
213           1            0            0            0
0            0            0
214           1            0            0            0
0            0            0
215           1            0            0            0
0            0            0
216           1            0            0            0
0            0            0
217           1            0            0            0
0            0            0
218           1            0            0            0
0            0            0
219           1            0            0            0
0            0            0
220           1            0            0            0
0            0            0
221           1            0            0            0
0            0            0
222           1            0            0            0
0            0            0
223           1            0            0            0
0            0            0
224           1            0            0            0
0            0            0
225           1            0            0            0
0            0            0
226           1            0            0            0
0            0            0
227           1            0            0            0
0            0            0
228           1            0            0            0
0            0            0
229           1            0            0            0
0            0            0
230           1            0            0            0
0            0            0
231           1            0            0            0
0            0            0
232           1            0            0            0
0            0            0
233           1            0            0            0
0            0            0
234           1            0            0            0
0            0            0
235           1            0            0            0
0            0            0
236           1            0            0            0
0            0            0
237           1            0            0            0
0            0            0
238           1            0            0            0
0            0            0
239           1            0            0            0
0            0            0
240           1            0            0            0
0            0            0
241           1            0            0            0
0            0            0
242           1            0            0            0
0            0            0
243           1            0            0            0
0            0            0
244           1            0            0            0
0            0            0
245           1            0            0            0
0            0            0
246           1            0            0            0
0            0            0
247           1            0            0            0
0            0            0
248           1            0            0            0
0            0            0
249           1            0            0            0
0            0            0
250           1            0            0            0
0            0            0
251           1            0            0            0
0            0            0
252           1            0            0            0
0            0            0
253           1            0            0            0
0            0            0
254           1            0            0            0
0            0            0
255           1            0            0            0
0            0            0
256           1            0            0            0
0            0            0
257           1            0            0            0
0            0            0
258           1            0            0            0
0            0            0
259           1            0            0            0
0            0            0
260           1            0            0            0
0            0            0
261           1            0            0            0
0            0            0
262           1            0            0            0
0            0            0
263           1            0            0            0
0            0            0
264           1            0            0            0
0            0            0
265           1            0            0            0
0            0            0
266           1            0            0            0
0            0            0
267           1            0            0            0
0            0            0
268           1            0            0            0
0            0            0
269           1            0            0            0
0            0            0
270           1            0            0            0
0            0            0
271           1            1            0            0
0            0            0
272           1            1            0            0
0            0            0
273           1            1            0            0
0            0            0
274           1            1            0            0
0            0            0
275           1            1            0            0
0            0            0
276           1            1            0            0
0            0            0
277           1            1            0            0
0            0            0
278           1            1            0            0
0            0            0
279           1            1            0            0
0            0            0
280           1            1            0            0
0            0            0
281           1            1            0            0
0            0            0
282           1            1            0            0
0            0            0
283           1            1            0            0
0            0            0
284           1            1            0            0
0            0            0
285           1            1            0            0
0            0            0
286           1            1            0            0
0            0            0
287           1            1            0            0
0            0            0
288           1            1            0            0
0            0            0
289           1            1            0            0
0            0            0
290           1            0            1            0
0            0            0
291           1            0            0            1
0            0            0
292           1            0            0            0
1            0            0
293           1            0            0            0
0            1            0
294           1            0            0            0
0            0            1
295           1            1            0            0
0            0            0
296           1            0            1            0
0            0            0
297           1            0            0            1
0            0            0
298           1            0            0            0
1            0            0
299           1            0            0            0
0            1            0
300           1            0            0            0
0            0            1
301           1            1            0            0
0            0            0
302           1            0            1            0
0            0            0
303           1            0            0            1
0            0            0
304           1            0            0            0
1            0            0
305           1            0            0            0
0            1            0
306           1            0            0            0
0            0            1
307           1            1            0            0
0            0            0
308           1            0            1            0
0            0            0
309           1            0            0            1
0            0            0
310           1            0            0            0
1            0            0
311           1            0            0            0
0            1            0
312           1            0            0            0
0            0            1
313           1            1            0            0
0            0            0
314           1            0            1            0
0            0            0
315           1            0            0            1
0            0            0
316           1            0            0            0
1            0            0
317           1            0            0            0
0            1            0
318           1            0            0            0
0            0            1
319           1            1            0            0
0            0            0
320           1            0            1            0
0            0            0
321           1            0            0            1
0            0            0
322           1            0            0            0
1            0            0
323           1            0            0            0
0            1            0
324           1            0            0            0
0            0            1
325           1            1            0            0
0            0            0
326           1            0            1            0
0            0            0
327           1            0            0            1
0            0            0
328           1            0            0            0
1            0            0
329           1            0            0            0
0            1            0
330           1            0            0            0
0            0            1
331           1            1            0            0
0            0            0
332           1            0            1            0
0            0            0
333           1            0            0            1
0            0            0
334           1            0            0            0
1            0            0
335           1            0            0            0
0            1            0
336           1            0            0            0
0            0            1
337           1            1            0            0
0            0            0
338           1            0            1            0
0            0            0
339           1            0            0            1
0            0            0
340           1            0            0            0
1            0            0
341           1            0            0            0
0            1            0
342           1            0            0            0
0            0            1
343           1            1            0            0
0            0            0
344           1            0            1            0
0            0            0
345           1            0            0            1
0            0            0
346           1            0            0            0
1            0            0
347           1            0            0            0
0            1            0
348           1            0            0            0
0            0            1
349           1            1            0            0
0            0            0
350           1            0            1            0
0            0            0
351           1            0            0            1
0            0            0
352           1            0            0            0
1            0            0
353           1            0            0            0
0            1            0
354           1            0            0            0
0            0            1
355           1            1            0            0
0            0            0
356           1            0            1            0
0            0            0
357           1            0            0            1
0            0            0
358           1            0            0            0
1            0            0
359           1            0            0            0
0            1            0
360           1            0            0            0
0            0            1
attr(,"assign")
[1] 0 1 1 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$`factor(mat)`
[1] "contr.treatment"

This does not work"

> fit<-lmFit(sponge_ExpressionSet,design)
Error in lm.fit(design, t(M)) : incompatible dimensions
> exprs(sponge_data_matrix)->spongeExprs
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘exprs’ for signature
‘"matrix"’


My ExpressionSet is built from scratch:

>
sponge_ExpressionSet<-new("ExpressionSet",exprs=sponge_data_matrix,phenoData=pd,experimentData=experimentData,featureData=an)
> sponge_ExpressionSet
ExpressionSet (storageMode: lockedEnvironment)
assayData: 15744 features, 72 samples
  element names: exprs
protocolData: none
phenoData
  sampleNames: 1_1 1_2 ... 9_8 (72 total)
  varLabels: Chip.Number File.Name ... percentlessthan0 (12 total)
  varMetadata: labelDescription
featureData
  featureNames: 1 2 ... 15744 (15744 total)
  fvarLabels: Column Row ... X.1 (23 total)
  fvarMetadata: labelDescription
experimentData: use 'experimentData(object)'
Annotation:

	[[alternative HTML version deleted]]

