-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodelComparison.R
37 lines (28 loc) · 1.01 KB
/
modelComparison.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# R script to take the decadal rates of SLR and calculate principal components for
# comparsion with "synthetic" time series from model output
# Annual data is in stns177Annual
# Rates are in stns177Rates
# Avoid missing value problems by only choosing stations which are complete
completeStns <- vector(mode="integer", length=0)
for (i in 1:177){
if (length(which(is.na(stns177Rates[1:46,i]))) == 0){
completeStns <- c(completeStns,i)
}
}
completeStnsRates <- stns177Rates[1:46,completeStns]
numCompleteStns <- length(completeStns)
# Detrend each time series
dtCompleteStnsRates <- array(NA, dim=c(46,numCompleteStns))
for (i in 1:numCompleteStns){
m <- mean(completeStnsRates[,i])
message(as.character(m))
dtCompleteStnsRates[,i] <- completeStnsRates[,i] - m
}
# Find the covariance matrix
R <- cov(dtCompleteStnsRates)
# Find eigenvalues and eigenvectors
eigenV <- eigen(R)
# Find the explained variances
PCvars <- diag(eigenV$vectors)/sum(diag(eigenV$vectors))
# Highest PCvar is EOF1
EOForder <- rank(PCvars)