Question: Extracting data from edgeR R package
1
gravatar for Sara
16 months ago by
Sara150
Sara150 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 • 430 views
ADD COMMENTlink modified 16 months ago by zx87549.9k • written 16 months ago by Sara150
1
gravatar for zx8754
16 months ago by
zx87549.9k
London
zx87549.9k 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 16 months ago • written 16 months ago by zx87549.9k
0
gravatar for russhh
16 months ago by
russhh5.5k
UK, U. Glasgow
russhh5.5k 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 16 months ago by russhh5.5k

@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 16 months ago by Sara150

Sorry, that wasn't clear

ADD REPLYlink written 16 months ago by russhh5.5k
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: 1467 users visited in the last hour
_