Reputation: 11
I am comparing SAS
commands with that of R
. Consider I want to assess the effect of one exposure (like CAT
where 1 equals high
and 0 equals low
) and one cofounding variable
(like cholesterol
leve
, CHL
) on a disease variable (like CHD
). In SAS
to get a numerical value for the odds ratio, consider, for example, the specific values CHL
equal to 220 and HPT
equal to 1 when the model contains interaction terms like (CC = CAT*CHL
) the command is:
PROC GENMOD data=l2 DESCENDING;
MODEL CHD=CAT CHL CC/LINK=LOGIT DIST=BINOMIAL;
ESTIMATE CAT 1 CC 220 /EXP;
RUN;
I just want to find such a command in R. Is there any cods for that in R?
Upvotes: 1
Views: 1917
Reputation: 263342
Copying my earlier comment as an answer: I believe the OP is asking about a data situation with 4 columns and would need
mdl <- glm(CHD ~ CAT + CHOL + CC, data=df, "binomial")
to follow your advice. Better however would be to not separately compute the interaction term but use the formula mechanism to represent interactions with the "*" operator:
mdl <- glm(CHD ~ CAT * CHOL , data=df, "binomial")
which will give you both main-effects and interaction coefficients. It will also work better with the predict method, where you won't be tripped up by possibly entering an interactions term that doesn't match the main effects. I'm not sure what the /EXP option is producing in SAS but I'm guessing it might be returning the odds ratio. This gives predicted probabilities:
predict(mdl, data.frame(CHL=220, HPT=1), type= "response")
I don't think a single value for each covariate can produce an odds ratio, unless you implicitly assume a baseline of the mean of the covariates. You could concievably get useful information with:
exp( diff( predict(mdl, data.frame(CHL=c(220, mean(df$CHL) ) , HPT= c(1,0) ) ) ) )
This is intended to be (although it is untested in the absence of data and there might need to be some further arithmetic) the odds ratio comparing a person with CHL=220 and Hypertension with a person with no hypertension and whatever the mean of the cohorts cholesterol might be.
The UCLA Biostatisics page are good for learning this and you might be able to pick up some data examples to present at this page:
There are also resources for persons wanting to use prior knowledge of SAS:
http://r4stats.com/2012/06/13/why-r-is-hard-to-learn/
http://www.revolutionanalytics.com/news-events/free-webinars/2011/intro-to-r-for-sas-spss/
Free PDF that was later expanded into full book:
Upvotes: 1