This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Specifying a variable as a random effect in model.matrix()

I understand that it is possible to specify variables as fixed effects in R for building a model matrix, for example:

model.matrix(~age-category, data = sample_table)

Is it possible to do the same but with random effects? I want to specify a column called "subject_ID" for a paired analysis as a random effect, but it is currently a factor. The below command throws an error:

model.matrix(~(1 | subject_ID), data = sample_table)

Error in 1 | subject : 
  operations are possible only for numeric, logical or complex types

Is this the right approach? Are there functions other than model.matrix() that can be used to achieve this? For context, I'm trying to build the model matrix before I run SNM for the normalization of expression data. Appreciate any help!

snm model.matrix r

I am facing the same error.. Have you figured it out?

0 answers

No answers yet.

Log in to answer this question.