I am so sorry about the format of this post - I wasn't able to post this normally (see here), so here are screen shots
Edit: managed to get the code pasted - removed screenshots and wrote out the question again:
I am really at a loss here. I have an experiment where the samples are in the following groups: Status (Control; Status), Time.Point (Before Treatment; After Treatment)
I want to take "repeated measures" into account (i.e. before vs after) and was trying to follow the instructions here. "Group Specific condition effects, individuals nested within groups" followed by this: (in order to deal with the unbalanced nature of the experiment) "Levels without samples"
I am getting stuck and don't know how to fix it
dsq <- phyloseq_to_deseq2(taxa_subset, ~ 1)
> dsq
class: DESeqDataSet
dim: 52 20
metadata(1): version
assays(1): counts
rownames(52): Otu00001 Otu00002 ... Otu19614 Otu32323
rowData names(0):
colnames(20): BP1 BP1P ... BP7 BP7P
colData names(9): Sample.ID Age ... Experiment.Number Type
coldata <- colData(dsq)
> head(coldata)
DataFrame with 6 rows and 10 columns
Sample.ID Age Time.Point Treatment Sex Status Animal
<character> <character> <character> <character> <character> <character> <character>
BP1 BP1 Offspring Before Chronic Stress Male Control Chronic Stress
BP1P BP1 Offspring After Chronic Stress Male PNS Chronic Stress
BP2 BP2 Offspring Before Chronic Stress Male PNS Chronic Stress
BP21 BP21 Offspring Before Chronic Stress Male PNS Chronic Stress
BP23 BP23 Offspring Before Chronic Stress Male PNS Chronic Stress
BP23P BP23 Offspring After Chronic Stress Male PNS Chronic Stress
Experiment.Number Type Sample.ID.with.P
<character> <character> <character>
BP1 2C Sample BP1
BP1P 2H Sample BP1P
BP2 2D Sample BP2
BP21 2D Sample BP21
BP23 2D Sample BP23
BP23P 2H Sample BP23P
dsq$Status <- factor(dsq$Status, levels = c("Control","Stress"))
dsq$Time.Point <- factor(dsq$Time.Point, levels = c("Before","After"))
dsq$Sample.ID <- factor(dsq$Sample.ID)
mm2 <- model.matrix(~ Time.Point + Time.Point:Sample.ID + Status:Time.Point, data = colData(dsq))
colnames(mm2)
unname(mm2)
all.zero <- apply(mm2, 2, function(x) all(x==0))
all.zero
idx <- which(all.zero)
mm2 <- mm2[,-idx]
unname(mm2)
> head(mm2)
(Intercept) Time.PointAfter Time.PointBefore:Sample.IDBP2 Time.PointAfter:Sample.IDBP2
BP1 1 0 0 0
BP1P 1 1 0 0
BP2 1 0 1 0
BP21 1 0 0 0
BP23 1 0 0 0
BP23P 1 1 0 0
design(dsq) <- mm2
diagdds <- DESeq(dsq)
using supplied model matrix
Error in checkFullRank(full) :
the model matrix is not full rank, so the model cannot be fit as specified.
One or more variables or interaction terms in the design formula are linear
combinations of the others and must be removed.
Please read the vignette section 'Model matrix not full rank':
vignette('DESeq2')
Ah thank you for your answer! How do I apply the matrices to the function correctly? I thought the
design(dsq) <- mm2
would do that.Re the screenshots - yes I wrote out the full question on here and have been trying to post it correctly but I kept getting an error and it wouldn't let me post (I even made a second post trying to address that - here), so I had to resort to screenshots of the question.
If you read this section we say it:
https://bioconductor.org/packages/release/bioc/vignettes/DESeq2/inst/doc/DESeq2.html#group-specific-condition-effects-individuals-nested-within-groups
"You can remove these columns manually from the model matrix ..."
Thank you - that is what I was working off of but I must have misunderstood how to do that. I followed the instructions given:
I followed the instructions in the next bit "Levels without samples" and tried apply the new matrix to the design but that's where it seems I've gone wrong. How do I do that?
I really appreciate your help in this - I'm not a very experienced user and trying to learn.
Edit: I'm still quite stuck and don't know what to do - does anyone have any suggestions?
Given that this is an important step, it might be worth finding someone with R experience who can guide you. You don't want to just try it until the code doesn't give an error.