How to edit this forest plot code to accommodate a non-log scale?

j4ne

New Member
#1
I want to create a version of the forest plot here: http://support.sas.com/kb/42/867.html

Unfortunately, the scale isn't useful for the values I want to include (Hedge's g instead of odds ratio), which range from ~-2 to +8. If I include a negative number in the datalines, the whole plot becomes unreadable.

Is it possible to rejig the code to accommodate the scale? I'm not overly familiar with SAS, so my coding skills are fairly limited.

Part of the code that I've tried editing to no avail:
proc sgplot data=forest4 noautolegend;
scatter y=study2value x=oddsratio / markerattrs=graphdata2(symbol=diamondfilled size=10);
scatter y=studyvalue x=oddsratio / xerrorupper=ucl2 xerrorlower=lcl2 markerattrs=graphdata1(symbol=squarefilled size=0);
vector x=x2 y=studyvalue / xorigin=x1 yorigin=studyvalue lineattrs=graphdata1(thickness=8) noarrowheads;
scatter y=studyvalue x=or / markerchar=oddsratio x2axis;
scatter y=studyvalue x=lcl / markerchar=lowercl x2axis;
scatter y=studyvalue x=ucl / markerchar=uppercl x2axis;
scatter y=studyvalue x=wt / markerchar=weight x2axis;
refline 1 100 / axis=x;
refline 0.1 10
/ axis=x lineattrs=(pattern=shortdash) transparency=0.5;
inset ' Favors Treatment' / position=bottomleft;
inset 'Favors Placebo' / position=bottom;
xaxis type=log offsetmin=0 offsetmax=0.35 min=0.01 max=100 minor display=(nolabel) ;
x2axis offsetmin=0.7 display=(noticks nolabel);
yaxis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.05 values=(1 to &count by 1);
run;
Many thanks for any help
 
Last edited:

hlsmith

Not a robit
#2
Well have you played around with the part that says, "type=log"?


P.S., If you get the code working - it would be nice if you could post it. I am not planning a continuous outcome meta-analysis, but I can't rule out that the code may be of interest in the distant future.
 

j4ne

New Member
#3
I've fixed the scale, but now have a new problem - the size of the boxes on the graph doesn't correspond to the pre-computed weights I've listed. Instead, the code is incorrectly calculating new weights/box sizes based on the odds ratio. See here -

--e.g. 3% has two different sizes, 14% is smaller than 4%, etc

I've tried modifying the code to avoid that, but either:

1. It calculates the correct box size, but not anchored in the correct place:


2. It anchors the box in the correct place, but makes all the boxes a uniform size:


Any ideas??? :confused:

Here's some of the code I've been using, with the 'weight' section highlighted - full code is here:

/* Apply the format to the study values and remove Overall from Study column. */
/* Compute the width of the box proportional to weight in log scale. */
data forest4;
format studyvalue study2value study.;
drop fmtname type label start end hlo pct;
set forest3 (where=(studyvalue > 0)) nobs=nobs;
if studyvalue=1 then studyvalue=.;
/* Compute marker width */
x1=oddsratio / (10 ** (weight/2));
x2=oddsratio * (10 ** (weight/2));

/* Compute top and bottom offsets */
if _n_ = nobs then do;
pct=0.75/nobs;
call symputx("pct", pct);
call symputx("pct2", 2*pct);
call symputx("count", nobs);
end;
run;

ods listing close;
ods html image_dpi=100 path="." file='sgplotforest.html';
ods graphics / reset width=600px height=400px imagename="Forest_Plot_Vector" imagefmt=gif;

title "Meta-analysis ";
title2 h=8pt 'Hedges G and 95% CI';

proc sgplot data=forest4 noautolegend;
scatter y=study2value x=oddsratio / markerattrs=graphdata2(symbol=diamondfilled size=10);
scatter y=studyvalue x=oddsratio / xerrorupper=ucl2 xerrorlower=lcl2 markerattrs=graphdata1(symbol=squarefilled size=0);
vector x=x2 y=studyvalue / xorigin=x1 yorigin=studyvalue lineattrs=graphdata1(thickness=8) noarrowheads;
scatter y=studyvalue x=or / markerchar=oddsratio x2axis;
scatter y=studyvalue x=lcl / markerchar=lowercl x2axis;
scatter y=studyvalue x=ucl / markerchar=uppercl x2axis;
scatter y=studyvalue x=wt / markerchar=weight x2axis;
refline 0 / axis=x lineattrs=(pattern=shortdash) transparency=0.5;
inset ' Favors Sham Treatment' / position=bottomleft;
inset 'Favors Active Treatment' / position=bottom;
xaxis offsetmin=0 offsetmax=0.35 min=-2 max=2 minor display=(nolabel) ;
x2axis offsetmin=0.7 display=(noticks nolabel);
yaxis display=(noticks nolabel) offsetmin=0.1 offsetmax=0.05 values=(1 to &count by 1);
run;

ods html close;
ods listing;
 

hlsmith

Not a robit
#4
It is a little hard to help without the data . So you have your Hedge's Gs in the model as the variable call Oddsratio? What are you using for weights. I am guessing the weights are suppose to be the inverses of the studies variance. What are you using?