# Independent numerical validation using metafor; not required by the default Python run. suppressPackageStartupMessages(library(metafor)) x<-read.csv('/study/data/endpoints.csv',stringsAsFactors=FALSE) h<-read.csv('/study/data/hr_effects.csv',stringsAsFactors=FALSE) p<-read.csv('/study/data/prior_meta_inputs.csv',stringsAsFactors=FALSE) rows<-list() for(ep in c('death','mi_all','stroke')) { d<-subset(x,population=='stable' & endpoint==ep & trial %in% c('FAME3','HREVS')) e<-escalc(measure='RR',ai=d$events_pci,bi=d$n_pci-d$events_pci,ci=d$events_cabg,di=d$n_cabg-d$events_cabg) fit<-rma.uni(e$yi,e$vi,method='PM',test='adhoc',control=list(tol=1e-12)) zn<-rma.uni(e$yi,e$vi,method='PM',test='z',control=list(tol=1e-12)) rows[[length(rows)+1]]<-data.frame(key=paste0('stable_5y_',ep),effect=exp(coef(fit)),lo_mhk=exp(fit$ci.lb),hi_mhk=exp(fit$ci.ub),lo_normal=exp(zn$ci.lb),hi_normal=exp(zn$ci.ub),tau2=fit$tau2) } for(ep in c('death','death_mi_stroke','repeat_any')) { d<-subset(h,population=='all' & endpoint==ep & trial %in% c('FAME3','BEST')) yi<-log(d$hr_pci_over_cabg);vi<-((log(d$ci_upper)-log(d$ci_lower))/(2*qnorm(.975)))^2 fit<-rma.uni(yi,vi,method='PM',test='adhoc',control=list(tol=1e-12));zn<-rma.uni(yi,vi,method='PM',test='z',control=list(tol=1e-12)) rows[[length(rows)+1]]<-data.frame(key=paste0('mixed_horizon_all_HR_',ep),effect=exp(coef(fit)),lo_mhk=exp(fit$ci.lb),hi_mhk=exp(fit$ci.ub),lo_normal=exp(zn$ci.lb),hi_normal=exp(zn$ci.ub),tau2=fit$tau2) } write.csv(do.call(rbind,rows),'/out/independent-r-validation.csv',row.names=FALSE) mh<-list() for(ep in unique(p$endpoint)) { for(kind in c('as_plotted','independent_randomized_only')) { d<-subset(p,endpoint==ep);if(kind=='independent_randomized_only')d<-subset(d,report=='Fearon2025') fit<-rma.mh(measure='RR',ai=d$events_pci,bi=d$n_pci-d$events_pci,ci=d$events_cabg,di=d$n_cabg-d$events_cabg) mh[[length(mh)+1]]<-data.frame(endpoint=ep,version=kind,rr=exp(coef(fit)),lo=exp(fit$ci.lb),hi=exp(fit$ci.ub)) } } write.csv(do.call(rbind,mh),'/out/independent-r-prior-mh.csv',row.names=FALSE) writeLines(c(R.version.string,paste('metafor',packageVersion('metafor'))),'/out/independent-r-environment.txt') cat('Validated',length(rows),'random-effects estimates and',length(mh),'Mantel-Haenszel estimates.\n')