#Calculate probability distributions for prevalence, incidence, duration and specific stage durations based on observed prevalence and incidence data, using a Bayesian method.
#Note that for the figures and results in the paper, we considered 10000 values in modeling incidence and overall and stage specific prevalence and in calculating overall and stage-specific duration of the occult period. In this version of the program only 1000 values were evaluated, with a small loss in precision but a big gain in speed of execution.
incidence<-matrix(nrow=1000,ncol=2)
prevalence<-matrix(nrow=1000,ncol=2)
earlyprev<-matrix(nrow=1000,ncol=2)
early1prev<-matrix(nrow=1000,ncol=2)
CISprev<-matrix(nrow=1000,ncol=2)
Stage1prev<-matrix(nrow=1000,ncol=2)
Stage2prev<-matrix(nrow=1000,ncol=2)
Stage3prev<-matrix(nrow=1000,ncol=2)
Stage34prev<-matrix(nrow=1000,ncol=2)
dearlyprev<-matrix(nrow=1000,ncol=2)
dearly1prev<-matrix(nrow=1000,ncol=2)
dCISprev<-matrix(nrow=1000,ncol=2)
dStage1prev<-matrix(nrow=1000,ncol=2)
dStage2prev<-matrix(nrow=1000,ncol=2)
dStage3prev<-matrix(nrow=1000,ncol=2)
dStage34prev<-matrix(nrow=1000,ncol=2)
woopct<-vector(mode="numeric",length=1000)
woo<-vector(mode="numeric",length=1000)
woo1pct<-vector(mode="numeric",length=1000)
woo1<-vector(mode="numeric",length=1000)
CISwoopct<-vector(mode="numeric",length=1000)
CISwoo<-vector(mode="numeric",length=1000)
Stage1woopct<-vector(mode="numeric",length=1000)
Stage1woo<-vector(mode="numeric",length=1000)
Stage2woopct<-vector(mode="numeric",length=1000)
Stage2woo<-vector(mode="numeric",length=1000)
Stage3woopct<-vector(mode="numeric",length=1000)
Stage3woo<-vector(mode="numeric",length=1000)
Stage34woopct<-vector(mode="numeric",length=1000)
Stage34woo<-vector(mode="numeric",length=1000)
dincidence<-matrix(nrow=1000,ncol=2)
dprevalence<-matrix(nrow=1000,ncol=2)
incsample<-vector(mode="numeric",length=1000)
prevsample<-vector(mode="numeric",length=1000)
durationsample<-vector(mode="numeric",length=1000)
#provide observed values for calculating incidence and prevalence and early/late stage distribution. These are taken from the analysis of the literature described in the paper.
#womanyears is the total number of person*years surveyed in the sample population from which incidence is calculated. prompt could be: "Number of person*years observed for cancer incidence"
womanyears<-2345
#incidentcancers is the total number of cancers diagnosed in the person*years monitored for cancer incidence. prompt could be: "Number of cancers diagnosed during the person*years monitored for cancer incidence"
incidentcancers<-36
incidentcancersrange<-3*incidentcancers^0.5
#PBSOs is the total number of prophylactic surgeries, with adequate pathological examination, in the sample used to estimate prevalence of occult cancer. prompt could be: "Number of prophylactic surgeries considered for cancer prevalence"
PBSOs<-406 #number of PBSOs suitable for prevalence estimate in BRCA1 carriers
#occultcancers is the total number of occult unsuspected cancers discovered in these prophylactic surgeries. prompt could be: "Number of occult unsuspected cancers discovered in these prophylactic surgeries"
occultcancers<-32 #number of occult cancers found in the PBSOs suitable for prevalence estimate, in BRCA1 carriers.
occultcancersrange<-3*occultcancers^0.5
#Note the sample of PBSOs used to figure the stage distribution includes some that were excluded from prevalence estimate because of poorly specified denominator.
#CIS is the total number of occult carcinomas in situ to be considered for estimating the stage distribution. prompt could be: "Total number of carcinomas in situ to be considered for estimating the stage distribution."
CIS<-9
#Stage1 is the total number of Stage I occult cancers to be considered for estimating the stage distribution. prompt could be: "Total number of Stage I occult cancers to be considered for estimating the stage distribution."
Stage1<-16
#Stage2 is the total number of Stage I occult cancers to be considered for estimating the stage distribution. prompt could be: "Total number of Stage II occult cancers to be considered for estimating the stage distribution."
Stage2<-6
#Stage3 is the total number of Stage I occult cancers to be considered for estimating the stage distribution. prompt could be: "Total number of Stage III occult cancers to be considered for estimating the stage distribution."
Stage3<-5
#Stage4 is the total number of Stage I occult cancers to be considered for estimating the stage distribution. prompt could be: "Total number of Stage IV occult cancers to be considered for estimating the stage distribution."
Stage4<-1
Stage34<-Stage3+Stage4
Allinvasive<-Stage1+Stage2+Stage3+Stage4
allstage<-CIS+Stage1+Stage2+Stage3+Stage4 #total number of occult cancers discovered by PBSO in BRCA1 carriers - note this sample of PBSOs includes some that were excluded from prevalence estimate because of poorly specified denominator.
for (i in 1:1000)
#if the true incidence (probability of a cancer developing per woman-year) were incidence[i,1], the probability that one would diagnose 36 or fewer cancers in 2345 women-years is incidence[i,2]. The range of values evaluated for the true incidence was chosen to bracket the 99.99% confidence interval.
{
incidence[i,1]<-((incidentcancers-incidentcancersrange)/womanyears)+((incidentcancers+incidentcancersrange)/womanyears)*i/1000
incidence[i,2]<-pbinom(incidentcancers,womanyears+1,0.01*((incidentcancers-incidentcancersrange)/womanyears)+((incidentcancers+incidentcancersrange)/womanyears)*i/1000)
#if the true prevalence (probability of an occult cancer being detected per PBSO) were prevalence[i,1], the probability that one would detect 32 or fewer cancers in 406 PBSOs is prevalence[i,2], The range of values evaluated for the true prevalence was chosen to bracket the 99.99% confidence interval.
prevalence[i,1]<-((occultcancers-occultcancersrange)/PBSOs)+((occultcancers+occultcancersrange)/PBSOs)*i/1000
prevalence[i,2]<-pbinom(occultcancers,PBSOs+1,0.01*((occultcancers-occultcancersrange)/PBSOs)+((occultcancers+occultcancersrange)/PBSOs)*i/1000)
#if the true percentage of occult tumors that are early stage during the occult period (probability of an occult cancer being CIS, stage I or stage II when detected by PBSO) were earlyprev[i,1], the probability that one would detect 31 or fewer early cancers among 37 cancers found by PBSOs is earlyprev[i,2], The range of values evaluated for the true probability of being discovered while early was chosen to bracket the 99.99% confidence interval.
earlyprev[i,1]<-50+50*i/1000
earlyprev[i,2]<-pbinom((CIS+Stage1+Stage2),allstage+1,0.5+50*i/100000)
early1prev[i,1]<-40+50*i/1000
early1prev[i,2]<-pbinom(CIS+Stage1,allstage+1,0.4+50*i/100000)
CISprev[i,1]<-5+50*i/1000
CISprev[i,2]<-pbinom(CIS,allstage+1,0.05+50*i/100000)
Stage1prev[i,1]<-20+50*i/1000
Stage1prev[i,2]<-pbinom(Stage1,allstage+1,0.2+50*i/100000)
Stage2prev[i,1]<-50*i/1000
Stage2prev[i,2]<-pbinom(Stage2,allstage+1,50*i/100000)
Stage3prev[i,1]<-50*i/1000
Stage3prev[i,2]<-pbinom(Stage3,allstage+1,50*i/100000)
Stage34prev[i,1]<-50*i/1000
Stage34prev[i,2]<-pbinom(Stage34,allstage+1,50*i/100000)
}
quartz()
plot(incidence,type="l",lwd=1,xlab="incidence (%)",ylab="probability",main="Probability that serous cancer incidence
in BRCA1 carriers is greater than X")
quartz()
plot(prevalence,type="l",lwd=1,xlab="prevalence (%)",ylab="probability",main="Probability that serous cancer prevalence
in BRCA1carriers is greater than X")
quartz()
plot(earlyprev,type="l",lwd=1,xlab="percent stage CIS,I or II",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are still early stage is greater than X")
quartz()
plot(early1prev,type="l",lwd=1,xlab="percent CIS + Stage I",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are CIS or Stage I is greater than X")
quartz()
plot(CISprev,type="l",lwd=1,xlab="percent CIS",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are CIS is greater than X")
quartz()
plot(Stage1prev,type="l",lwd=1,xlab="percent stage I",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are Stage I is greater than X")
quartz()
plot(Stage2prev,type="l",lwd=1,xlab="percent stage II",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are Stage II is greater than X")
quartz()
plot(Stage3prev,type="l",lwd=1,xlab="percent stage III",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are Stage III is greater than X")
quartz()
plot(Stage34prev,type="l",lwd=1,xlab="percent stage IV",ylab="probability",main="Probability that the % of occult cancers
in BRCA1 carriers that are Stage III or IV is greater than X")
for (i in 1:1000)
{
dincidence[i,1]<-0.7+2*i/1000
dincidence[i,2]<-dbinom(incidentcancers,womanyears+1,0.007+2*i/100000)
dprevalence[i,1]<-3.6+10*i/1000
dprevalence[i,2]<-dbinom(occultcancers,PBSOs+1,0.036+10*i/100000)
dearlyprev[i,1]<-50+50*i/1000
dearlyprev[i,2]<-dbinom((CIS+Stage1+Stage2),allstage+1,0.5+50*i/100000)
dearly1prev[i,1]<-40+50*i/1000
dearly1prev[i,2]<-dbinom((CIS+Stage1),allstage+1,0.4+50*i/100000)
dCISprev[i,1]<-5+50*i/1000
dCISprev[i,2]<-dbinom(CIS,allstage+1,0.05+50*i/100000)
dStage1prev[i,1]<-20+50*i/1000
dStage1prev[i,2]<-dbinom(Stage1,allstage+1,0.2+50*i/100000)
dStage2prev[i,1]<-50*i/1000
dStage2prev[i,2]<-dbinom(Stage2,allstage+1,50*i/100000)
dStage3prev[i,1]<-50*i/1000
dStage3prev[i,2]<-dbinom(Stage3,allstage+1,50*i/100000)
dStage34prev[i,1]<-50*i/1000
dStage34prev[i,2]<-dbinom(Stage34,allstage+1,50*i/100000)
}
quartz()
plot(dincidence,type="l",lwd=1,xlab="Incidence",ylab="Relative Probability",main="probability density of serous cancer
incidence in BRCA1 carriers")
quartz()
plot(dprevalence,type="l",lwd=1,xlab="Prevalence",ylab="Relative Probability",main="probability density of serous cancer
prevalence in BRCA1 carriers")
quartz()
plot(dearlyprev,type="l",lwd=1,xlab="Percent stage CIS,I or II",ylab="Relative Probability",main="probability density of % early stage
in BRCA1 carriers")
quartz()
plot(dearly1prev,type="l",lwd=1,xlab="Percent CIS + Stage I",ylab="Relative Probability",main="probability density of % CIS + Stage I
in BRCA1 carriers")
quartz()
plot(dCISprev,type="l",lwd=1,xlab="Percent CIS",ylab="Relative Probability",main="probability density of % CIS
in BRCA1 carriers")
quartz()
plot(dStage1prev,type="l",lwd=1,xlab="Percent Stage I",ylab="Relative Probability",main="probability density of % Stage I
in BRCA1 carriers")
quartz()
plot(dStage2prev,type="l",lwd=1,xlab="Percent Stage II",ylab="Relative Probability",main="probability density of % Stage II
in BRCA1 carriers")
quartz()
plot(dStage3prev,type="l",lwd=1,xlab="Percent Stage III",ylab="Relative Probability",main="probability density of % Stage III
in BRCA1 carriers")
quartz()
plot(dStage34prev,type="l",lwd=1,xlab="Percent Stage III & IV",ylab="Relative Probability",main="probability density of % Stage III & IV combined
in BRCA1 carriers")
irand10000<-runif(1000,min=0,max=1)
prand10000<-runif(1000,min=0,max=1)
erand10000<-runif(1000,min=0,max=1)
e1rand10000<-runif(1000,min=0,max=1)
CISrand10000<-runif(1000,min=0,max=1)
Stage1rand10000<-runif(1000,min=0,max=1)
Stage2rand10000<-runif(1000,min=0,max=1)
Stage3rand10000<-runif(1000,min=0,max=1)
Stage34rand10000<-runif(1000,min=0,max=1)
for (i in 1:1000)
for (j in 1:1000)
if (incidence[j,2]>irand10000[i])incsample[i]<-incidence[j,1] else break
#incidence:
summary(incsample,digits=2)
quantile(incsample,0.025)
quantile(incsample,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (prevalence[j,2]>prand10000[i])prevsample[i]<-prevalence[j,1] else break
#prevalence:
summary(prevsample,digits=2)
quantile(prevsample,0.025)
quantile(prevsample,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (earlyprev[j,2]>erand10000[i])woopct[i]<-earlyprev[j,1] else break
#duration of early-stage (CIS, Stage I & Stage II) occult period - window of opportunity as a fraction of total occult period:
summary(woopct,digits=2)
quantile(woopct,0.025)
quantile(woopct,0.975)
durationsample<-prevsample/incsample
for (i in 1:1000)
for (j in 1:1000)
if (early1prev[j,2]>e1rand10000[i])woo1pct[i]<-early1prev[j,1] else break
#duration of earliest-stage (CIS, Stage I) occult period - window of opportunity as a fraction of total occult period:
summary(woo1pct,digits=2)
quantile(woo1pct,0.025)
quantile(woo1pct,0.975)
#duration of entire occult period:
summary(durationsample)
quantile(durationsample,0.025)
quantile(durationsample,0.975)
woo<-woopct*durationsample/100
#duration of early (CIS, Stage I & Stage II) occult period - window of opportunity:
summary(woo,digits=2)
quantile(woo,0.025)
quantile(woo,0.975)
woo1<-woo1pct*durationsample/100
#duration of earliest (CIS, Stage I) occult period:
summary(woo1,digits=2)
quantile(woo1,0.025)
quantile(woo1,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (CISprev[j,2]>CISrand10000[i])CISwoopct[i]<-CISprev[j,1] else break
#duration of CIS occult period as a fraction of total occult period:
summary(CISwoopct, digits=2)
quantile(CISwoopct,0.025)
quantile(CISwoopct,0.975)
CISwoo<-CISwoopct*durationsample/100
#duration of CIS occult period:
summary(CISwoo,digits=2)
quantile(CISwoo,0.025)
quantile(CISwoo,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (Stage1prev[j,2]>Stage1rand10000[i])Stage1woopct[i]<-Stage1prev[j,1] else break
#duration of Stage I occult period as a fraction of total occult period:
summary(Stage1woopct,digits=2)
quantile(Stage1woopct,0.025)
quantile(Stage1woopct,0.975)
Stage1woo<-Stage1woopct*durationsample/100
#duration of Stage I occult period:
summary(Stage1woo,digits=2)
quantile(Stage1woo,0.025)
quantile(Stage1woo,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (Stage2prev[j,2]>Stage2rand10000[i])Stage2woopct[i]<-Stage2prev[j,1] else break
#duration of Stage II occult period as a fraction of total occult period:
summary(Stage2woopct,digits=2)
quantile(Stage2woopct,0.025)
quantile(Stage2woopct,0.975)
#duration of Stage II occult period:
Stage2woo<-Stage2woopct*durationsample/100
summary(Stage2woo,digits=2)
quantile(Stage2woo,0.025)
quantile(Stage2woo,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (Stage3prev[j,2]>Stage3rand10000[i])Stage3woopct[i]<-Stage3prev[j,1] else break
#duration of Stage III occult period as a fraction of total occult period:
summary(Stage3woopct,digits=2)
quantile(Stage3woopct,0.025)
quantile(Stage3woopct,0.975)
#duration of Stage III occult period:
Stage3woo<-Stage3woopct*durationsample/100
summary(Stage3woo,digits=2)
quantile(Stage3woo,0.025)
quantile(Stage3woo,0.975)
for (i in 1:1000)
for (j in 1:1000)
if (Stage34prev[j,2]>Stage34rand10000[i])Stage34woopct[i]<-Stage34prev[j,1] else break
#duration of (Stage III + Stage IV) occult period as a fraction of total occult period:
summary(Stage34woopct,digits=2)
quantile(Stage34woopct,0.025)
quantile(Stage34woopct,0.975)
#duration of (Stage III + Stage IV) occult period:
Stage34woo<-Stage34woopct*durationsample/100
summary(Stage34woo,digits=2)
quantile(Stage34woo,0.025)
quantile(Stage34woo,0.975)
lateoccult<-(100-woopct)*durationsample/100
summary(lateoccult,digits=2)
quantile(lateoccult,0.025)
quantile(lateoccult,0.975)
library(lattice)
quartz()
densityplot(durationsample, type="l",xlab="Duration of occult period (years)", ylab="Relative Probability",main="Probability density plot of average
duration of serous cancer occult period
in BRCA1 carriers", col="red")
quartz()
densityplot(woo, type="l",xlab="Years occult and CIS, Stage I or Stage II", ylab="Relative Probability",main="Probability density plot of average
duration of early-stage occult period
in BRCA1 carriers", col="darkgreen")
quartz()
densityplot(woo1, type="l",xlab="Years occult and CIS or Stage I", ylab="Relative Probability",main="Probability density plot of average
duration of CIS + Stage I occult period
in BRCA1 carriers", col="magenta")
quartz()
densityplot(CISwoo, type="l",xlab="Years occult and CIS", ylab="Relative Probability",main="Probability density plot of average
duration of CIS occult period
in BRCA1 carriers", col="magenta")
quartz()
densityplot(Stage1woo, type="l",xlab="Years occult and Stage I", ylab="Relative Probability",main="Probability density plot of average
duration of Stage I occult period
in BRCA1 carriers", col="orchid4")
quartz()
densityplot(Stage2woo, type="l",xlab="Years occult and Stage II", ylab="Relative Probability",main="Probability density plot of average
duration of Stage II occult period
in BRCA1 carriers", col="purple")
quartz()
densityplot(Stage3woo, type="l",xlab="Years occult and Stage III", ylab="Relative Probability",main="Probability density plot of average
duration of Stage III occult period
in BRCA1 carriers", col="orange")
quartz()
densityplot(Stage34woo, type="l",xlab="Years occult and Stage III or Stage IV", ylab="Relative Probability",main="Probability density plot of average
duration of Stage III & Stage IV occult period
in BRCA1 carriers", col="tomato")