# NOTE: THIS FILE CONTAINS ERRORS AND HAS BEEN SUPERCEDED BY R_les_proxy.txt # WE ARE GRATEFUL TO MCSHANE AND WYNER FOR NOTICING THEM. (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)), to the power of 4 to get eigenvalues^2 pc_var[[1]] = pc_sdev_orig^4 pc_var[[2]] = pc_sdev_correct^4 pc_var[[3]] = pc_sdev_correct_notilj^4 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]])) 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]])) 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:20] > exp(pc_hat[[1]][1:20]+sd_res[[i]]))," PCs",sep="")) } # Alternatively... print("Or Cumulative Percent Variance explained > 50%...") for (i in 1:3){ n=0 for (j in 1:10) { if (sum(pc_var[[i]][1:j]) < 0.5) {n=n+1} } print(paste("For network ",i," retain ",n+1," PCs",sep="")) } #