This is an introduction to contrast analysis for estimating the linear trend among condition means with R and SPSS . The tutorial focuses on obtaining point and confidence intervals. The contents of this introduction is based on Maxwell, Delaney, and Kelley (2017) and Rosenthal, Rosnow, and Rubin (2000). I have taken the (invented) data from Haans (2018). The estimation perspective to statistical analysis is aimed at obtaining point and interval estimates of effect sizes. Here, I will use the frequentist perspective of obtaining a point estimate and a 95% Confidence Interval of the relevant effect size. For linear trend analysis, the relevant effect size is the slope coefficient of the linear trend, so, the purpose of the analysis is to estimate the value of the slope and the 95% confidence interval of the estimate. We will use contrast analysis to obtain the relevant data.

[Note: A pdf-file that differs only slightly from this blogpost can be found on my Researchgate page: here; I suggest Haans (2018) for an easy to follow introduction to contrast analysis, which should really help understanding what is being said below].

The references cited above are clear about how to construct contrast coefficients (lambda coefficients) for linear trends (and non-linear trends for that matter) that can be used to perform a significance test for the null-hypothesis that the slope equals zero. Maxwell, Delaney, and Kelley (2017) describe how to obtain a confidence interval for the slope and make clear that to obtain interpretable results from the software we use, we should consider how the linear trend contrast values are scaled. That is, standard software (like SPSS) gives us a point estimate and a confidence interval for the contrast estimate, but depending on how the coefficients are scaled, these estimates are not necessarily interpretable in terms of the slope of the linear trend, as I will make clear

momentarily.

So our goal of the data-analysis is to obtain a point and interval estimate of the slope of the linear trend and the purpose of this contribution is to show how to obtain output that is interpretable as such.

## A Linear Trend

Figure 1: Negative Linear Trend with slope \beta_1 = -1.0 |

## Estimating the slope

The groups means of all of the four rows are \boldsymbol{\bar{Y}} = [7, 7, 6, 2]. The lambda weights are \boldsymbol{\Lambda} = [-1.5, -0.5, 0.5, 1.5]. The value of the contrast estimate equals \hat{\psi}_{linear} = -8, the sum of the squared lambda weights equals \sum_{j=1}^{k}\lambda_{j}^{2} = 5, so the estimated slope equals -1.6. The equation for the linear trend is therefore \hat{\mu}_j = 9.5 – 1.6X_j. Figure 2 displays the obtained means and the estimated means based on the linear trend.

Figure 2: Obtained group means and estimated group means (unfilled dots) based on the linear trend. |

## Obtaining the slope estimate with SPSS

UNIANOVA score BY row /METHOD=SSTYPE(3) /INTERCEPT=INCLUDE /CRITERIA=ALPHA(0.05) /LMATRIX = "Negative linear trend?" row -1.5 -0.5 0.5 1.5 intercept 0 /DESIGN=row.

Figure 3: SPSS Output Linear Trend Contrast |

UNIANOVA score BY row /METHOD=SSTYPE(3) /INTERCEPT=INCLUDE /CRITERIA=ALPHA(0.05) /LMATRIX = "Negative linear trend?" row -1.5/5 -0.5/5 0.5/5 1.5/5 intercept 0 /DESIGN=row.

Using the syntax above leads to the results presented in Figure 4.

Figure 4: SPSS Output Slope Estimate with adjusted contrast weights |

## Obtaining the estimation results with R

# load the dataset load('~\betweenData.RData') # load the functions of the emmeans package library(emmeans) # set options for the emmeans package to get # only confidence intervals set infer=c(TRUE, TRUE)for both # CI and p-value emm_options(contrast = list(infer=c(TRUE, FALSE))) # specify the contrast (note divide # by sum of squared contrast weights) myContrast = c(-1.5, -0.5, 0.5, 1.5)/ 5 # fit the model (this assumes the data are # available in the workspace) theMod = lm(examscore ~ location) # get expected marginal means theMeans = emmeans(theMod, "location") contrast(theMeans, list("Slope"=myContrast))

## contrast estimate SE df lower.CL upper.CL ## Slope -1.6 0.3162278 16 -2.270373 -0.9296271 ## ## Confidence level used: 0.95