- Thread starter Disvengeance
- Start date

So you are trying to make a graph that will look like the line part on the figure of your overlay post except the ci will be zero at the reference value, correct. It wont be that graph but stylistically it will resemble it. Are you planning on using SAS? I have wanted to do this as well.

There is probably an easier way but you may be able to get them by just running a bunch of oddsratio statements after your model statement. Do you conduct medical research? I like your questions and plus you are using SAS. I have done something like this using proc nlmixed (sp?) once but I used estimate statement and a bunch of connected points with whiskers.

My area of research is epidemiology and I pretty much use SAS (though I've been trying to slowly learn R). I'm not necessarily at the point where I'd like to try making the figure I mentioned in the other post, I just wanted to start thinking about that figure in advance because I thought it might be useful to play around with at some point.

For this problem I'm working with a continuous predictor so I created plots of the predicted logits by the predictor, but I thought a plot of the odds ratio would be nice. The main issue I've had with tackling this problem is that for this current project I'm using complex survey data and so I have to use proc surveylogistic, which I've found doesn't have quite the same level of options as other SAS procedures. In this case I'd like to use a level of the covariate as the reference (e.g. the mean or the minimum). I was under the impression that the estimate, contrast, and lsmeans/lsmestiamte statements only allow class variables, but I may be wrong about that.

My initial approach was to use the lsmeans statement to calculate predicted "adjusted" logits (and their standard errors) for the entire range of the continuous covariate, and then calculate the odds ratios from those, but I got stumped when it came to getting the confidence interval of these odds ratios. I'm curious whether there might be an easier/better approach to getting the same result. I'd thought to just use a data step to manually calculate the standard error of the odds ratio using the standard errors of the logit, but I don't know how to perform this calculation and haven't been able to find a reference.

Yeah, unless there is a nice SAS User Group Paper out there, you can definitely do this using Proc nlmixed. In particular the estimate statement. You would need to write one for each ORs of interest. Then take the estimates with their confidence intervals and input that data into a proc sgplot with the band option for the nice blue semi-transparent CIs.

Let me know if you want to work on writing the actual code. Perhaps we can use one of the SAS.help datasets. I usually play around with Heart (the Framingham dataset).

Hmm, probably could still do it, but it may be quite a bit of work (probably too much, unless you are pretty good at linear algebra in the face of clusters). Have you run a logistic model with these data yet? Will it be multi-level?

I've run two logistic regression models using proc surveylogistic, and calculated the predicted logits for levels of the covariate. The outcome is binary and the covariate is continuous (for one model the covariate has about 400 possible values and the other about 1200). This is why I was hoping to use the standard error of the logit to get the confidence interval for the OR, but I haven't had any luck finding any equation or reference (maybe it's too obvious?)

So you are obtaining results from two models and are trying to pool them? Are both models using the same dataset? Your last 2 posts really confused my interpretation of what you are trying to do.

Do you have to use proc surveylogistic, are you controlling for other variables or using weights in either of the models. Perhaps posting the code may help me get what you are doing.

I'm running proc suryvelogistic with strata,clusters, and weights. I'm running both adjusted and unadjusted models using a quadratic truncated power function spline with 3 knots, and using a do loop and the lsmeans statement to calculate the logit at the mean level of the covariates. I wanted to then use the minimum of the predictor as the reference level to calculate odds ratios from these logits (which I've done), but all I have to work with from lsmeans are the standard errors of the logits, so I was trying to figure out a way to get the standard error of the odds ratio from these logit standard errors. Here is the code I am using:

Code:

```
%macro macro;
%let k=0.01;
%do %until (&k=8);
ods select none;
proc surveylogistic data=data;
strata strata;cluster cluster;weight weight;domain domain;class var1(ref='0') / param=glm;
effect spl = spline( var2 / degree=2 basis=tpf details knotmethod=list(0.5 1 1.5));
model y(event='1')=spl var1 spl*var1;
lsmeans var1 / at var2=(&k) cl exp;
ods output LSmeans=udat;
run;
data udat(where=(domain="var2=1"));set udat;run;
%if &k=0.01 %then %do;
data adju;set udat;run;
%end;
%else %do;
data adju;set adju udat;run;
%end;
%let k=%sysevalf(&k+0.01);
%end;
%mend;
%macro;
```

Yeah, that is a beastly model, glad I don't mess around with nation survey data. Not familiar with proc surveylogistic, can you use estimate statements?

If so, you may be able to mess around with writing the odds in them along with their division to get the ORs. Not sure how this works out in a model with clusters, so I would first write an estimate statement for something you can calculate the odds for and make sure it is correct -then evolve it.

If I can use the estimate statement that'd be much easier, I was just unsure of how to go about it since I want to use compare one level of the continuous covariate (var2) with another level (var2) to get the odds ratio. Is this possible using the estimate statement?

Yes, I beleive it may be possible. However your macro may complicate the process. The following is just an idea but it would be something like this. I am sure there is a cleaner way to write it and you may have to type in the values for the intercept and other coefficients, but the following may get the odds ratio of a value of 2 over 1 for the continuous variabe (x1).

Code:

```
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]
estimate
(([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+exp(-(b0 + b1*[/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]2[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])))) / ([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]-([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+exp(-(b0 + b1*[/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]2[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])))))) /
(([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+exp(-(b0 + b1*[/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])))) / ([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]-([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/([/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+exp(-(b0 + b1*[/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080][FONT=Courier New][SIZE=2][COLOR=#008080]1[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))))));
[/SIZE][/FONT][/SIZE][/FONT]
```

I think I managed to get the same result using a contrast statement, which was fairly easy to incorporate into the macro:

Code:

```
contrast 'OR1' var1 -1 -1 spl &k var1*spl -&k -&k / e estimate=exp;
contrast 'OR2' var1 1 0 spl &k var1*spl &k 0 / e estimate=exp;
contrast 'OR3' var1 0 1 spl &k var1*spl 0 &k / e estimate=exp;
```

Last edited:

Geat. Some day I may bug you for spline help. I have not really used them yet.

If the above code works you can then possibly output the values and use them in something like this:

http://support.sas.com/documentation/cdl/en/grstatproc/62603/HTML/default/viewer.htm#a003155743.htm

If you get everything to work, I would be interested in seeing your final product and code.