<p>You need to look at how to create a model matrix : <a href="https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/model.matrix" rel="nofollow noreferrer">https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/model.matrix</a></p>
<p>In your code, you did not specify the data from which the Sex columns should be taken, or you did not created the Sex variable</p>
<p>Either create <code>Sex=df$Sex</code> or specify it in the model.matrix function <code>model.matrix(~ Sex, data=df)</code></p>

CC BY-SA 4.0
2023-06-13T18:34:39.537Z
Thanks for the response
Feynman
CC BY-SA 4.0
2023-06-13T18:47:44.727Z
I'm guessing you didn't address the other part of the question because this post had 2 questions embedded in it. If you know how to address the other part, could you help with that as well, please? I made another post while taking out the part that you answered.
Feynman
CC BY-SA 4.0
2023-06-14T06:36:55.087Z
It is impossible to apply this regression on non-numeric column (error is pretty clear), you need to select the adequate columns
Basti
CC BY-SA 4.0
2023-06-14T06:44:33.977Z
How would I go about doing that? I've tried ```lmFit(data.matrix(new_dataset[,-c(1,2)]), design)```, which gives the error ""row dimension of design doesn't match column dimension of data object"" and ```fit <- lmFit(new_dataset[,-c(1,2)], design[,-c(1,2)])``` which gives the same non-numeric column error.
Feynman
CC BY-SA 4.0
2023-06-14T07:09:43.850Z
Matrix to regress should be "A matrix-like data object containing log-ratios or log-expression values for a series of arrays, with rows corresponding to genes and columns to samples." You cannot regress the df object as it stands. It should be a matrix with samples as columns and V1, V2, etc as rows. You need to format df accordingly, everything is written in the lmFit description https://rdrr.io/bioc/limma/man/lmFit.html
Basti
CC BY-SA 4.0
2023-06-14T20:31:30.227Z
Okay, I transposed my df (I think that's what you meant). I'm still getting the same numerical error (what I have currently is ```fit <- lmFit(transposeddf[-(1:2)], design)```) (skipping the first two rows which are non-numeric). And the reason the matrix is flipped is because I needed to transpose it earlier for a separate process.
Feynman
CC BY-SA 4.0
2023-06-13T10:33:58.900Z
2023-06-13T10:33:58.900Z
Basti
<p>Here is part of my data table, which I will call &quot;df&quot;:</p>
<pre><code>    Subject.ID    Sex           V1           V2           V3           V4           V5
1   GTEX-1117F female   4.24944534   0.18307358   1.99276843   0.21785110   0.74777407
2   GTEX-1128S male    3.286585483  0.165944088  1.843983844  0.444455046  0.307311939
3   GTEX-11EMC female   3.31947343   0.27846061   1.46519089   0.33753984   0.91708799
4   GTEX-11GSP female  3.232353768  0.215492230  1.778208576  0.166458372  0.644225472
5   GTEX-11TTK male    2.934705200  0.256406854  1.712815854  0.256165277  0.948301812
6   GTEX-11ZUS male     3.77188558   0.18434378   2.43189035   0.37373172   1.14339342
7   GTEX-12WSD female   4.22032995   0.21933892   0.93900085   0.08687886   1.06901468
8   GTEX-12ZZX female   3.43616184   0.39473363   2.73205207   0.33525457   1.51399598
9   GTEX-1313W male     3.66334462   0.39418485   2.47248777   0.53545580   0.64634702
10  GTEX-131XW female  2.956614288  0.276317993  1.977096712  0.167743280  1.528071165
</code></pre>
<p>How do I correctly format the following code to account for the kind of dataframe I'm working with? I'm using sex as the factors to be interacted. Here is what I have so far:</p>
<pre><code>design &lt;- model.matrix(~ Sex)
fit &lt;- lmFit(df, design)
fit &lt;- eBayes(fit)
topTable(fit)
</code></pre>
<p>The first line is giving me the error &quot;Error in eval(predvars, data, env) : object 'Sex' not found&quot; (and idk why I'm getting this error since there is a &quot;Sex&quot; column in df). The second line gives me the error &quot;Expression object should be numeric, instead it is a data.frame with n non-numeric columns&quot; (and I know why I'm getting this error; I'm not sure how to handle the error, though).</p>

<r><limma>
How do I correctly format my limma/eBayes code?
# How do I correctly format my limma/eBayes code?

(Asked by: username_0 on 2023-06-13)

Here is part of my data table, which I will call "df":
    Subject.ID    Sex           V1           V2           V3           V4           V5
1   GTEX-1117F female   4.24944534   0.18307358   1.99276843   0.21785110   0.74777407
2   GTEX-1128S male    3.286585483  0.165944088  1.843983844  0.444455046  0.307311939
3   GTEX-11EMC female   3.31947343   0.27846061   1.46519089   0.33753984   0.91708799
4   GTEX-11GSP female  3.232353768  0.215492230  1.778208576  0.166458372  0.644225472
5   GTEX-11TTK male    2.934705200  0.256406854  1.712815854  0.256165277  0.948301812
6   GTEX-11ZUS male     3.77188558   0.18434378   2.43189035   0.37373172   1.14339342
7   GTEX-12WSD female   4.22032995   0.21933892   0.93900085   0.08687886   1.06901468
8   GTEX-12ZZX female   3.43616184   0.39473363   2.73205207   0.33525457   1.51399598
9   GTEX-1313W male     3.66334462   0.39418485   2.47248777   0.53545580   0.64634702
10  GTEX-131XW female  2.956614288  0.276317993  1.977096712  0.167743280  1.528071165

How do I correctly format the following code to account for the kind of dataframe I'm working with? I'm using sex as the factors to be interacted. Here is what I have so far:
design <- model.matrix(~ Sex)
fit <- lmFit(df, design)
fit <- eBayes(fit)
topTable(fit)

The first line is giving me the error "Error in eval(predvars, data, env) : object 'Sex' not found" (and idk why I'm getting this error since there is a "Sex" column in df). The second line gives me the error "Expression object should be numeric, instead it is a data.frame with n non-numeric columns" (and I know why I'm getting this error; I'm not sure how to handle the error, though).

**Tags:** r, limma

---

## 1 answers

### Answer by username_1 on 2023-06-13. Score: 2 | Accepted answer

You need to look at how to create a model matrix : <https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/model.matrix>

In your code, you did not specify the data from which the Sex columns should be taken, or you did not created the Sex variable

Either create `Sex=df$Sex` or specify it in the model.matrix function `model.matrix(~ Sex, data=df)`

> **Comments:**
> **username_0**: Thanks for the response  
> **username_0**: I'm guessing you didn't address the other part of the question because this post had 2 questions embedded in it. If you know how to address the other part, could you help with that as well, please? I made another post while taking out the part that you answered.  
> **username_1**: It is impossible to apply this regression on non-numeric column (error is pretty clear), you need to select the adequate columns  
> **username_0**: How would I go about doing that? I've tried ```lmFit(data.matrix(new_dataset[,-c(1,2)]), design)```, which gives the error ""row dimension of design doesn't match column dimension of data object"" and ```fit <- lmFit(new_dataset[,-c(1,2)], design[,-c(1,2)])``` which gives the same non-numeric column error.  
> **username_1**: Matrix to regress should be "A matrix-like data object containing log-ratios or log-expression values for a series of arrays, with rows corresponding to genes and columns to samples." You cannot regress the df object as it stands. It should be a matrix with samples as columns and V1, V2, etc as rows. You need to format df accordingly, everything is written in the lmFit description https://rdrr.io/bioc/limma/man/lmFit.html  
> **username_0**: Okay, I transposed my df (I think that's what you meant). I'm still getting the same numerical error (what I have currently is ```fit <- lmFit(transposeddf[-(1:2)], design)```) (skipping the first two rows which are non-numeric). And the reason the matrix is flipped is because I needed to transpose it earlier for a separate process.  

---

