DATA Step, Macro, Functions and more

Setting up Complicated Contrasts

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Setting up Complicated Contrasts

I'm running an experiment where I'm interested in climate, time of year, and parasitism levels on population densities of an insect.

I sample 3 climate types 26 times over the course of a year. Climate A has 5 sites, and Climates B and C each have 2 sites for 9 sites total.

 

My code looks like this:

 

proc glimmix data=final ;

class site climate interval;

model totalfin = interval climate previous_para / dist=poi link=log solution;

random interval / subject= site(climate) residual;

run;

 

Model suggests there is a highly significant effects of sample interval, parasitism, but not climate (p=0.11). Looking at the raw data it appears that climate effects exists, but they vary by season and this is washing out the effects. I want to compare climate effects within each season so I assign each interval to a season. I want to use contrasts rather than grouping 26 intervals into 4 groups to maintain my df. I can look at seasonal differences on densities via these contrasts, but I'm having trouble finding a way to code the contrasts so that I can look at site(climate) differences on densities within these seasons.

 

contrast "Spring vs. Summer" interval -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 -1 -1 ;

contrast "Spring vs. Fall" interval  0 0 0 0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 ;

contrast "Spring vs. Winter" interval 0 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 0 0 ;

contrast "Summer vs. Fall" interval  1 1 1 1 1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 ;

contrast "Summer vs. Winter" interval 1 1 1 1 1 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1;

contrast "Fall vs. Winter" interval 0 0 0 0 0 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0;

 

If it comes down to it I can just assign each interval to a categorical season, but I would like to avoid this if possible.

 

Thanks!


Accepted Solutions
Solution
‎01-25-2018 09:44 PM
Respected Advisor
Posts: 2,647

Re: Setting up Complicated Contrasts

The model should be

 

model totalfin = season interval(season) climate season*climate previous_para ... ;

 

Then you can compute lsmeans for season*climate

--
Paige Miller

View solution in original post


All Replies
Respected Advisor
Posts: 2,647

Re: Setting up Complicated Contrasts

You might want to put season into your model, and have interval nested within season.

 

Then you can compute least squares means (LSMEANS) for site and season, instead of writing out all possible contrasts of site and season.

 

--
Paige Miller
Respected Advisor
Posts: 2,647

Re: Setting up Complicated Contrasts

Posted in reply to PaigeMiller

Adding: It seems to me that creating contrasts are useful in the case where the coefficients in the contrast are irregular in the sense that you are not just comparing level X to level Y; for example if you want to test if summer is equal to the average of spring and fall, you'd need a contrast for that. If you're just comparing summer to fall, the LSMEANS ought to do that with minimal effort on your part.

--
Paige Miller
Occasional Contributor
Posts: 13

Re: Setting up Complicated Contrasts

Posted in reply to PaigeMiller

I agree with your point about the use of contrasts.

Regarding including season in the model,I can do that but all it does again is just compare differences in densities between intervals(season). I need to look at the lsmeans of climate within a specific season (e.g. coastal vs. inland within spring, summer, fall and winter).

 

proc glimmix data=final;

class site climate interval season;

model totalfin = interval(season) climate  previous_para / dist=poi link=log solution;

random interval(season) / subject= site(climate) residual;

lsmeans climate / cl pdiff plot=meanplot;

lsmeans interval(season) / cl pdiff plot=meanplot;

 

This model doesn't let me do interval(season)*climate in the model statement. I might have to just end up getting rid of interval after all and do lmeans of season*climate

Solution
‎01-25-2018 09:44 PM
Respected Advisor
Posts: 2,647

Re: Setting up Complicated Contrasts

The model should be

 

model totalfin = season interval(season) climate season*climate previous_para ... ;

 

Then you can compute lsmeans for season*climate

--
Paige Miller
Occasional Contributor
Posts: 13

Re: Setting up Complicated Contrasts

Posted in reply to PaigeMiller

Thank you!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 118 views
  • 0 likes
  • 2 in conversation