Tags:
create new tag
, view all tags, tagging instructions
Return to Stat Graph Home

Title: Forest Plot of Hazard Ratios by Patient Subgroups

ClinAEStatGraphicsForm edit

Image
Click on image to enlarge.
Title Forest Plot of Hazard Ratios by Patient Subgroups
Graph_Subgroup Adverse Events
AE_Clinical_Question 1. Which AEs are elevated in treatment vs. control?, 5. Which AEs are elevated in patient subgroups?, 6. What are be the risk factors of an AE?
Description This plot shows the hazard ratios (black squares), and 95 % CIs (horizontal lines), p-values for the interaction between the treatment effect and any subgroup variable, and cumulative estimated 4-year event rates for the AE of interest.

Note that this plot may be adjusted to show treatments effects measured by risk differences, risk ratios, odds, ratio based on investigators preference.
Contributor/Email Sanjay Matange (email: Sanjay.Matange@sas.com)
Background

Keywords

References Pocock et al. ‘Figures in clinical trial reports: current practice and scope for improvement’
Datasets

CDISC_Data

Other_Data

CLASSIFICATIONS

Graph_Type Forest Plot
Variable_Relationship Continuous versus Categorical
Data_Types Categorical
Special_Considerations

Code_Available Yes
Software Program SAS
Software SAS 9.2 (TS2M3) release or later
SAS 9.40M3 release.
R-Code - Attachment

R-Code

SAS-Code - Attachment

SAS-Code
/*-------------------------------------------------------------------*/
/*--Forest Plot for CTSPedia --*/
/*--SAS 9.2 (TS2M3) release or later --*/
/*--Name: Sanjay Matange --*/
/*--Company: SAS Institute Inc. --*/
/*--Date : 06Aug 2012 --*/
/*--History: 06Aug2012/SNM - Add horizontal bands. --*/
/*-------------------------------------------------------------------*/

/*--CTSPedia General AE G1 Forest Plot--*/
%let gpath='C:\';

ods html close;

/*--Leading blanks in the subgroup variable must be non--blank spaces --*/
/*--Use character value 'A0', or copy from Windows System Character Map--*/
/*--Regular leading blanks will be stripped, losing the indentation --*/
data forest;
input Subgroup $1-25 Count Percent Mean Low High PCIGroup Group PValue;
zero=0;
PCI_lbl='PCI group';
grp_lbl='group';
pval_lbl='-';
if count ne . then CountPct?=put(count, 4.0) || "(" || put(percent, 3.0) || ")";
val=mod(N_-1, 6);
if val eq 1 or val eq 2 or val eq 3 then ref=subgroup;
datalines;
Overall 2166 100 1.3 0.9 1.5 17.2 15.6 .
Age . . . . . . . 0.05
<= 65 Yr 1534 71 1.5 1.05 1.9 17.0 13.2 .
> 65 Yr 632 29 0.8 0.6 1.25 17.8 21.3 .
Sex . . . . . . . 0.13
Male 1690 78 1.5 1.05 1.9 16.8 13.5 .
Female 476 22 0.8 0.6 1.3 18.3 22.9 .
Race or ethnic group . . . . . . . 0.52
Nonwhite 428 20 1.05 0.6 1.8 18.8 17.8 .
White 1738 80 1.2 0.6 1.6 16.7 15.0 .
From MI to Randomization . . . . . . . 0.81
<= 7 days 963 44 1.2 0.8 1.5 18.9 18.6 .
> 7 days 1203 56 1.15 0.75 1.5 15.9 12.9 .
Infract-related artery . . . . . . . 0.38
LAD 781 36 1.4 0.9 1.9 20.1 16.2 .
Other 1385 64 1.1 0.8 1.4 15.6 15.3 .
Ejection Fraction . . . . . . . 0.48
< 50% 1151 54 1.2 0.8 1.5 22.6 20.4 .
>= 50% 999 46 0.9 0.6 1.4 10.7 11.1 .
Diabetes . . . . . . . 0.41
Yes 446 21 1.4 0.9 2.0 29.3 23.3 .
No 1720 79 1.1 0.8 1.5 14.4 13.5 .
Killip class . . . . . . . 0.39
I 1740 81 1.2 0.8 1.6 15.2 13.1 .
II-IV 413 19 0.95 0.6 1.5 25.3 26.9 .
;
run;

/*--Define templage for Forest Plot--*/
/*--Template uses a Layout Lattice of 5 columns--*/
proc template;
define statgraph Forest;
dynamic _show_bands;
begingraph;
layout lattice / columns=5 columnweights=(0.21 0.09 0.4 0.2 0.1);

