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!
The model should be
model totalfin = season interval(season) climate season*climate previous_para ... ;
Then you can compute lsmeans for season*climate
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.
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.
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
The model should be
model totalfin = season interval(season) climate season*climate previous_para ... ;
Then you can compute lsmeans for season*climate
Thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: