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)

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).


1 Answer 1


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)

  • $\begingroup$ Thanks for the response $\endgroup$
    – Feynman
    Jun 13 at 18:34
  • $\begingroup$ 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. $\endgroup$
    – Feynman
    Jun 13 at 18:47
  • $\begingroup$ It is impossible to apply this regression on non-numeric column (error is pretty clear), you need to select the adequate columns $\endgroup$
    – Basti
    Jun 14 at 6:36
  • $\begingroup$ 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. $\endgroup$
    – Feynman
    Jun 14 at 6:44
  • 1
    $\begingroup$ 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 rdrr.io/bioc/limma/man/lmFit.html $\endgroup$
    – Basti
    Jun 14 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.