# Code based on MW print("Frequencies of MCMC simulations exceeding modern warmth for different time periods:") # Read file with data filenames setwd("bayesmodel") load(paste("bayes_recon_",numpc,".R",sep="")) all_idxD <- c(in_idxD, out_idxD) yhat <- list(yhat1, yhat2, yhat3) # Get max temp: MaxTemp <- max(instrument[,2]) tmp <- substr(instrument[,1], 1, 3) DecAvgTemp <- as.vector( by(instrument[,2], tmp, mean) ) names(DecAvgTemp) <- paste(unique(tmp),"0",sep="") MaxDec <- max(DecAvgTemp) SecMaxDec <- sort(DecAvgTemp, decreasing=TRUE)[2] ######### # YEARS # ######### # Which recons have a year with temp >= MaxTemp; # And how many such years do they have? print("Years") NumBigger <- rep(NA, dim(yhat[[3]])[2]) for(i in 1:dim(yhat[[3]])[2]){ NumBigger[i] <- sum(yhat[[3]][,i] >= MaxTemp) } print(mean(NumBigger>0)) summary(NumBigger) ################ # TRUE DECADES # ################ # Which recons have a true decade with average temp >= MaxDec (and SecMaxDec); # And how many such true decades do they have? print("true decades") NumBiggerDec <- rep(NA, dim(yhat[[3]])[2]) NumBiggerDec2 <- rep(NA, dim(yhat[[3]])[2]) for(i in 1:dim(yhat[[3]])[2]){ tmp <- substr(all_idxD, 1, nchar(all_idxD)-1) tmp2 <- as.vector( by(yhat[[3]][,i], tmp, mean) ) NumBiggerDec[i] <- sum(tmp2 >= MaxDec) NumBiggerDec2[i] <- sum(tmp2 >= SecMaxDec) } print(mean(NumBiggerDec>0)) summary(NumBiggerDec) print(mean(NumBiggerDec2>0)) summary(NumBiggerDec2) ################## # ROLLING BLOCKS # ################## # Which recons have a rolling decades with average temp >= max # And how many such rolling decades do they have? print("Rolling decades") library(zoo) DecMean <- rollmean(instrument[,2], k=10) MM <- max(DecMean) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) for(i in 1:dim(yhat[[3]])[2]){ tmp <- rollmean(yhat[[3]][,i], k=10) NumBiggerMM[i] <- sum(tmp >= MM) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) # Which recons have a rolling 30-year block with average temp >= max # And how many such rolling 30-year blocks do they have? print("Rolling 30-year blocks") library(zoo) DecMean <- rollmean(instrument[,2], k=30) MM <- max(DecMean) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) for(i in 1:dim(yhat[[3]])[2]){ tmp <- rollmean(yhat[[3]][,i], k=30) NumBiggerMM[i] <- sum(tmp >= MM) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) # Which recons have a rolling 60-year block with average temp >= max # And how many such rolling 60-year blocks do they have? print("Rolling 60-year blocks") library(zoo) DecMean <- rollmean(instrument[,2], k=60) MM <- max(DecMean) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) for(i in 1:dim(yhat[[3]])[2]){ tmp <- rollmean(yhat[[3]][,i], k=60) NumBiggerMM[i] <- sum(tmp >= MM) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) ############################## # ROLLING BLOCKS: DERIVATIVE # ############################## # Which recons have a rolling decades with "derivative" >= "max derivative" # And how many such rolling decades do they have? print("Rolling decades/derivative") library(zoo) tmplo <- loess(instrument[,2]~instrument[,1], span=.33) tmpy <- predict(tmplo, instrument[,1], se=FALSE) #tmpMM <- rollmax(tmpy, 10) #tmpmm <- -rollmax(-tmpy, 10) kk <- 10 tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] MM <- max(tmpMM-tmpmm) MMAbs <- max(abs(tmpMM-tmpmm)) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) NumBiggerMMAbs <- rep(NA, dim(yhat[[3]])[2]) tmpxx <- 1:dim(yhat[[3]])[1] for(i in 1:dim(yhat[[3]])[2]){ tmplo <- loess(yhat[[3]][,i]~tmpxx, span=.33) tmpy <- predict(tmplo, tmpxx, se=FALSE) tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] tmp <- tmpMM - tmpmm NumBiggerMM[i] <- sum(tmp >= MM) tmp <- abs(tmpMM - tmpmm) NumBiggerMMAbs[i] <- sum(tmp >= MMAbs) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) print(mean(NumBiggerMMAbs>0)) summary(NumBiggerMMAbs) # Which recons have a rolling 30-year block with "derivative" >= "max derivative" # And how many such rolling 30-year blocks do they have? print("Rolling 30-year blocks/derivative") tmplo <- loess(instrument[,2]~instrument[,1], span=.33) tmpy <- predict(tmplo, instrument[,1], se=FALSE) #tmpMM <- rollmax(tmpy, 10) #tmpmm <- -rollmax(-tmpy, 10) kk <- 30 tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] MM <- max(tmpMM-tmpmm) MMAbs <- max(abs(tmpMM-tmpmm)) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) NumBiggerMMAbs <- rep(NA, dim(yhat[[3]])[2]) tmpxx <- 1:dim(yhat[[3]])[1] for(i in 1:dim(yhat[[3]])[2]){ tmplo <- loess(yhat[[3]][,i]~tmpxx, span=.33) tmpy <- predict(tmplo, tmpxx, se=FALSE) tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] tmp <- tmpMM - tmpmm NumBiggerMM[i] <- sum(tmp >= MM) tmp <- abs(tmpMM - tmpmm) NumBiggerMMAbs[i] <- sum(tmp >= MMAbs) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) print(mean(NumBiggerMMAbs>0)) summary(NumBiggerMMAbs) # Which recons have a rolling 60-year block with "derivative" >= "max derivative" # And how many such rolling 60-year blocks do they have? print("Rolling 60-year blocks/derivative") library(zoo) tmplo <- loess(instrument[,2]~instrument[,1], span=.33) tmpy <- predict(tmplo, instrument[,1], se=FALSE) kk <- 60 tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] MM <- max(tmpMM-tmpmm) MMAbs <- max(abs(tmpMM-tmpmm)) NumBiggerMM <- rep(NA, dim(yhat[[3]])[2]) NumBiggerMMAbs <- rep(NA, dim(yhat[[3]])[2]) tmpxx <- 1:dim(yhat[[3]])[1] for(i in 1:dim(yhat[[3]])[2]){ tmplo <- loess(yhat[[3]][,i]~tmpxx, span=.33) tmpy <- predict(tmplo, tmpxx, se=FALSE) tmpMM <- tmpy[(kk+1):length(tmpy)] tmpmm <- tmpy[1:(length(tmpy)-kk)] tmp <- tmpMM - tmpmm NumBiggerMM[i] <- sum(tmp >= MM) tmp <- abs(tmpMM - tmpmm) NumBiggerMMAbs[i] <- sum(tmp >= MMAbs) } print(mean(NumBiggerMM>0)) summary(NumBiggerMM) print(mean(NumBiggerMMAbs>0)) summary(NumBiggerMMAbs) setwd("../")