My Question #1
In the MAST documentation there are examples for doing the lrTest dropping one of the coefficients from the model. When it comes to dropping multiple coefficients, i.e. for the general case of comparing a full model to a nested reduced model, it seems that the documentation is a bit unclear. I would like to confirm that this can be done in the following way, with a toy example:
Say I have a crossed design and would like to analyze the data in the classical two-way ANOVA-like manner, for which the model expressed in R formula is ~x*z
, where x
is a factor of two levels "a"
and "b"
, and z
is a factor of three levels "a"
, "b"
, and "c"
. And I would like to do a LR test for all the interaction terms at once. The design matrix, say from model.matrix
would have columns named "(Intercept)"
, "xb"
, "zb"
, "zc"
, "xb:zb"
and "xb:zc"
, the interaction terms would correspond to the last two columns. Given this, I tried the code below:
# zlmFit is a returned object from running zlm() with the above design
# do LR test for the intended interaction effects
lrTest(zlmFit, hypothesis=as.matrix(c(0,0,0,0,1,1)))
This did run and returned some results. But I would like to confirm that this is the correct way and the results are indeed for the intended test as described above.
My Question #2
It was mentioned in the MAST publication that the cellular detection rate (CDR) can be controlled for by adding the variable as a covariate in the discrete and continuous models. Somehow I had always thought that MAST::zlm
does the CDR correction in this way internally, but I recently realized I was probably wrong... So again just confirming, zlm
is actually not doing CDR correction internally by default, and if desired the user should manually add CDR as a covariate to his/her model, is this correct?
Thanks in advance for your help.
Hi Andrew,
Thanks a lot for your quick reply. For Question 1, thanks for directing me to the examples in
ZlmFit-class
. I'm still a bit unsure after reading those. Back to my above toy example, if sticking with the convenient user interface the package provides and avoid using a contrast matrix, would passing multiple coefficients in a character vector toCoefficientHypothesis
be the correct way? e.g.:lrTest(zlmFit, CoefficientHypothesis(c("xb:zb","xb:zc")))
Also, I have to say that I'm not formally a statistician, and if the 0's and 1' in the contrast matrix I wrote in my original post should be the opposite, then I must have been seriously missing something... To double check, isn't it that the
CoefficientHypothesis
(in the single coefficient case) will be internally converted to a contrast vector of zeros except for the position of the specified model coefficient, which will be filled with 1? Thus the coefficients to literally drop from the full model should get value 1 in the contrast (or am I mistaken)? And when passing a plain matrix to thehypothesis
argument oflrTest
it will be treated as a contrast matrix? I also did a few quick tests and found inconsisent results even if I pass a matrix and reverse the 0's and 1's... Could you please kindly help looking through these below and help explain a bit further?However, as seen above, all 3 tests have different resulting P values. But I saw that the
df
's fromlrt1
andlrt3
are the same, but different from that of `lrt2' (not shown). What did I miss?Thanks again!
I wonder if other members of the development team or other experienced users may answer my question above... Thanks!
Err, you are right -- I did have it inverted. I edited my answer above. Sorry for the confusion!
Thanks a lot for your reply Andrew, this is very helpful! I tried and indeed the df=2 test by passing a two-column matrix gave the same results as passing a vector of two coefficient names to
CoefficientHypothesis
.The remaining question is why for the df=1 case, the
lrt1
(results with a single-column matrix/column vector) andlrt3
(results withCoefficientHypothesis
) are different, as asked in my previous post. Could you please help shed some light on this when you have another few free minutes? Again, much appreciated.I'm suspicious there may be a bug in the matrix method, and would use the CoefficientHypothesis method instead.
When passed a matrix,
lrTest
calls a method.rotateMM
, which I suppose is trying to fit the model subject to the constraint imposed by the contrast, but it's doing something odd that doesn't really make sense to 2023 me. It'd be great if you could open a an issue on github so that I can look into this more when I have more time.OK sounds good. I will open an issue on GitHub. Thanks again.
Edited: the issue is now opened here.