<p>The problem is that you are transposing the vector of GA values with <code>t(ano$GA)</code>. Why would you do that? It produces a row matrix that is inappropriate for input to <code>model.matrix</code>.</p>
<p>All you need is</p>
<pre><code>design &lt;- model.matrix(~ano$GA)
</code></pre>
<p>and everything will work fine.</p>

CC BY-SA 4.0
2022-07-14T00:22:48.193Z
2022-07-14T03:16:12.347Z
2022-07-14T03:16:12.347Z
Gordon Smyth
<p>I have Affymetrix gene level expression matrix (genes in the rows and sample ID on the columns), and I have annotation data of microarray experiment observation where sample ID in the rows and description identification on the columns.</p>
<p><strong>example data</strong></p>
<p>here is Affymetrix gene level expression matix:</p>
<pre><code>&gt; dim(exprs_mat)
[1] 112830   735
&gt; exprs_mat[1:4, 1:3]
        Tarca_001_P1A01 Tarca_003_P1A03 Tarca_004_P1A04
1_at           6.062215        6.125023        5.875502
10_at          3.796484        3.805305        3.450245
100_at         5.849338        6.191562        6.550525
1000_at        3.567779        3.452524        3.316134
</code></pre>
<p>here is annotation data which contain experiment observation:</p>
<pre><code>&gt; dim(ano)
[1] 735   6
&gt; head(ano)
                       SampleID   GA Batch     Set Train Platform
Tarca_001_P1A01 Tarca_001_P1A01 11.0     1 PRB_HTA     1    HTA20
Tarca_013_P1B01 Tarca_013_P1B01 15.3     1 PRB_HTA     1    HTA20
Tarca_025_P1C01 Tarca_025_P1C01 21.7     1 PRB_HTA     1    HTA20
Tarca_037_P1D01 Tarca_037_P1D01 26.7     1 PRB_HTA     1    HTA20
Tarca_049_P1E01 Tarca_049_P1E01 31.3     1 PRB_HTA     1    HTA20
Tarca_061_P1F01 Tarca_061_P1F01 32.1     1 PRB_HTA     1    HTA20
</code></pre>
<p>I intend to see how the genes in each sample are correlated with GA value of corresponding samples in the annotation data. How can I get my expected correlation matrix and filter out the genes by correlation value? any idea to make this happen correctly?</p>
<p><strong>my attempt</strong></p>
<pre><code>library(limma)
fit &lt;- limma::lmFit(exprs_mat, design = model.matrix( ~ 0 + t(ano$GA))
fit &lt;- eBayes(fit)
topTable(fit, coef=2)
</code></pre>
<p>but this attempt gave me dimension error and I still didn't get highly correlated genes from <code>exprs_mat</code> with each <code>ano$GA</code>in <code>ano</code>data. I just removed <code>0+</code> and ran the code, then I got this error:</p>
<pre><code>row dimension of design doesn't match column dimension of data object
</code></pre>
<p>I am pretty sure I did <code>df[!is.na(df$GA), ]</code>, removed <code>NA</code> in both <code>exprs_mat</code> and <code>ano</code> metadata already, but the same error still persists. I also tried <code>df[complete.cases(df),]</code> to make sure I removed all <code>NA</code> values in my data.</p>
<p>How can I get those highly correlated genes correctly? any possible way to make this happen in R? any thought?</p>
<p>How can I cut down <code>exprs_mat</code> with the shortlist of genes? any idea?</p>
<p><strong>desired output</strong></p>
<p>I intend to filter out genes in the gene expression matrix <code>expr_mat</code> by using correlation value (only keep highly correlated genes), expected sub expression matrix should have same data structure as <code>expr_mat</code>. any way to get this done?</p>

CC BY-SA 4.0
2019-06-25T18:16:50.737Z
Have a look at the dimensions of what `model.matrix()` is returning, that should be telling.
Devon Ryan
<r><microarray><gene-expression><limma>
Any way to filter out highly correlated genes with limma linear model?
# Any way to filter out highly correlated genes with limma linear model?

(Asked by: username_0 on 2019-06-25)

I have Affymetrix gene level expression matrix (genes in the rows and sample ID on the columns), and I have annotation data of microarray experiment observation where sample ID in the rows and description identification on the columns.
example data
here is Affymetrix gene level expression matix:
> dim(exprs_mat)
[1] 112830   735
> exprs_mat[1:4, 1:3]
        Tarca_001_P1A01 Tarca_003_P1A03 Tarca_004_P1A04
1_at           6.062215        6.125023        5.875502
10_at          3.796484        3.805305        3.450245
100_at         5.849338        6.191562        6.550525
1000_at        3.567779        3.452524        3.316134

here is annotation data which contain experiment observation:
> dim(ano)
[1] 735   6
> head(ano)
                       SampleID   GA Batch     Set Train Platform
Tarca_001_P1A01 Tarca_001_P1A01 11.0     1 PRB_HTA     1    HTA20
Tarca_013_P1B01 Tarca_013_P1B01 15.3     1 PRB_HTA     1    HTA20
Tarca_025_P1C01 Tarca_025_P1C01 21.7     1 PRB_HTA     1    HTA20
Tarca_037_P1D01 Tarca_037_P1D01 26.7     1 PRB_HTA     1    HTA20
Tarca_049_P1E01 Tarca_049_P1E01 31.3     1 PRB_HTA     1    HTA20
Tarca_061_P1F01 Tarca_061_P1F01 32.1     1 PRB_HTA     1    HTA20

I intend to see how the genes in each sample are correlated with GA value of corresponding samples in the annotation data. How can I get my expected correlation matrix and filter out the genes by correlation value? any idea to make this happen correctly?
my attempt
library(limma)
fit <- limma::lmFit(exprs_mat, design = model.matrix( ~ 0 + t(ano$GA))
fit <- eBayes(fit)
topTable(fit, coef=2)

but this attempt gave me dimension error and I still didn't get highly correlated genes from exprs_mat with each ano$GAin anodata. I just removed 0+ and ran the code, then I got this error:
row dimension of design doesn't match column dimension of data object

I am pretty sure I did df[!is.na(df$GA), ], removed NA in both exprs_mat and ano metadata already, but the same error still persists. I also tried df[complete.cases(df),] to make sure I removed all NA values in my data.
How can I get those highly correlated genes correctly? any possible way to make this happen in R? any thought?
How can I cut down exprs_mat with the shortlist of genes? any idea?
desired output
I intend to filter out genes in the gene expression matrix expr_mat by using correlation value (only keep highly correlated genes), expected sub expression matrix should have same data structure as expr_mat. any way to get this done?

**Tags:** r, microarray, gene-expression, limma
> **Comments:**
> **username_1**: Have a look at the dimensions of what `model.matrix()` is returning, that should be telling.  

---

## 1 answers

### Answer by username_2 on 2022-07-14. Score: 2 | Accepted answer

The problem is that you are transposing the vector of GA values with t(ano$GA). Why would you do that? It produces a row matrix that is inappropriate for input to model.matrix.
All you need is
design <- model.matrix(~ano$GA)

and everything will work fine.


---

