Surface Temperature Reconstructions for the Last 2,000 Years (2006)

Chapter: Appendix B: R Code for Figure 9-2

Previous Chapter: Appendix A: Statement of Task
Suggested Citation: "Appendix B: R Code for Figure 9-2." National Research Council. 2006. Surface Temperature Reconstructions for the Last 2,000 Years. Washington, DC: The National Academies Press. doi: 10.17226/11676.

B
R Code for Figure 9-2

n <- 600;

baseline <- n - 0:99;

phi <- 0.9;


HSIndex <- function(x)

{

(mean(x[baseline]) - mean(x)) / sqrt(var(x));

}


SimulatePC1 <- function(p = 50)

{

a <- matrix(NA, n, p);

for (j in 1:p) {

b <- arima.sim(model = list(ar = phi), n);

a[ , j] <- b - mean(b[baseline]);

}

invisible(svd(a)$u[,1]);

}


a <- matrix(NA, n, 5);

for (j in 1:ncol(a)) {

a[ , j] <- SimulatePC1();

}


b <- apply(a, 2, HSIndex);

c <- t(sign(b) * t(a));

matplot(c, type = “l”, xlab = “”, ylab = “”, lty = 2);

Suggested Citation: "Appendix B: R Code for Figure 9-2." National Research Council. 2006. Surface Temperature Reconstructions for the Last 2,000 Years. Washington, DC: The National Academies Press. doi: 10.17226/11676.

PopulationCov <- function(n)

{

a <- matrix(NA, n, n);

a[] <- phi^abs(row(a) - col(a));

for (i in 1:n)

a[i, ] <- a[i, ] - mean(a[i, baseline]);

for (j in 1:n)

a[ , j] <- a[ , j] - mean(a[baseline, j]);

invisible(a);

}


e <- eigen(PopulationCov(n));

lines(e$vectors[,1], col = 2, lwd = 2);

Suggested Citation: "Appendix B: R Code for Figure 9-2." National Research Council. 2006. Surface Temperature Reconstructions for the Last 2,000 Years. Washington, DC: The National Academies Press. doi: 10.17226/11676.
Page 140
Suggested Citation: "Appendix B: R Code for Figure 9-2." National Research Council. 2006. Surface Temperature Reconstructions for the Last 2,000 Years. Washington, DC: The National Academies Press. doi: 10.17226/11676.
Page 141
Next Chapter: Appendix C: Biosketches of Committee Members
Subscribe to Email from the National Academies
Keep up with all of the activities, publications, and events by subscribing to free updates by email.