1
$\begingroup$

I tried running a few polynomial contrasts in SAS for a continuous time variable for linear, quadratic, cubic and quartic contrasts and the F values for each were the same. When I used categorical time, they were different. Additionally, I've never been super clear on how to come up with the contrast values - I know they need to sum to 0, but it always just seems like they're somewhat arbitrary.

Continuous:

proc mixed data=health;
class id;
model y = time group time*group;
repeated / subject=id type=UN;
contrast 'linear' time -2 -1 0 1 2;
contrast 'quadratic' time 2 -1 -2 -1 2;
contrast 'cubic' time -1 2 0 -2 1;
contrast 'quartic' time 1 -4 6 -4 1;
run;

Categorical:

proc mixed data=health;
class id time group;
model y = time group time*group;
repeated / subject=id type=UN;
contrast 'linear' time -2 -1 0 1 2;
contrast 'quadratic' time 2 -1 -2 -1 2;
contrast 'cubic' time -1 2 0 -2 1;
contrast 'quartic' time 1 -4 6 -4 1;
run;
$\endgroup$

1 Answer 1

0
$\begingroup$

Short answer is no, at least for time. Simply specify a quadratic term (time^2) instead of a contrast, and successively add ^3 and ^4. While I am aware that you prefer SAS, R has built-in functions to specify many types of contrast coefficients and corresponding interactions.

$\endgroup$
3
  • 1
    $\begingroup$ Thanks! That make sense. I actually prefer R, but have only ever done contrasts in SAS and was just avoiding learning how to do it in R. $\endgroup$
    – vzste
    Commented Sep 28, 2018 at 19:32
  • $\begingroup$ No problem. It is actually straightforward and there are a few helper functions beyond specifying your own with n-1 vectors grouped with cbind. The "ordered" class has built in contrasts: var <- ordered(var). Get them with contrasts(var), which you can also use to update the contrasts. Default of ordered categorical is contr.poly, i.e. polynomial (quadratic, cubic and so on until n - 1) and there is some kind of weighting. You can specify helmert: constrasts(var) <- contr.helmert(n) or contr.SAS or contr.sum $\endgroup$ Commented Sep 28, 2018 at 20:06
  • $\begingroup$ Another shortcut for quadratic and cubic terms for continuous variables is to insert poly(var, 3) in your formula, which simplified how many interaction terms you have to specify! You are welcome, as so are upvotes ; ) $\endgroup$ Commented Sep 28, 2018 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.