/*--Column headers--*/
sidebar / align=top;
layout lattice / rows=2 columns=5 columnweights=(0.15 0.2 0.25 0.32 0.08);
entry textattrs=(size=8) halign=left "Subgroup";
entry textattrs=(size=8) " No.of Patients (%)";
entry textattrs=(size=8) "Hazard Ratio";
entry halign=right textattrs=(size=8) "4-Yr Cumulative Event Rate" ;
entry halign=right textattrs=(size=8) "P Value" ;
entry " ";
entry " ";
entry " ";
entry halign=right textattrs=(size=6) "Medical Therapy";
entry " ";
endlayout;
endsidebar;

/*--First Subgroup column, shows only the Y2 axis--*/
layout overlay / walldisplay=none xaxisopts=(display=none)
y2axisopts=(reverse=true display=(tickvalues)
tickvalueattrs=(weight=bold));
scatterplot y=subgroup x=zero / markerattrs=(size=0) yaxis=y2;
endlayout;

/*--Second column showing Count and percent--*/
layout overlay / xaxisopts=(display=none)
y2axisopts=(reverse=true display=none) walldisplay=none;
if (exists(_show_bands))
referenceline y=ref / yaxis=y2 lineattrs=(thickness=15 color=cxf0f0f0);
endif;
scatterplot y=subgroup x=zero / markercharacter=countpct yaxis=y2
markercharacterattrs=graphvaluetext;
endlayout;

/*--Third column showing odds ratio graph--*/
layout overlay / xaxisopts=(label=' <---PCI Better---- ----Medical Therapy Better--->'
linearopts=(tickvaluepriority=true
tickvaluelist=(0.0 0.5 1.0 1.5 2.0 2.5)))
y2axisopts=(reverse=true display=none) walldisplay=none;
if (exists(_show_bands))
referenceline y=ref / yaxis=y2 lineattrs=(thickness=15 color=cxf0f0f0);
endif;
scatterplot y=subgroup x=mean / xerrorlower=low xerrorupper=high yaxis=y2
markerattrs=(symbol=squarefilled);
referenceline x=1;
endlayout;

/*--Fourth column showing PCIGroup and Group columns--*/
layout overlay / x2axisopts=(display=(tickvalues) offsetmin=0.25 offsetmax=0.25)
y2axisopts=(reverse=true display=none) walldisplay=none;
if (exists(_show_bands))
referenceline y=ref / yaxis=y2 lineattrs=(thickness=15 color=cxf0f0f0);
endif;
scatterplot y=subgroup x=pci_lbl / markercharacter=PCIGroup xaxis=x2 yaxis=y2
markercharacterattrs=graphvaluetext;
scatterplot y=subgroup x=grp_lbl / markercharacter=group xaxis=x2 yaxis=y2
markercharacterattrs=graphvaluetext;
endlayout;

/*--Fifth column showing PValues--*/
layout overlay / x2axisopts=(display=none)
y2axisopts=(reverse=true display=none) walldisplay=none;
if (exists(_show_bands))
referenceline y=ref / yaxis=y2 lineattrs=(thickness=15 color=cxf0f0f0);
endif;
scatterplot y=subgroup x=pval_lbl / markercharacter=pvalue xaxis=x2 yaxis=y2
markercharacterattrs=graphvaluetext;
endlayout;
endlayout;
entryfootnote halign=left textattrs=(size=7)
'The p-value is from the test statistic for testing the interaction between the '
'treatment and any subgroup variable';
endgraph;
end;
run;

/*--Create font with smaller fonts for axis label, value and data--*/
proc template;
define style listingSF;
parent = Styles.Listing;
style GraphFonts from GraphFonts
"Fonts used in graph styles" /
'GraphDataFont' = ("<sans-serif>, <MTsans-serif>",7pt)
'GraphValueFont' = ("<sans-serif>, <MTsans-serif>",7pt)
'GraphLabelFont' = ("<sans-serif>, <MTsans-serif>",7pt, bold);
;
end;
run;

%let dpi=150;
ods listing style=listingSF gpath=&gpath image_dpi=&dpi;

/*--Render Forest Plot without horizontal bands--*/
ods graphics / reset width=7in height=5in imagename='Forest_92';
proc sgrender data=Forest template=Forest;
run;

/*--Render Forest Plot with horizontal bands--*/
ods graphics / reset width=7in height=5in imagename='Forest_Ref_92';
proc sgrender data=Forest template=Forest;
dynamic _show_bands='YES';
run;


/*-------------------------------------------------------------------*/
/*--Forest Plot for CTSPedia --*/
/*--SAS 9.40M3 release or later --*/
/*--Name: Sanjay Matange --*/
/*--Company: SAS Institute Inc. --*/
/*--Date : 30May2016 --*/
/*--History: 30May2016 - SNM - Add horizontal bands. --*/
/*-------------------------------------------------------------------*/
%let gpath='.';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

