Home  /  Stata News  /  Vol 31 No 1 (2016 quarter 1)  /  Effects in multilevel models using contrasts ## How do you compare? Examining effects in multilevel models using contrasts

If your statistical background includes ANOVA modeling and analysis of designed experiments, you are likely already familiar with contrasts. If not, contrasts may be a new concept, or perhaps you use certain types of contrasts but call them by different names. So before we jump to contrasts with multilevel models, let’s look at a few types of tests you can perform using Stata’s contrast command.

### Making comparisons using contrast

As with the example data in Keppel and Wickens (2004, chapter 13), let’s suppose we have fifth-grade students who are asked to learn a set of vocabulary words and are tested on them a week later. We are interested in comparing three teaching methods and four types of words. When teaching, the teacher provides no verbal feedback, positive feedback, or negative feedback. The four word lists are categorized by the frequency with which the words are used, where freq=1 corresponds to words least frequently used and freq=4 corresponds to words most frequently used.

Let's start by regressing vocabulary test score on the frequency categories. The coefficients in the regression output are one type of contrast—comparisons with the base level of least frequently used words. Mean test scores for the third and fourth frequency levels are statistically greater than those for the first (base) level. However, it would be nice to know whether differences exist for each increase in word frequency level. Are there differences between the second and third levels? Between the third and fourth levels? We can use the ar. contrast operator to make these “reverse adjacent” comparisons. Here we find that the change from level 2 to level 3 is the only one with a statistically significant difference in estimated mean scores.

We can see this large jump when we plot the estimated means using margins freq followed by the marginsplot command. Now, let’s fit a model allowing for an interaction between frequency and type of feedback by typing

. regress score freq##feedback
(output omitted)


We can use contrast to obtain tests of the main and interaction effects. We have statistical evidence for an interaction effect, but at this point, we can’t say much about where differences exist. A plot allows us to visualize the interaction. We can test specific hypotheses about the relationship between word frequency and teaching method. For example, when positive feedback is given, feedback=2, does word frequency have an effect? There is no statistically significant difference in the four means for this teaching method.

We can also test whether there is an effect of teaching method at individual frequency levels. For the first and second frequency levels (but not the third and fourth), there is a statistical difference in the estimated means for the different teaching methods.

Is there really any interaction if we consider only the change from the first to second frequency level? We do not find evidence of an interaction effect at these frequency levels.

### Multilevel models

We can easily apply the same types of contrasts when fitting multilevel models. For example, suppose that each student was tested multiple times. We can fit a random-effects model allowing for student-level variation in the intercepts and perform the same types of contrasts. To do this, we could type

. mixed score feedback##freq || id:
. contrast feedback##freq
. contrast feedback@frequency


However, acknowledging that we have repeated measurements on students and a fairly small sample size, we request that both mixed and contrast report small-sample tests using a repeated-measures ANOVA method for computing denominator degrees of freedom. As before, we find an interaction between the type of feedback and the frequency of word use. Using the contrast command below, we also find that the simple effects of feedback exist only for the lower-frequency words. ### And beyond

We have considered fairly traditional experimental design applications. However, the use of contrast is not so limited. contrast can be used after fitting most models in Stata. Options are available for working with unequal group sizes and for adjusting results for multiple comparisons. Find details on these and many other extensions in [R] contrast.

—Kristin MacDonald
Asst. Director of Statistical Services

### Reference

Keppel, G., and T. D. Wickens. 2004. Design and Analysis: A Researcher’s Handbook. 4th ed. Upper Saddle River, NJ: Pearson.
{"ft_lang_label":"__label__en","ft_lang_prob":0.91600627,"math_prob":0.78915834,"size":4522,"snap":"2023-14-2023-23","text_gpt3_token_len":893,"char_repetition_ratio":0.13523683,"word_repetition_ratio":0.0,"special_character_ratio":0.19172932,"punctuation_ratio":0.104878046,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96975565,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"im_url_duplicate_count":[null,null,null,4,null,4,null,4,null,4,null,4,null,4,null,4,null,4,null,4,null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-28T03:13:07Z\",\"WARC-Record-ID\":\"<urn:uuid:5e2f6bcc-bdbb-4409-baf4-939eab99911f>\",\"Content-Length\":\"63684\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e03e9f00-f8c3-406b-8524-3ce82ebef60c>\",\"WARC-Concurrent-To\":\"<urn:uuid:aba09f12-92f5-4d58-9f3e-d7f84a46287c>\",\"WARC-IP-Address\":\"66.76.6.5\",\"WARC-Target-URI\":\"https://www.stata.com/stata-news/news31-1/multilevel-models-using-contrasts/\",\"WARC-Payload-Digest\":\"sha1:Q7OLVKLOSZ5HA3SKIRKQSDGX7TFFCONV\",\"WARC-Block-Digest\":\"sha1:LKNADRSWJGPSPDMFS2HDJGR66IXB3YUE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224643462.13_warc_CC-MAIN-20230528015553-20230528045553-00732.warc.gz\"}"}