############# Priors and Empirical Bayes estimates ######################### #Use empirical Bayes method to choose Wsoro in prior for method Mr=1 #Or use subjective prior ? res<-0 if(prior.switch.SORO==0){ ## Empirical Bayes obs.rip.var<-apply(r.s.b,2,var) if(prior.switch.SORO.Tony){ Wsoro<-diag(obs.rip.var) - Vsoro }else{ Wsoro<-var(r.s.b) } print('SORO: Empirical Bayes prior') res<-tryCatch(solve(Wsoro), error=function(e) print("Wsoro is not positive definite")) }else if(prior.switch.SORO==1){ ## Subjective prior Wsoro.v<-0.02 Wsoro<-diag(rep(Wsoro.v,Ni)) print('SORO: Subjective prior') }else if(prior.switch.SORO==2){ ## Vague subjective prior Wsoro.v<-0.1 Wsoro<-diag(rep(Wsoro.v,Ni)) print('SORO: Vague subjective prior') } uWsoro<-Wsoro if(!is.character(res)){ uWsoro.inv<-solve(Wsoro) } ########################################################## #RFSP #In the provided data, we are rank deficient (NJ=488, No=534), need to handle differently #Preserve the covariance structure if(prior.switch.RFSP==0){ ## Empirical Bayes obs.op.var<-c(apply(cop.J.full,2,var),apply(fop.J.full,2,var)) obs.op.cor<-matrix(0,No,No) obs.op.cor[1:Ni,1:Ni]<-cor(cop.J.full) obs.op.cor[(Ni+1):No,(Ni+1):No]<-cor(fop.J.full) if(prior.switch.RFSP.Tony){ Rsd<-diag(sqrt(obs.op.var-diag(Vrfsp))) }else{ ##DAS made this empricial Bayes change in light of 1d4d15d Rsd<-diag(sqrt(obs.op.var)) } Wsp<-Rsd %*% (obs.op.cor %*% Rsd) print('RFSP: Empirical Bayes prior') }else if(prior.switch.RFSP==1){ ## Subjective prior Wsp.v<-0.02 Wsp<-diag(rep(Wsp.v,No)) print('RFSP: Subjective prior') }else if(prior.switch.RFSP==2){ ## Vague subjective prior Wsp.v<-0.10 Wsp<-diag(rep(Wsp.v,No)) print('RFSP: Vague subjective prior') } uWsp<-Wsp uWsp.inv<-solve(Wsp) ########################################################## ##Wca mca = apply(ccp.J.full, 2, mean) Wca<-cov(ccp.J.full) #just in case res<-0 if(prior.switch.TUF==0){ ## Empirical Bayes if(prior.switch.TUF.Tony){ obs.ccp.var<-apply(ccp.J.full,2,var) Wca<-diag(obs.ccp.var)-Vtuf }else{ Wca<-var(ccp.J.full) } res<-tryCatch(solve(Wca), error=function(e) print("Wca is not positive definite")) print('TUF: Empirical Bayes prior') }else if(prior.switch.TUF==1){ ## Subjective prior Wca.v<-0.02 Wca<-diag(rep(Wca.v,Ni)) print('TUF: Subjective prior') }else if(prior.switch.TUF==2){ ## Vague subjective prior Wca.v<-0.10 Wca<-diag(rep(Wca.v,Ni)) print('TUF: Vague subjective prior') } uWca<-Wca if(!is.character(res)){ Wca.inv<-solve(Wca) } ########################################################## #Without data, we cannot improve on the Wca data #Wtuf mtuf<-mca Wtuf<-Wca