50 votes

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: ...
Antoni Parellada's user avatar
50 votes

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 ...
ttnphns's user avatar
  • 57.6k
27 votes

What is a contrast matrix?

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{...
ogustavo's user avatar
  • 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 ...
amoeba's user avatar
  • 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 - ...
Ben Ogorek's user avatar
  • 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 ...
Isabella Ghement's user avatar
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: ...
Isabella Ghement's user avatar
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 ...
Vincent's user avatar
  • 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$...
G.L.'s user avatar
  • 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 ...
AdamO's user avatar
  • 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 ...
Antoni Parellada's user avatar
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 ...
statmerkur's user avatar
  • 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 ...
Frank Harrell's user avatar
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 ...
llewmills's user avatar
  • 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 ...
Russ Lenth's user avatar
  • 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 ...
AdamO's user avatar
  • 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.
Dimitris Rizopoulos's user avatar
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 ...
Russ Lenth's user avatar
  • 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 &...
Thomas Lumley's user avatar
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 ...
EdM's user avatar
  • 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 ...
Noah's user avatar
  • 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 ...
Robert Long's user avatar
  • 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 ...
dariober's user avatar
  • 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,...
statmerkur's user avatar
  • 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). ...
Frank Harrell's user avatar
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 ...
EdM's user avatar
  • 92.5k
4 votes

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 ...
Bonferroni's user avatar
4 votes
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 ...
Travis's user avatar
  • 462
4 votes
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 ...
Rose Hartman's user avatar
  • 2,185
4 votes

to correct or not correct?

You need to correct for multiple hypothesis because you did four experiments: when you compare those results, you are selecting only the best ones, affecting the meaning of those p-values. In fact, ...
AndreaL's user avatar
  • 521

Only top scored, non community-wiki answers of a minimum length are eligible