I am interested in looking at the differences in the effect of a condition on each sex. The contrast I am interested in is (Female.post - Female.pre) - (Male.post - Male.pre). I am uncertain as to how best incorporate pairing into my study and adjust for covariates.
One way I have tried to incorporate pairing is to randomize the patient effect by using duplicateCorrelation(). My design is therefore:
f = paste(dge$samples$sex, dge$samples$condition, sep = ".")
f = factor(f, levels = c("Male.pre", "Male.post", "Female.pre", "Female.post"))
d = model.matrix(~ 0 + f + age + dm + axc, colData)
cont = makeContrasts(M.PvP="fMale.post-fMale.pre", F.PvP="fFemale.post-fFemale.pre", sexDiff="(fFemale.post-fFemale.pre) - (fMale.post-fMale.pre)", levels = d)
where colData is my list of covariates, dge&samples is the colData object in my dge object containing all sample an count info, M.PvP is the effect of condition on males, F.PvP is the effect of condition of females, and sexDiff is the contrast of interest (the difference in the effect of condition on each sex). I get around 274 genes for the contrast of interest.
However, I am concerned that using duplicateCorrelation() in addition to adjusting for covariates in the design matrix is over-adjusting and assumes a linear relationship between my outcome and my covariates.
So another strategy I have tried is to block for the pairing effect in the design matrix as such:
design <- model.matrix(~ patient + sex:condition, colData)
design <- design[,!grepl("pre", colnames(design))]
colnames(design) <- sub(":", "_", colnames(design))
con <- makeContrasts(sexDiff = "sexFemale_conditionpost - sexMale_conditionpost", levels=design)
However, when I go to do my fit, I get the error "In contrasts.fit(fit, con) : row names of contrasts don't match col names of coefficients". Additionally, I only get 6 genes in my contrast of interest.
What strategy should I be going with? Thank you so much for taking the time to help!
If you got an error in your second approach, how did you still manage to test for DE genes with that contrast? In any case, provide a minimum working example that can recapitulate the error.
When I make my contrast matrix (following con <- makeContrasts(sexDiff = "sexFemale_conditionpost - sexMale_conditionpost", levels=design)), I get the following message: Warning message: In makeContrasts(sexDiff = "sexFemale_conditionpost - sexMale_conditionpost", : Renaming (Intercept) to Intercept
When I make my fit based on my contrast matrix (fit = lmfit(voom, design) fit2 = contrasts.fit(fit, con)) I get the following:
Warning message:
In contrasts.fit(fit, con) :
row names of contrasts don't match col names of coefficients
Limma still allows me to create these objects
That's a warning, not an error.