DESEQ2 Repeated Measures-like design error help
Entering edit mode
DS ▴ 10
Last seen 9 weeks ago
United Kingdom

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

    unname(mm2) <- apply(mm2, 2, function(x) all(x==0))

    idx <- which(
    mm2 <- mm2[,-idx]
    > 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':

DESeq2 • 402 views
Entering edit mode
Last seen 1 hour ago
United States

The last line is ignoring all the work you've done. You didn't supply the matrices to the function.

Note that instead of screenshots, it is recommended to copy paste code with "code fences" : triple backticks.

this will render like so

If you use single backticks inline it will look like so

Entering edit mode

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.

Entering edit mode

If you read this section we say it:

"You can remove these columns manually from the model matrix ..."

Entering edit mode

Thank you - that is what I was working off of but I must have misunderstood how to do that. I followed the instructions given:

"You can remove these columns manually from the model matrix and pass the corrected model matrix to the full argument of the DESeq function. See example code in the next section. Note that, in this case, you will not be able to create the DESeqDataSet with the design that leads to less than full rank model matrix. You can either use design=~1 when creating the dataset object, or you can provide the corrected model matrix to the design slot of the dataset from the start."

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?

Entering edit mode

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.


Login before adding your answer.

Traffic: 638 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6