Calculating the standard error of an odds ratio from the standard errors of 2 logits

Disvengeance

New Member
I've just completed a logistic regression model with a continuous covariate, and calculated the logit and standard errors using SAS for creating a plot of the logit vs. the predictor. I'd like to use this data to calculate and plot the odds ratio and 95% confidence interval using an arbitrary level of the predictor as the reference for calculating the odds ratio; however, I don't know how to go about calculating the standard error of an odds ratio from the standard errors of the two logits used to calculate the odds ratio. Does this procedure make sense and can anyone provide a reference or offer some suggestions?

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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.

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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.

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

I'm currently looking into proc nlmixed, which you mentioned. I think this might provide an easier way of getting what I would like.

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

Will play around with some code in the morning and post.

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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).

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

I am definitely interested in this. My only concern is whether proc nlmixed provide appropriate estimates of the standard errors, because I will be using it with survey data.

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

Why do you think your survey data is different from other data sources? Is it weighted or manipulated in some way?

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

Yes, the data is from NHANES, which is a complex, multistage, probability sampling design. So analyses need to take into account strata, clusters, and weights.

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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?

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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?)

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

Would it be correct to calculate the SE of the OR from the SE of the logits as

$$SE_{ln(OR)}=\sqrt{SE_{logit1}^2+SE_{logit2}^2}$$

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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.

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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;
%end;
%else %do;
%end;
%let k=%sysevalf(&k+0.01);
%end;
%mend;
%macro;

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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.

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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?

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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]

hlsmith

Omega Contributor
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

Not pretty, but this is the approach I was thinking of. Guessing you can drop the exp part if you think about what is in the output.

P.S., it would also kick out the SE and/or 95% CI.

Disvengeance

New Member
Re: Calculating the standard error of an odds ratio from the standard errors of 2 log

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;
I would have used the estimate statement but all of the examples I could find for splines used positional syntax and I'd need more time to wrap my head around that.

Last edited: