#Functions for modified power prior and conditional power prior Prior<-function(logHR,alpha){ tempRes<-dunif(alpha,min=0,max=10)* prod(dnorm(logHR,mean=0,sd=100)) if (tempRes==0){ #Set prior to almost zero when it is zero, to prevent numerical problems when taking logarithms. tempRes<- 10^-300 } Prior<-tempRes } LikelihoodCPPPooledPiecewise<-function(parameters,theta,minTrial,maxTrial,P,K,N,Trial,X,dataset){ #Log-likelihood function for pooled analysis of conditional power prior, with piecewise constant baseline hazard. alpha<-parameters[1:K] par<-parameters[(K+1):(K+P)] sigma<-parameters[K+P+1] Prior<-0 mu<-matrix(0,N,K) for (k in 1:K){mu[,k] <- dataset$TimeIntervals[,k]*exp(alpha[k]+X%*%par)} vector<-theta*(Trial0.01 & sigma<100){ Prior <- Prior + log(1/(100-0.01)) #Commensurate Priors on Current Log-Hazards for (j in 1:P){ Prior <- Prior+ dnorm(par[j],mean=0,sd=100,log=TRUE) } Prior <- Prior+ dnorm(alpha[1],mean=0,sd=100,log=TRUE) for (k in 2:K) { Prior<- Prior + dnorm(alpha[k],mean=alpha[k-1],sd=sigma,log=TRUE) } }else{ Prior <- -10^300 } LikelihoodCPPPooledPiecewise<- Prior + Likl } LikelihoodMPPPooledPiecewise<-function(parameters,minTrial,maxTrial,P,K,N,Trial,X,a,b,dataset,ScalingConstant){ #Log-likelihood function for pooled analysis of modified power prior, with piecewise constant baseline hazard. alpha<-parameters[1:K] par<-parameters[(K+1):(K+P)] sigma<-parameters[K+P+1] theta<-parameters[K+P+2] Prior<-0 mu<-matrix(0,N,K) for (k in 1:K){mu[,k] <- dataset$TimeIntervals[,k]*exp(alpha[k]+X%*%par)} vector<-theta*(Trial0.01 & sigma<100 & theta>0 & theta<1){ Prior <- Prior + log(1/(100-0.01)) #Commensurate Priors on Current Log-Hazards for (j in 1:P){ Prior <- Prior+ dnorm(par[j],mean=0,sd=100,log=TRUE) } Prior <- Prior+ dnorm(alpha[1],mean=0,sd=100,log=TRUE) for (k in 2:K) { Prior<- Prior + dnorm(alpha[k],mean=alpha[k-1],sd=sigma,log=TRUE) } Prior<- Prior + log(dbeta(theta,a,b)) ScalingConstantTemp <- -(theta*length(ScalingConstant)-floor(theta*length(ScalingConstant)))*ScalingConstant[floor(theta*length(ScalingConstant))+1] if ((theta*length(ScalingConstant))>1){ ScalingConstantTemp<- ScalingConstantTemp - (-theta*length(ScalingConstant)+floor(theta*length(ScalingConstant)+1))*ScalingConstant[floor(theta*length(ScalingConstant))] } }else{ Prior <- -10^200 ScalingConstantTemp<- 0 } LikelihoodMPPPooledPiecewise<- Prior + Likl + ScalingConstantTemp } LikelihoodMPPPooledPiecewiseScalingConstant<-function(parameters,theta,minTrial,maxTrial,P,K,N,Trial,X,dataset){ #Log-likelihood function for pooled analysis of modified power prior, with piecewise constant baseline hazard. #Only for calculating the scaling constant, so current trial is not included in calculation! alpha<-parameters[1:K] par<-parameters[(K+1):(K+P)] sigma<-parameters[K+P+1] Prior<-0 mu<-matrix(0,N,K) for (k in 1:K){mu[,k] <- dataset$TimeIntervals[,k]*exp(alpha[k]+X%*%par)} vector<-theta*(Trial0.01 & sigma<100){ Prior <- Prior + log(1/(100-0.01)) #Commensurate Priors on Current Log-Hazards for (j in 1:P){ Prior <- Prior+ dnorm(par[j],mean=0,sd=100,log=TRUE) } Prior <- Prior+ dnorm(alpha[1],mean=0,sd=100,log=TRUE) for (k in 2:K) { Prior<- Prior + dnorm(alpha[k],mean=alpha[k-1],sd=sigma,log=TRUE) } }else{ Prior <- -10^300 } if(is.nan(Likl)){ Likl<- -10^300 } LikelihoodMPPPooledPiecewiseScalingConstant<- Prior + Likl } LikelihoodMPPPooledPiecewiseScalingConstantWithoutPrior<-function(parameters,minTrial,maxTrial,P,K,N,Trial,X,dataset){ #Log-likelihood function (excluding prior) for pooled analysis of modified power prior, with piecewise constant baseline hazard. #Only for calculating the scaling constant, so current trial is not included in calculation! alpha<-parameters[1:K] par<-parameters[(K+1):(K+P)] sigma<-parameters[K+P+1] Prior<-0 mu<-matrix(0,N,K) for (k in 1:K){mu[,k] <- dataset$TimeIntervals[,k]*exp(alpha[k]+X%*%par)} vector<-1*(Trial