/*--Add "Id" to identify subgroup headings from values--*/
data forest_subgroup;
label PCIGroup='PCI Group' Group='Therapy Group';
input Id Subgroup $3-27 Count Percent Mean Low High PCIGroup Group PValue;
label countpct='No. (%) of Patients';
indentWt=1;
ObsId?=_n
;
if count ne . then CountPct?=put(count, 4.0) || "(" || put(percent, 3.0) || ")";
datalines;
1 Overall 2166 100 1.3 0.9 1.5 17.2 15.6 .
1 Age . . . . . . . 0.05
2 <= 65 Yr 1534 71 1.5 1.05 1.9 17.0 13.2 .
2 > 65 Yr 632 29 0.8 0.6 1.25 17.8 21.3 .
1 Sex . . . . . . . 0.13
2 Male 1690 78 1.5 1.05 1.9 16.8 13.5 .
2 Female 476 22 0.8 0.6 1.3 18.3 22.9 .
1 Race or ethnic group . . . . . . . 0.52
2 Nonwhite 428 20 1.05 0.6 1.8 18.8 17.8 .
2 White 1738 80 1.2 0.85 1.6 16.7 15.0 .
1 From MI to Randomization . . . . . . . 0.81
2 <= 7 days 963 44 1.2 0.8 1.5 18.9 18.6 .
2 > 7 days 1203 56 1.15 0.75 1.5 15.9 12.9 .
1 Diabetes . . . . . . . 0.41
2 Yes 446 21 1.4 0.9 2.0 29.3 23.3 .
2 No 720 79 1.1 0.8 1.5 14.4 13.5 .
;
run;

/*--Set indent weight, add insets and horizontal bands--*/
data forest_subgroup_2;
set forest_subgroup nobs=n end=last;
length text $20;
val=mod(_N_-1, 6);
if val eq 1 or val eq 2 or val eq 3 then ref=obsid;

/*--Separate Subgroup headers and obs into separate columns--*/
indentwt=1;
if id=1 then indentWt=0;

output;
if last then do;
call missing (subgroup, count, percent, mean, low, high,
pcigroup, group, countpct, indentwt, val, ref);
obsid=n+1;
xl=0.4; yl=n+1; text='P'; output;;
xl=1.7; yl=n+1; text='T'; output;
end;
run;

/*--Define Format with Unicode for the left and right arrows--*/
proc format;;
value $txt
"T" = "Therapy Better (ESC){Unicode '2192'x}"
"P" = "(ESC){Unicode '2190'x} PCI Better";
run;

/*--Attribute maps for Subgroup Test attributes--*/
data attrmap;
length textweight $10;
id='text'; value='1'; textcolor='Black'; textsize=7; textweight='bold'; output;
id='text'; value='2'; textcolor='Black'; textsize=5; textweight='normal'; output;
run;

/*--Forest Plot using SAS 9.40M3 SGPLOT--*/
options missing=' ';
ods listing style=htmlBlue;
title j=r h=7pt '4-Yr Cumulative Event Rate';
ods graphics / reset width=5in height=3in imagename='Subgroup_Forest_SG_94';
proc sgplot data=forest_subgroup_2 nowall noborder nocycleattrs dattrmap=attrmap noautolegend;
format text $txt.;
styleattrs axisextent=data;
refline ref / lineattrs=(thickness=13 color=cxf0f0f0);
highlow y=obsid low=low high=high;
scatter y=obsid x=mean / markerattrs=(symbol=squarefilled);
scatter y=obsid x=mean / markerattrs=(size=0) x2axis;
refline 1 / axis=x;
text x=xl y=obsid text=text / position=bottom contributeoffsets=none strip;
yaxistable subgroup / location=inside position=left textgroup=id labelattrs=(size=7)
textgroupid=text indentweight=indentWt;
yaxistable countpct / location=inside position=left labelattrs=(size=7) valueattrs=(size=7);
yaxistable PCIGroup group pvalue / location=inside position=right pad=(right=15px)
labelattrs=(size=7) valueattrs=(size=7);
yaxis reverse display=none colorbands=odd colorbandsattrs=(transparency=1) offsetmin=0.0;
xaxis display=(nolabel) values=(0.0 0.5 1.0 1.5 2.0 2.5);
x2axis label='Hazard Ratio' display=(noline noticks novalues) labelattrs=(size=8);
run;
Stata-Code - Attachment

Stata-Code

Other Code - Attachment

Other Code

Disclaimer The views expressed within CTSpedia are those of the author and must not be taken to represent policy or guidance on the behalf of any organization or institution with which the author is affiliated.
Permission Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT OLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Reference Image Matange_ForestPlot_Pocock_200.png
Topic revision: r4 - 30 May 2016 - 11:43:02 - SanjayMatange
 

Copyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CTSPedia? Send feedback