1
$\begingroup$

I have a time series of the Sea Surface Temperature (SST) of the Caribean Sea and I have to obtain the anomalies of that time series.

        Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct    Nov    Dec
1948 24.786 24.767 25.117 25.514 26.565 27.374 27.778 28.022 27.827 27.308 26.545 25.620
1949 25.191 24.962 25.038 25.591 26.325 27.044 27.719 28.059 28.077 27.541 26.501 25.568
1950 24.713 24.461 24.682 25.122 26.157 26.965 27.688 28.072 28.089 27.429 26.318 25.194
1951 24.423 24.114 24.335 25.153 26.399 27.474 28.143 28.547 28.441 27.854 26.904 25.842
1952 25.025 24.812 25.317 25.734 26.660 27.615 28.069 28.468 28.384 27.738 26.640 25.402
1953 24.619 24.614 25.048 25.917 26.870 27.485 28.021 28.363 28.311 27.687 26.768 25.829
1954 25.176 24.804 25.089 25.768 26.579 27.222 27.684 28.053 27.971 27.164 26.141 25.162
1955 24.553 24.340 24.679 25.266 26.182 26.959 27.649 28.108 28.053 27.453 26.594 25.483
1956 24.492 24.361 24.791 25.446 26.295 26.867 27.505 27.946 27.889 27.420 26.347 25.504
1957 24.928 24.811 25.110 25.690 26.677 27.566 28.221 28.486 28.459 27.793 26.889 25.794
1958 24.982 24.616 25.134 25.940 26.842 27.887 28.421 28.758 28.712 28.085 27.185 26.233
1959 25.432 25.376 25.469 25.987 26.726 27.424 28.042 28.242 28.349 27.988 26.962 26.049
1960 25.364 25.060 25.195 25.877 26.907 27.645 28.187 28.427 28.344 28.002 27.124 25.859
1961 25.194 25.116 25.415 25.907 26.755 27.363 27.960 28.269 28.224 27.672 26.792 25.849
1962 25.335 25.174 25.257 25.696 26.708 27.386 28.144 28.467 28.398 27.828 26.593 25.624
1963 25.103 24.899 25.371 25.914 26.646 27.481 27.953 28.341 28.277 27.652 26.733 25.661
1964 25.023 24.864 25.188 25.678 26.622 27.434 27.753 27.950 27.859 27.217 26.348 25.285
1965 24.478 24.373 24.636 25.399 26.180 26.973 27.499 27.912 27.954 27.550 26.709 25.768
1966 24.885 24.625 24.797 25.494 26.307 27.183 27.877 28.186 28.225 27.728 26.615 25.466
1967 24.794 24.639 24.872 25.375 26.345 27.023 27.564 27.914 27.973 27.529 26.550 25.478
1968 24.521 24.180 24.466 25.344 26.259 27.241 27.929 28.349 28.283 27.681 26.692 25.643
1969 24.838 24.668 25.022 26.111 27.064 27.970 28.415 28.547 28.431 27.852 26.705 25.604
1970 24.849 24.565 24.964 25.809 26.502 27.206 27.793 28.065 28.101 27.570 26.367 25.412
1971 24.756 24.505 24.660 25.258 26.161 26.984 27.564 27.832 27.747 27.238 26.304 25.473
1972 24.903 24.638 25.025 25.624 26.355 27.086 27.629 27.938 28.112 27.757 26.969 26.070
1973 25.217 24.837 25.237 25.591 26.594 27.422 27.919 28.030 27.989 27.440 26.454 25.131
1974 24.783 24.371 24.839 25.495 26.199 27.103 27.608 27.938 27.907 27.200 26.276 25.229
1975 24.622 24.564 24.867 25.532 26.407 27.202 27.545 27.947 27.777 27.236 26.326 25.045
1976 24.058 23.905 24.467 25.101 25.954 26.744 27.458 27.854 27.899 27.539 26.537 25.631
1977 24.768 24.636 25.078 25.422 26.202 27.195 27.869 28.085 28.096 27.613 26.797 25.758
1978 24.876 24.496 24.901 25.673 26.661 27.311 27.762 28.034 28.025 27.584 26.828 25.851
1979 24.920 24.658 24.853 25.461 26.285 27.295 27.820 28.137 28.090 27.640 26.608 25.577
1980 24.917 24.588 25.038 25.697 26.828 27.554 28.094 28.295 28.269 27.653 26.622 25.470
1981 24.684 24.514 24.832 25.601 26.686 27.545 28.058 28.269 28.314 27.558 26.497 25.572
1982 24.933 24.950 25.302 25.782 26.244 27.219 27.827 28.070 28.105 27.546 26.505 25.582
1983 25.011 24.826 24.964 25.533 26.533 27.559 27.962 28.250 28.202 27.679 26.762 25.971
1984 25.118 24.859 24.906 25.558 26.239 26.828 27.428 27.669 27.734 27.202 26.150 25.112
1985 24.318 24.271 24.755 25.199 26.387 27.411 27.737 28.095 27.917 27.358 26.483 25.429
1986 24.657 24.638 24.688 25.307 26.224 27.123 27.605 27.935 27.795 27.411 26.718 25.869
1987 24.976 24.645 24.866 25.400 26.513 27.425 28.068 28.427 28.564 27.764 26.818 25.879
1988 24.830 24.549 24.811 25.438 26.429 27.313 27.803 28.096 27.953 27.309 26.580 25.279
1989 24.764 24.433 24.572 25.446 26.289 26.978 27.651 28.042 28.089 27.388 26.620 25.535
1990 24.957 24.903 24.897 25.592 26.405 27.240 27.663 28.210 28.357 27.823 26.603 25.473
1991 24.968 24.738 25.084 25.637 26.420 27.180 27.858 28.132 28.039 27.465 26.407 25.361
1992 24.633 24.574 25.001 25.353 25.941 27.261 27.779 28.006 27.941 27.448 26.552 25.572
1993 24.987 24.549 24.565 25.222 26.050 27.154 27.777 28.123 28.142 27.623 26.686 25.595
1994 24.742 24.683 24.935 25.684 26.583 27.330 27.555 27.868 27.946 27.446 26.758 25.813
1995 25.031 24.679 24.906 25.430 26.635 27.461 28.084 28.317 28.450 27.866 26.822 25.955
1996 24.926 24.628 24.667 25.210 26.104 27.157 27.636 27.837 28.119 27.441 26.515 25.343
1997 24.862 24.744 24.997 25.316 26.309 27.201 28.096 28.396 28.324 27.677 26.768 25.921
1998 25.340 25.061 24.937 25.598 26.607 27.940 28.416 28.825 28.607 28.048 26.948 26.014
1999 25.287 24.739 24.846 25.565 26.486 27.208 27.571 28.461 28.440 27.583 26.483 25.280
2000 24.583 24.297 24.579 25.224 26.222 27.061 27.762 28.160 28.330 27.742 26.728 25.698
2001 24.750 24.731 24.866 25.398 26.005 27.255 27.809 28.315 28.403 27.762 26.605 25.827
2002 25.158 24.950 25.007 25.783 26.482 27.117 27.771 28.397 28.413 27.991 27.188 26.064
2003 25.070 24.965 25.641 25.791 26.849 27.452 27.813 28.253 28.422 28.178 27.268 25.854
2004 24.991 24.882 25.037 25.373 25.992 27.244 27.962 28.332 28.308 27.955 26.810 25.702
2005 24.773 24.284 24.816 25.634 26.525 27.819 28.374 28.837 28.899 28.161 26.976 25.819
2006 25.032 24.568 24.847 25.511 26.515 27.539 27.918 28.425 28.757 28.331 27.144 26.068
2007 25.487 25.064 25.243 25.692 26.578 27.361 28.164 28.588 28.558 28.069 26.874 25.987
2008 25.107 25.002 25.040 25.449 26.216 27.264 27.778 28.359 28.375 27.772 26.578 25.438
2009 24.791 24.363 24.454 25.321 26.100 27.207 28.046 28.387 28.531 28.255 27.176 26.390
2010 25.058 24.769 24.735 25.528 26.745 28.046 28.406 28.859 28.692 27.858 26.761 25.273
2011 24.498 24.614 24.853 25.824 26.557 27.568 28.147 28.709 28.591 27.863 26.878 25.936
2012 25.054 24.927 25.096 25.646 26.457 27.417 28.011 28.399 28.493 28.129 26.740 25.966
2013 25.392 25.105 24.906 25.613 26.354 27.135 27.715 28.345 28.545 28.280 27.297 26.302

