# Tag Info

### Polynomial contrasts for regression

Just to recap (and in case the OP hyperlinks fail in the future), we are looking at a dataset hsb2 as such: ...
• 26.3k

### What is a contrast matrix?

In their nice answer, @Gus_est, undertook a mathematical explanation of the essence of the contrast coefficient matrix L (notated there a C). $\bf Lb=k$ is the fundamental formula for testing ...
• 57.6k

I'll use lower-case letters for vectors and upper-case letters for matrices. In case of a linear model of the form: $$\mathbf{y}=\mathbf{X} \boldsymbol{\beta} + \boldsymbol{\varepsilon}$$ where $\bf{... • 646 12 votes ### What is a contrast matrix? "Contrast matrix" is not a standard term in the statistical literature. It can have [at least] two related by distinct meanings: A matrix specifying a particular null hypothesis in an ANOVA ... • 105k 12 votes Accepted ### Statistics Help: Difference between Differences? It's a little risky to answer without better understanding your use case, but assuming iid nested data within columns and testing the hypotheses:$$H_0: \mu_A - \mu_B = \mu_C - \mu_D, \\ H_1: \mu_A - ... • 5,387 11 votes Accepted ### When is deviation coding useful? @llewmills: This week, I encountered a project where the deviation coding you inquired about came in handy, so I thought I would share here what I learned on this topic. First, I think it will be ... • 20.3k 10 votes ### Specify contrasts for lme with interactions If you look at the summary of your fixed effects portion of the model, you can label each row as follows: ... • 20.3k 9 votes Accepted ### What are average comparisons in the marginaleffects package? Question 1 Yes, you have correctly described what avg_comparisons() does by default. Question 2 This is an example of “G-Computation”, which is a popular strategy ... • 310 8 votes ### Interpretation of betas when there are multiple categorical variables Actually as you correctly pointed out, in the case of a single categorical variable (with potentially more than 2 levels),$\hat{\beta}_0$is indeed the mean of the reference and the other$\hat\beta$... • 81 8 votes ### Multivariable Logistic in R, without the "reference" level in a categorical predictor To make Adria's comment crystal clear: R uses a so called ANOVA (sum) contrast when there's a polytomous factor variable with multiple levels in a linear model and the intercept is suppressed. This ... • 62.7k 7 votes Accepted ### Computation of polynomial contrast variables As a segue to my prior post on this topic I want to share some tentative (albeit incomplete) exploration of the functions behind the linear algebra and related R functions. This is supposed to be a ... • 26.3k 7 votes ### Post hoc test after ANOVA with repeated measures using R If you want to stick with the aov() function you can use the emmeans package which can handle ... • 5,970 6 votes ### How does one do a Type-III SS ANOVA in R with contrast codes? The fact that type III tests are used in your place of work is the weakest of reasons to keep using them. SAS has done major damage to statistics in this regard. Bill Venables' exegesis, referenced ... • 92.3k 6 votes ### Contrasts in ANOVA in R Testing contrasts of factorial variables is notoriously difficult in R. Most of the things that go on beneath the surface in friendlier programs like SPSS must be spelled out specifically in R. This ... • 2,151 6 votes ### Calculating ratios for contrasts after lmer model It is doable! You have to do it in stages, though. Using the warpbreaks data to illustrate, I'll do such comparisons of wool at ... • 20.3k 6 votes Accepted ### How to interpret sum contrast in regression (LMM)? contr.sum makes sure all the contrasts sum to zero so that the "intercept" term is the grand mean. The effects are summarized with coefficients representing the ... • 62.7k 6 votes Accepted ### Is it ok to define the contrasts after building the model? Yes, you can first fit the model using the default treatment contrasts in R, and then you can use the emmeans package to perform the comparisons of interest, also correcting for multiple testing. • 21.1k 6 votes Accepted ### In emmeans package, how to exclude certain uninteresting contrasts from pairwise comparisons Question 1 As is documented, P-value correction is done by default separately for each by group. In this case, each by group ... • 20.3k 6 votes Accepted ### Why Helmert coding in R divides subsequent differences It's been that way since before R existed, so you can be reasonably confident it isn't a bug. For an authoritative source, the definition is given in chapter 2 of Statistical Models in S, by Chambers &... • 38.8k 6 votes Accepted ### Controlling for baseline in pre-post between design: using$\Delta(T_2-T_1)$or controlling for T1 in the regression model (or both)? The options under (d) are wrong, as a change score is associated with the baseline value. See this page, for example. Otherwise, it depends on what you mean by "taking into account the baseline ... • 92.5k 6 votes ### How to choose reference category of predictors in logistic regression? My aim is to identify if education has an effect on the outcome. If that is the case, then you should do a likelihood ratio test between a model with education and a model without it. That is ... • 33.4k 5 votes ### How do I approach a linear mixed effects model with a 2-level group? I get an output that only lists group A but not group B for some reason. Presumably, group B is the reference level, and since R uses contrast coding by default, B will be included in the intercept ... • 60.9k 5 votes ### Is it preferable to subset data to test specific hypotheses or specify a full model and run contrasts? This may be an example showing why subsets of the same data give different results and why the assumption of equal variance across covariates matters. Here, group A has much higher dispersion compared ... • 4,260 5 votes ### Post hoc contrasts when only certain contrasts make sense In what follows I assume that you want to control the FWER (in the strong sense). In general, if you want to test a fixed number of arbitrary planned contrasts (in your case: treatment A vs. control A,... • 5,970 5 votes Accepted ### How to interpret categorical variable in logistic regression with contrast coding It's best to choose variable coding on arbitrary convenience, then to get any contrast of interest by subtracting predicted log odds (and possibly anti-logging the difference to get an odds ratio). ... • 92.3k 4 votes Accepted ### Defining a contrast matrix to test the null hypothesis$H_0: \beta_5=\beta_6=0\$

The strict traditional definition of "contrasts" requiring row sums of 0 (e.g., in Wikipedia) seems to have been relaxed in practice. See, for example this page on contrast coding in R (note that R ...
• 92.5k

### Is there a consensus on adjusting alpha for multiple contrasts if the main effect is significant?

The idea that only non-orthogonal comparisons require adjustment is a myth. See section 6.1 of Frane (2015): http://jrp.icaap.org/index.php/jrp/article/view/514/417 In general, computing several ...
• 311
Accepted

### Is the Scheffé test of contrasts the "best-case" for post-hoc tests?

Firstly, there are many tests and each one has its good and bad sides over another test. Some of the most basic tests are Tukey's, Bonferroni's and Scheffés, so we can compare and contrast these to ...
• 462
Accepted

### Setting custom contrasts in R

Interesting problem! The issue is that you're basically re-coding Loc into a variable with three levels (corresponding to your three levels of ...
• 2,185