Question: Extracting data from edgeR R package
1
gravatar for Sara
11 weeks ago by
Sara50
Sara50 wrote:

I am using edgeR package in R and here the code I used

library(edgeR)
target <-read.delim("metadata.txt", header=T)
x <- read.csv('data4.txt', row.names = 1)
group <- factor(target$group)
design <- model.matrix(~0+group)

when I print the design variable I would get the following results:

> design
   group1 group2
1       1      0
2       1      0
3       0      1
4       1      0
5       0      1
6       1      0
7       1      0
8       1      0
9       0      1
10      0      1
11      1      0
12      0      1
attr(,"assign")
[1] 1 1
attr(,"contrasts")
attr(,"contrasts")$group
[1] "contr.treatment"

I would like to make a new variable called comparison like this:

comparison = "group1-group2"

I actually do not know how to do that because group1 and group2 are not headers or separated sections. do you guys know how to that?

edger R • 150 views
ADD COMMENTlink modified 11 weeks ago by zx87548.4k • written 11 weeks ago by Sara50
1
gravatar for zx8754
11 weeks ago by
zx87548.4k
London
zx87548.4k wrote:

Get the dimnames:

#example data
group <- factor(1:2)
design <- model.matrix(~0+group)
design 
#   group1 group2
# 1      1      0
# 2      0      1
# attr(,"assign")
# [1] 1 1
# attr(,"contrasts")
# attr(,"contrasts")$group
# [1] "contr.treatment"

paste(dimnames(design)[[2]], collapse = "-")
# [1] "group1-group2"
ADD COMMENTlink modified 11 weeks ago • written 11 weeks ago by zx87548.4k
0
gravatar for russhh
11 weeks ago by
russhh4.8k
UK, U. Glasgow
russhh4.8k wrote:

Hi are you trying to subtract the second column of the design from the first, you could do that with matrix manipulation: as.matrix(design) %*% c(1, -1). However, I suspect you're trying to define an experimental comparison (contrast) for use in the edgeR workflow. As such you're probably looking for limma::makeContrasts https://www.rdocumentation.org/packages/limma/versions/3.28.14/topics/makeContrasts ;

contrasts <- limma::makeContrasts(comparison = "group1 - group2", levels = design)
ADD COMMENTlink written 11 weeks ago by russhh4.8k

@russhh: in your solution I have to type manually but I want to make "group1 - group2" automatically. because instead of "group1 - group2" I can have: "groupA- groupB".

ADD REPLYlink written 11 weeks ago by Sara50

Sorry, that wasn't clear

ADD REPLYlink written 11 weeks ago by russhh4.8k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1774 users visited in the last hour