# NOTE: THIS FILE HAS BEEN CORRECTED FROM THE ORIGINAL SUBMISSION DUE # TO IMPLEMENTATION ERRORS NOTICED BY MCSHANE AND WYNER. (DEC 16 2010) # Calculate proxy PC log eigenvalue spectrum # cf. Mann et al (2007, JGR), Wilks (2006) pc_hat <- list(NULL) pc_var <- list(NULL) sd_res <- list(NULL) # normalise eigenvalues (saved arrays are sqrt(eigenvalue)), square to get eigenvalues # NOTE: ORIGINAL VERSION ERRONEOUSLY USED eigenvalues^2 (DEC 16 2010) pc_var[[1]] = pc_sdev_orig^2 pc_var[[2]] = pc_sdev_correct^2 pc_var[[3]] = pc_sdev_correct_notilj^2 for (i in 1:3){ pc_var[[i]] = pc_var[[i]]/sum(pc_var[[i]]) } # fit line to lowest half of log spectrum for (i in 1:3){ nhalf=floor(length(pc_var[[i]])/2) # CORRECTION: divide by 2 (DEC 16 2010) mylm <- lm(log(pc_var[[i]][1:nhalf])~., data=data.frame(x=1:nhalf)) pc_hat[[i]] <- predict(mylm, data.frame(x=1:nhalf)) sd_res[[i]] <- sd(residuals(mylm)) } # plot points and lines pdf(pdffile, width=7, height=7) plot(1:40,0.01*1:40,type="n", xlab="Eigenvalue number", ylab="Variance explained", ylim=c(0.002,0.5), xlim=c(0,40), col="grey", main="Eigenvalue spectrum", cex.main=0.8, log="y", yaxs="i",xaxs="i") for (i in 1:3){ nhalf=floor(length(pc_var[[i]])/2) # CORRECTION: divide by 2 (DEC 16 2010) points(pc_var[[i]][1:nhalf],col=i,pch=i) lines(exp(pc_hat[[i]][1:nhalf]),col=i) } legend(15,0.1,legend=c("MW network (93 proxies)","Correct proxies (57)","Correct proxies (no Tiljander) (55)"),pch=c(1,2,3),col=c(1,2,3)) dev.off() # using tolerance and criteria estimate PCs to be retained. # retain if log(eigenvalue) is greater than the fit plus a tolerance (1 sd residuals) print("Use Log Eigenvalue criteria...") for (i in 1:3){ print(paste("For network ",i," retain ",sum(pc_var[[1]][1:30] > exp(pc_hat[[1]][1:30]+sd_res[[i]]))," PCs",sep="")) } # Alternatively... print("Or Cumulative Percent Variance explained > 50%...") for (i in 1:3){ n=0 for (j in 1:length(pc_var[[i]])) { if (sum(pc_var[[i]][1:j]) < 0.5) {n=n+1} } # MODIFIED LOOP VARIABLE (DEC 16 2010) print(paste("For network ",i," retain ",n+1," PCs",sep="")) }