I've tried to calculate the mean every 12 months and subtracting it to each data of the year. I constructed a code in Matlab but when i plot the anomaly series, it still retains the annual variability.

Code:

y=data(1:792,1);  %Data
n=length(x);     
anomaly_tem=zeros(1,n/12); 
p=0;
for i=1:(n/12)
  med_tem=mean(y((12*(i-1)+1):(12*i)));
   for j=1:12
    p=p+1;
    anomaly_tem(p)=y(p)-med_tem;
   end
end
startDate = datenum('01-01-1948');
endDate = datenum('12-31-2013');
dat = linspace(startDate,endDate,length(anomaly_tem));

plot(dat,anomaly_pre,'color','black')
xlim([min(dat) max(dat)]);
datetick('x','yyyy','keeplimits')

Some other way to do this?

$\endgroup$
2
$\begingroup$

By removing the annual means you are rescaling the data in each year, this does not affect the seasonal pattern in the data. To do so, you can remove the monthly means, i.e., calculate the mean of all the observations recorded in January and remove this mean to all these observations recorded in January, the same is done for the other months. These are the plots that I get in each case:

yearly and monthly means removed

Another interesting graphical view of the data is a plot of the annual means. This reduces the data to one observation per year. As it is a smoother version of the original data it may reveal some pattern in the long-term. As shown in the plot below, an increasing trend seems clear in the last years of the sample.

