Timeline for What is a contrast matrix?
Current License: CC BY-SA 3.0
65 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 15 at 16:01 | comment | added | Tomas | Super complicated, wrote a book without actually answering the question. I was asking for simple definition; it would take a professor to dig it out of your answer, if it is even there... | |
Jul 13, 2017 at 7:10 | history | edited | ttnphns | CC BY-SA 3.0 |
added 13 characters in body
|
Jul 12, 2017 at 12:20 | history | edited | ttnphns | CC BY-SA 3.0 |
added 22 characters in body
|
Apr 13, 2017 at 12:44 | history | edited | CommunityBot |
replaced http://stats.stackexchange.com/ with https://stats.stackexchange.com/
|
|
Jul 10, 2016 at 1:24 | comment | added | ttnphns |
I'm defining G with having rows summing to zero What is that? Sum in each row is 0? That's exactly the property of L (apart fom row Constant). Or you mean different?
|
|
Jul 10, 2016 at 0:41 | comment | added | ogustavo | I addressed this issue when I said "Compare the last 3 columns of the above matrix (in this case, matrix $modified \mathbf{X}$) with @ttnphns' matrix L. Despite of the order, they are quite similar." In this case, L is a partition of $modified \mathbf{X}$. Now, comparing G and L, you may add lines and columns to them, to make them equal, but then they are not L nor G anymore. Moreover, I'm defining G with having rows summing to zero (that's the whole point of G), a characteristic that L doesn't have. | |
Jul 10, 2016 at 0:09 | comment | added | ttnphns | (cont.) OK, add column of 1s as the 1st col (as I did in my examples) and invert the matrix. You will get the matrix L. Now, insert in it the 1st col of 0s, and optionally remove the 1st row. Now you have the matrix which you labeled G. To me, it is just L matrix, only formatted specifically for general linear modeling (I touch this issue in my section "Where are the model parameters after all?"). You have not convinced me that a new term "G matrix" is needed. | |
Jul 10, 2016 at 0:08 | comment | added | ttnphns | @Gus_est, thanks for updating your great answer. But: Why do you insist your G matrix is different from "my" L matrix? I see no fundamental difference. Consider case in your section "Relating OP's contrast matrix to my answer". The starting matrix is the indicator coding matrix with level 1 taken as reference level. (in my examples, I took the last level as reference: you may take any level as reference, it changes nothing theoretically). | |
Jul 9, 2016 at 22:20 | comment | added | ogustavo | Thanks @amoeba and ttnphns for the discussion. As you can see, I made (another) revision to my answer, adding the comparisons I promised. I started to call my contrast matrix as G, since I couldn't relate it completely to neither L or C. | |
Jul 9, 2016 at 14:18 | history | edited | ttnphns | CC BY-SA 3.0 |
added 272 characters in body
|
Jul 9, 2016 at 13:41 | history | edited | ttnphns | CC BY-SA 3.0 |
added 715 characters in body
|
Jul 9, 2016 at 13:33 | history | edited | ttnphns | CC BY-SA 3.0 |
added 715 characters in body
|
Jul 8, 2016 at 23:45 | history | bounty ended | amoeba | ||
Jul 8, 2016 at 23:44 | comment | added | amoeba | +11. Ttnphns and @Gus_est, I learned a lot from both your answers, so I'd like to thank both of you and I'd like to award the bounty to both of you too. Unfortunately, it is not possible. So I am going to award the bounty to this answer now and then either start another bounty myself or ask somebody else to do it in order to award Gus'es answer too (if I do it myself, I can only offer 200, it has to be doubled; Glen_b suggested he can offer 100 instead). I will be away for the weekend, so only next week I will get back to updating my answer as I promised to Ttnphns. Cheers to all! | |
Jul 8, 2016 at 15:53 | comment | added | Tomas | Thank you for this answer, but I will probably never be able nor have time to understand it. And I studied maths :-) I expected some very simple definition as an answer :-) | |
Jul 8, 2016 at 0:33 | comment | added | ogustavo | @amoeba got it. as I said, I'll read it carefully and maybe I'll change mine to something else (might be G hehe) | |
Jul 8, 2016 at 0:26 | comment | added | amoeba | @ttnphns You suggest a good challenge. I will try. | |
Jul 8, 2016 at 0:24 | comment | added | amoeba | @Gus_est As far as I understand, this is not entirely correct. Ttnphns's C matrix specifies the coding scheme that goes into constructing the design matrix X. His L matrix tells the meaning of each beta coefficient in the resulting regression. In your answer, you always use the same dummy coding scheme. However, you can have various null hypotheses and use different matrices of contrasts to test them. That's why earlier in this huge comment thread I started calling your "contrast matrix" G matrix, to make it distinct from both C and L. But I haven't yet convinced ttnphns that it makes sense. | |
Jul 8, 2016 at 0:09 | comment | added | ogustavo | @amoeba and ttnphns, I've seen that there's much discussion on the "naming" of the contrast matrix. From what I understood, your L matrix is my C matrix, and your C matrix is the last matrix on my example 2. Is this correct? If it is, I'll change my matrices to L, to make both answers more relatable. | |
Jul 7, 2016 at 21:33 | history | edited | amoeba | CC BY-SA 3.0 |
some typos
|
Jul 7, 2016 at 21:14 | comment | added | ttnphns | @Antony, as I've written C simply shows the data values of X. "aggr" here simply means: take one case (row) from each group (factor level) and show it. No, "aggrX" is not different from C. | |
Jul 7, 2016 at 21:02 | comment | added | ttnphns | @amoeba, Seeing forward to your answer crossing t's and dotting i's, with an example. Let me suggest you, for the example, to take my user-defined set of contrasts from factor F of my answer, with the data I gave, and test it via a regression, to reproduce my results - but you don't use C-matrix to recode the data; use, say, just the dummy variables. Hope you succeed. | |
Jul 7, 2016 at 20:59 | comment | added | Antoni Parellada | I am working through your answer with the firm belief that I will learn a lot, and I would like to share some thoughts as positive feedback. Here's my first observation... I got lost at this equation / definition: $\bf C= {\it{aggr}} X$. I wonder if you could motivate the need for ${\it{aggr}} X$ as conceptually different from $C$. | |
Jul 7, 2016 at 20:34 | comment | added | amoeba | This comment thread becomes too long. I will try to find time to write up my own answer as an extended comment to yours and Gus'es answers. For now let me just repeat that I think if you read Gus'es answer, you will see what I mean by manually performing a test that is not tied to the coding scheme. | |
Jul 7, 2016 at 19:35 | history | edited | ttnphns | CC BY-SA 3.0 |
added 661 characters in body
|
Jul 7, 2016 at 18:58 | history | edited | ttnphns | CC BY-SA 3.0 |
added 3329 characters in body
|
Jul 7, 2016 at 14:54 | comment | added | ttnphns |
As far as I understand, one can "manually" perform a test that is not tied to the coding scheme. Maybe it is possible by some adjustments and I only gasp to hear from you how. But think abstractly - how can one perform a test that is not dependent on the data values? The omnibus ANOVA tests - yes (different [correct] coding shemes will give the same result). But testing elementary contrasts is not an omnibus test.
|
|
Jul 7, 2016 at 14:43 | comment | added | ttnphns |
In ANOVA, comparing the "betas" is comparing factor levels (groups). $\beta_1-\beta_2/2-\beta_3/2=0$ null-hyp. is exactly $\mu_1=\mu_{23}$ or Mean_Gr1-1/2(Mean_Gr2+Mean_Gr3) , which is the second row (2nd partial, or elementary contrast) in the Helmert contrast coefficient matrix L shown in my answer (see there). To test it (via regression), I would use the whole Helmert L matrix displayed, create data X coded by C=ginv(L), run regression. The regr. coefficient for contrast variable A1 will be equal the (estimated) difference and its p-value will be the test significance. So is my way.
|
|
Jul 7, 2016 at 14:21 | comment | added | amoeba |
That L will determine what are you going to test, you aren't free anymore to choose what to test : No, I disagree with that. As far as I understand, one can "manually" perform a test that is not tied to the coding scheme. The formulas for that are provided in the Gus'es answer. I am not saying it's convenient in practice, I am just saying that it's possible. I think what you are saying is that C-matrix determines the meaning of each beta coefficient and the corresponding p-values will be for $\beta_i=0$. This is clear. But one can still "manually" test e.g. if $\beta_1-\beta_2/2-\beta_3/2=0$.
|
|
Jul 7, 2016 at 14:07 | comment | added | ttnphns | (cont.) Now, if that L (which you got from that C) appears to be unreasonable/incorrect to test a reasonable hypothesis that means the C you were given should go to litter bin. | |
Jul 7, 2016 at 14:07 | comment | added | ttnphns | Your pt (2) is something strange to me, what's the sense in doing that? You must either start with L (and get C from it), or start with C (and get L from it). The two must be in tune with each other. If you are "given some C matrix" you cannot think of some else "user-defined" L, you have to invert that C and get the L it determines. That L will determine what are you going to test, you aren't free anymore to choose what to test: every concrete comparison test implies its concrete L and C (concrete way of coding data in X). | |
Jul 7, 2016 at 13:47 | comment | added | amoeba | Okay, so in this case you would have a manual (user-defined) L-matrix, but then it will not equal to $C^{-1}$, is that what you mean? I am just trying to distinguish two procedures: (1) construct user-defined L-matrix, convert it to C-matrix, run linear regression, done. In this case $L=C^{-1}$. (2) use some given C-matrix, construct a used-defined L-matrix, run linear regression to get betas, use formulas to compute F- and p-values. In this case manual $L$ and $C^{-1}$ are distinct. I thought that you define L-matrix as the inverse of C-matrix (they can't differ), that's why I introduced G. | |
Jul 7, 2016 at 13:10 | comment | added | ttnphns | As I've understood it, the 3x5 matrices with zero row sums in Gus answer are examples of L matrices. For a custom comparison, you compose a custom L matrix. There is no manual G matrix: you compose manual L matrix. Manuals for specific ANOVA program implementations are full of examples showing how to compose user-defined L matrices. I don't get why you think you need some "G" matrix. | |
Jul 7, 2016 at 12:55 | comment | added | ttnphns | (cont from prev comment) Or you can, of course, first select or invent a coding schema C, then convert it to L. But the question is will that L be correct? (such as, usually we want 0 sum in every its row, if we want k=0), we also may want the rows (contrasts) to be orthogonal, etc. That means that we are not totally free in choosing C, coding of values of X. | |
Jul 7, 2016 at 12:53 | comment | added | amoeba |
Sorry for the confusion. I was talking about a "manual" hypothesis testing using formulas provided in Gus'es answer. I can construct X design matrix using C-matrix for dummy coding; then compute beta coefficients using linear regression; then construct G-matrix (by G-matrix I mean what Gus called C) corresponding to Gr1-1/4Gr2-3/4Gr3=0 comparison, and then use Gus'es formulas to compute the F-statistic and the p-value. If I do it like that, then L-matrix tells me what individual beta coefficients mean, but my own "manual" G is not equal to L.
|
|
Jul 7, 2016 at 12:45 | comment | added | ttnphns | Sorry, I can't get your last comment with "G" matrix. What's that? Testing in ANOVA amounts to Lb=k where k is the null result (usually k=0) [see contrast testing results in my answer, the tables named "K matrix" by SPSS, where hypothesized value is 0]. We select or compose L matrix for out contrast test. We specify it for an ANOVA program we run. We don't need C because we don't need to create the design matrix X: ANOVA or GLM program does it internally. If you want to try to recreate the ANOVA results via plain regression program, you need to create X: so need to compute C out of L. | |
Jul 7, 2016 at 12:28 | comment | added | ttnphns | I'd like to notice yet another terminologic ambiguety (personally observed it in some different texts): what is a contrast? Some sources call a contrast a row in L matrix. Other sources call a contrast an entire L matrix. To overcome the ambiguety, I used words "elementary" contrast (L row) and "combined" contrast (all L) in my answer. | |
Jul 7, 2016 at 12:27 | comment | added | amoeba |
Thank you, this is helpful! Here is my understanding. One can choose any coding C-matrix (with the corresponding L-matrix) and then test a particular user-defined hypothesis using a G-matrix (I will call it G now, but this is what is denoted as C in Gus'es answer). This G does not have to be equal to L. For example, one can use C and L for dummy coding, but then test if Gr1-1/4Gr2-3/4Gr3=0 (using some specific G). However, one can put this same comparison into the L-matrix, convert it to C-matrix, and then obtain one beta coefficient specifically for this comparison. Does it make sense?
|
|
Jul 7, 2016 at 12:16 | comment | added | ttnphns | @amoeba, I wasn't reading Gus_est answer attentively. I believe he/she shows how comparisons are made by introducing the concept of contrasts. Contrasts (L [C in Gus' notation]) in ANOVA are often composed as user-defined contrasts to test custom hypotheses (for example, compare Gr1 with a mixed group 1/4Gr2+3/4Gr3). But the very standard ANOVA is based on contrasts L too - the (any of) standard types observed in my answer. Any correct L matrix - "user" or "standard type" - could be inverted into C matrix of codes. Gus just don't discuss that topic, having other priorities in the answer. | |
Jul 7, 2016 at 11:59 | comment | added | amoeba | I think we are on the same page about this. Here is another issue. You wrote that Gus_est in their answer talks about your L-matrix (naming it C). I don't understand this. I think Gus_est talks about a matrix that specifies a particular comparison test, which is something independent from coding scheme. E.g. we can have 4 groups and use a dummy coding scheme; this specifies your C-matrix and also your L-matrix. But then we can still test various different hypotheses, using various matrices that Gus_est calls C (i.e. using various contrasts). Hence, his C is not your L! Am I confused? | |
Jul 7, 2016 at 11:50 | comment | added | ttnphns |
The OP clearly was asking about the "contrast matrix" in the R sense. Whichever sense the OP meant the L and C matrices should be always discussed in binding, as I've noticed in a comment.
|
|
Jul 7, 2016 at 11:37 | comment | added | ttnphns | @amoeba, don't you stuff the attic with that terminologic scrap :-) People will always use words and terms differently. Let me modestly recommend you "my" terminology: L contrast coefficient matrix and C contrast coding matrix. | |
Jul 7, 2016 at 11:32 | comment | added | ttnphns | SPSS algorithms docs, SPSS manuals adhere to "L-matrix aka contrast coefficient matrix" terminology and seldom if ever name the C matrix. "Contrast coding matrix aka C-matrix" terms could be considered - perhaps - my invetion/suggestion. | |
Jul 7, 2016 at 11:32 | comment | added | amoeba | Yes, I agree. By now I am convinced that "contrast matrix" is a term that is only used in the R community and refers to the coding scheme. I checked the textbook that Gus_est refers to and they never use the term "contrast matrix", they only talk about "contrasts" (see my last comment under his answer). The OP clearly was asking about the "contrast matrix" in the R sense. | |
Jul 7, 2016 at 11:28 | comment | added | ttnphns |
@amoeba, in ats.ucla.edu/stat/r/library/contrast_coding.htm look please: 1. Dummy Coding....#the contrast matrix for categorical variable with four levels and they show the C matrix. Next, 2 Simple Coding...Below we show the more general rule for creating this kind of coding scheme.....Let's create the contrast matrix manually using the scheme shown above and they show the C matrix. So, they equate "coding scheme"="contrast matrix". People may use words how they like (and we know that R community use terminology very loosely).
|
|
Jul 7, 2016 at 11:03 | comment | added | amoeba |
If you search for "contrast matrix" in that manual, you will see 11 times that they use this term. (They never call it "coding matrix", by the way; only talk about "coding schemes"). Also, glance into the R help page on the contrast package/function: they call this thing "contrast matrix" all the time. So it seems that at least in R community, "contrast matrix" refers to what you call "contrast coding matrix". I am just trying to clarify the terminology. Note that OP has some R code in the question, so probably was referring to R usage.
|
|
Jul 7, 2016 at 0:35 | comment | added | ttnphns | I've glanced into the R manual you link to. Yes, all those matrices they display are the C matrices. B/w they call them "coding" matrices, not "contrast" matrices. (I prefer to call them contrast coding matrices, because it's values of the contrast variables). Note that Gus_est's answer is all about L matrix (its role in testing). | |
Jul 6, 2016 at 23:57 | history | edited | ttnphns | CC BY-SA 3.0 |
added 10 characters in body
|
Jul 6, 2016 at 23:57 | comment | added | ttnphns | @amoeba, I'm not familiar with "contrast matrix" and almost sure it stands for "contrast coefficient matrix" or L-matrix, which is an official or at least wide spread term in (M)ANOVA/GLM. "Contrast coding matrix" term is much less mentioned as it is simply the aggrigated view of the design matrix X; I've seen "basis matrix" word used in papers of one SPSS's senior statistician Dave Nichols. Absolutely, L (official label) and C (arbitrary label?) matrices are so closely related that one can hardly discuss one w/o the other. I suppose that "contrast matrix" should be considered as this pair. | |
Jul 6, 2016 at 22:37 | comment | added | amoeba | Thanks for writing and updating this answer! I have several questions, here is the first one. In your answer you introduced "contrast coding matrix" ($C$) and "contrast coefficient matrix" ($L$). (By the way, are these standard terms? When I google "contrast coding matrix", I get only 5 hits, two of which lead to this very page). The OP, however, asks about "contrast matrix" and also gives several examples of those as used in R (see also this manual). Am I right in understanding that this "contrast matrix" is your $C$ (not $L$)? | |
Jul 6, 2016 at 19:31 | history | edited | ttnphns | CC BY-SA 3.0 |
deleted 288 characters in body
|
Jul 6, 2016 at 16:55 | history | edited | ttnphns | CC BY-SA 3.0 |
added 40 characters in body
|
Jul 6, 2016 at 16:40 | history | edited | ttnphns | CC BY-SA 3.0 |
deleted 1 character in body
|
Jul 6, 2016 at 16:28 | history | edited | ttnphns | CC BY-SA 3.0 |
added 7649 characters in body
|
Jul 6, 2016 at 16:10 | history | edited | ttnphns | CC BY-SA 3.0 |
added 7649 characters in body
|
Jul 6, 2016 at 10:07 | comment | added | Tomas | please do not restrict this answer just to anova if possible. The [anova] tag was added by @amoeba by the time when you answered my question, but I don't want the answer to be restricted just to anova. | |
Jul 4, 2016 at 17:18 | history | edited | ttnphns | CC BY-SA 3.0 |
numeric typo corrected
|
Jul 3, 2016 at 21:44 | history | edited | amoeba | CC BY-SA 3.0 |
added 1 character in body
|
Jul 3, 2016 at 11:55 | history | edited | ttnphns | CC BY-SA 3.0 |
added 753 characters in body
|
Jul 3, 2016 at 3:15 | history | edited | ttnphns | CC BY-SA 3.0 |
added 141 characters in body
|
Jul 3, 2016 at 2:20 | history | edited | ttnphns | CC BY-SA 3.0 |
added 63 characters in body
|
Jul 3, 2016 at 2:05 | history | edited | ttnphns | CC BY-SA 3.0 |
added 3475 characters in body
|
Jul 3, 2016 at 0:51 | history | edited | ttnphns | CC BY-SA 3.0 |
deleted 7 characters in body
|
Jul 3, 2016 at 0:33 | history | edited | ttnphns | CC BY-SA 3.0 |
added 84 characters in body
|
Jul 3, 2016 at 0:22 | history | answered | ttnphns | CC BY-SA 3.0 |