annual means


For completeness, this is the R code that I used to produce the figures above.

# requires object "x" at the end of this script
y <- ts(as.vector(t(as.matrix(x[,-1]))), frequency=12, start=c(1948,1))
# remove the mean of each year
id1 <- gl(length(y)/12, 12)
a1 <- unlist(lapply(split(y, id1), mean))
z1 <- y - a1[id1]
# remove monthly means
id2 <- cycle(y)
a2 <- unlist(lapply(split(y, id2), mean))
z2 <- y - a2[id2]
# figure 1
par(mfrow=c(2,1), mar=c(2.5,3,2,2),las=1)
plot(z1, type="n")
grid()
lines(z1)
mtext(side=3, adj=0, text="yearly means removed")
plot(z2, type="n")
grid()
lines(z2)
mtext(side=3, adj=0, text="monthly means removed")
# figure 2
z3 <- ts(unlist(lapply(split(y, gl(length(y)/12, 12)), mean)), start=1948)
plot(z3, ylab="", type="n")
grid()
lines(z3)
lines(tsSmooth(StructTS(z3, type="level"))[,1], lty=1, lwd=3, col="blue")
mtext(side=3, adj=0, text="annual means and fitted time-varying level")

Load the data:

x <- read.csv(text=
"1948 24.786 24.767 25.117 25.514 26.565 27.374 27.778 28.022 27.827 27.308 26.545 25.620
1949 25.191 24.962 25.038 25.591 26.325 27.044 27.719 28.059 28.077 27.541 26.501 25.568
1950 24.713 24.461 24.682 25.122 26.157 26.965 27.688 28.072 28.089 27.429 26.318 25.194
1951 24.423 24.114 24.335 25.153 26.399 27.474 28.143 28.547 28.441 27.854 26.904 25.842
1952 25.025 24.812 25.317 25.734 26.660 27.615 28.069 28.468 28.384 27.738 26.640 25.402
1953 24.619 24.614 25.048 25.917 26.870 27.485 28.021 28.363 28.311 27.687 26.768 25.829
1954 25.176 24.804 25.089 25.768 26.579 27.222 27.684 28.053 27.971 27.164 26.141 25.162
1955 24.553 24.340 24.679 25.266 26.182 26.959 27.649 28.108 28.053 27.453 26.594 25.483
1956 24.492 24.361 24.791 25.446 26.295 26.867 27.505 27.946 27.889 27.420 26.347 25.504
1957 24.928 24.811 25.110 25.690 26.677 27.566 28.221 28.486 28.459 27.793 26.889 25.794
1958 24.982 24.616 25.134 25.940 26.842 27.887 28.421 28.758 28.712 28.085 27.185 26.233
1959 25.432 25.376 25.469 25.987 26.726 27.424 28.042 28.242 28.349 27.988 26.962 26.049
1960 25.364 25.060 25.195 25.877 26.907 27.645 28.187 28.427 28.344 28.002 27.124 25.859
1961 25.194 25.116 25.415 25.907 26.755 27.363 27.960 28.269 28.224 27.672 26.792 25.849
1962 25.335 25.174 25.257 25.696 26.708 27.386 28.144 28.467 28.398 27.828 26.593 25.624
1963 25.103 24.899 25.371 25.914 26.646 27.481 27.953 28.341 28.277 27.652 26.733 25.661
1964 25.023 24.864 25.188 25.678 26.622 27.434 27.753 27.950 27.859 27.217 26.348 25.285
1965 24.478 24.373 24.636 25.399 26.180 26.973 27.499 27.912 27.954 27.550 26.709 25.768
1966 24.885 24.625 24.797 25.494 26.307 27.183 27.877 28.186 28.225 27.728 26.615 25.466
1967 24.794 24.639 24.872 25.375 26.345 27.023 27.564 27.914 27.973 27.529 26.550 25.478
1968 24.521 24.180 24.466 25.344 26.259 27.241 27.929 28.349 28.283 27.681 26.692 25.643
1969 24.838 24.668 25.022 26.111 27.064 27.970 28.415 28.547 28.431 27.852 26.705 25.604
1970 24.849 24.565 24.964 25.809 26.502 27.206 27.793 28.065 28.101 27.570 26.367 25.412
1971 24.756 24.505 24.660 25.258 26.161 26.984 27.564 27.832 27.747 27.238 26.304 25.473
1972 24.903 24.638 25.025 25.624 26.355 27.086 27.629 27.938 28.112 27.757 26.969 26.070
1973 25.217 24.837 25.237 25.591 26.594 27.422 27.919 28.030 27.989 27.440 26.454 25.131
1974 24.783 24.371 24.839 25.495 26.199 27.103 27.608 27.938 27.907 27.200 26.276 25.229
1975 24.622 24.564 24.867 25.532 26.407 27.202 27.545 27.947 27.777 27.236 26.326 25.045
1976 24.058 23.905 24.467 25.101 25.954 26.744 27.458 27.854 27.899 27.539 26.537 25.631
1977 24.768 24.636 25.078 25.422 26.202 27.195 27.869 28.085 28.096 27.613 26.797 25.758
1978 24.876 24.496 24.901 25.673 26.661 27.311 27.762 28.034 28.025 27.584 26.828 25.851
1979 24.920 24.658 24.853 25.461 26.285 27.295 27.820 28.137 28.090 27.640 26.608 25.577
1980 24.917 24.588 25.038 25.697 26.828 27.554 28.094 28.295 28.269 27.653 26.622 25.470
1981 24.684 24.514 24.832 25.601 26.686 27.545 28.058 28.269 28.314 27.558 26.497 25.572
1982 24.933 24.950 25.302 25.782 26.244 27.219 27.827 28.070 28.105 27.546 26.505 25.582
1983 25.011 24.826 24.964 25.533 26.533 27.559 27.962 28.250 28.202 27.679 26.762 25.971
1984 25.118 24.859 24.906 25.558 26.239 26.828 27.428 27.669 27.734 27.202 26.150 25.112
1985 24.318 24.271 24.755 25.199 26.387 27.411 27.737 28.095 27.917 27.358 26.483 25.429
1986 24.657 24.638 24.688 25.307 26.224 27.123 27.605 27.935 27.795 27.411 26.718 25.869
1987 24.976 24.645 24.866 25.400 26.513 27.425 28.068 28.427 28.564 27.764 26.818 25.879
1988 24.830 24.549 24.811 25.438 26.429 27.313 27.803 28.096 27.953 27.309 26.580 25.279
1989 24.764 24.433 24.572 25.446 26.289 26.978 27.651 28.042 28.089 27.388 26.620 25.535
1990 24.957 24.903 24.897 25.592 26.405 27.240 27.663 28.210 28.357 27.823 26.603 25.473
1991 24.968 24.738 25.084 25.637 26.420 27.180 27.858 28.132 28.039 27.465 26.407 25.361
1992 24.633 24.574 25.001 25.353 25.941 27.261 27.779 28.006 27.941 27.448 26.552 25.572
1993 24.987 24.549 24.565 25.222 26.050 27.154 27.777 28.123 28.142 27.623 26.686 25.595
1994 24.742 24.683 24.935 25.684 26.583 27.330 27.555 27.868 27.946 27.446 26.758 25.813
1995 25.031 24.679 24.906 25.430 26.635 27.461 28.084 28.317 28.450 27.866 26.822 25.955
1996 24.926 24.628 24.667 25.210 26.104 27.157 27.636 27.837 28.119 27.441 26.515 25.343
1997 24.862 24.744 24.997 25.316 26.309 27.201 28.096 28.396 28.324 27.677 26.768 25.921
1998 25.340 25.061 24.937 25.598 26.607 27.940 28.416 28.825 28.607 28.048 26.948 26.014
1999 25.287 24.739 24.846 25.565 26.486 27.208 27.571 28.461 28.440 27.583 26.483 25.280
2000 24.583 24.297 24.579 25.224 26.222 27.061 27.762 28.160 28.330 27.742 26.728 25.698
2001 24.750 24.731 24.866 25.398 26.005 27.255 27.809 28.315 28.403 27.762 26.605 25.827
2002 25.158 24.950 25.007 25.783 26.482 27.117 27.771 28.397 28.413 27.991 27.188 26.064
2003 25.070 24.965 25.641 25.791 26.849 27.452 27.813 28.253 28.422 28.178 27.268 25.854
2004 24.991 24.882 25.037 25.373 25.992 27.244 27.962 28.332 28.308 27.955 26.810 25.702
2005 24.773 24.284 24.816 25.634 26.525 27.819 28.374 28.837 28.899 28.161 26.976 25.819
2006 25.032 24.568 24.847 25.511 26.515 27.539 27.918 28.425 28.757 28.331 27.144 26.068
2007 25.487 25.064 25.243 25.692 26.578 27.361 28.164 28.588 28.558 28.069 26.874 25.987
2008 25.107 25.002 25.040 25.449 26.216 27.264 27.778 28.359 28.375 27.772 26.578 25.438
2009 24.791 24.363 24.454 25.321 26.100 27.207 28.046 28.387 28.531 28.255 27.176 26.390
2010 25.058 24.769 24.735 25.528 26.745 28.046 28.406 28.859 28.692 27.858 26.761 25.273
2011 24.498 24.614 24.853 25.824 26.557 27.568 28.147 28.709 28.591 27.863 26.878 25.936
2012 25.054 24.927 25.096 25.646 26.457 27.417 28.011 28.399 28.493 28.129 26.740 25.966
2013 25.392 25.105 24.906 25.613 26.354 27.135 27.715 28.345 28.545 28.280 27.297 26.302", sep=" ", header=FALSE)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.