Análisis de series de temperatura global en R.

### DATOS: debemos descargar los datos desde http://www.stat.pitt.edu/stoffer/tsa2/index.html y guardarlos en el directorio de trabajo de R. 
#gtemp - Global mean land-ocean temperature deviations (from 1951-1980 average), measured in degrees centigrade, for the years 1880-2009;data taken from http://data.giss.nasa.gov/gistemp/graphs/
#gtemp2 - Similar to gtemp but the data are based only on surface air temperature data obtained from meteorological stations.

############################# 2º edición del libro ################
#Example 1.2
globtemp = ts(scan("globtemp.dat"), start=1856)
gtemp = window(globtemp, start=1900) # use data from 1990
plot(gtemp, type="o", ylab="Global Temperature Deviations")

#Example 2.1
fit = lm(gtemp~time(gtemp), na.action=NULL) # regress gtemp on time
#-- note: na.action=NULL is used to retain time series attributes - ?lm for info
summary(fit) # view the results
plot(gtemp, type="o", ylab="Global Temperature Deviation") # plot the series
abline(fit) # add regression line to the plot

#Examples 2.3 and 2.4
fit = lm(gtemp~time(gtemp), na.action=NULL) # regress gtemp on time

x11(); par(mfrow=c(3,1))
plot(gtemp, type="o", ylab="Global Temperature Deviation"); abline(fit) # add regression line to the plot
plot(resid(fit), type="o", main="detrended")
plot(diff(gtemp), type="o", main="first difference") # this and below will do example 2.4


x11() ; par(mfrow=c(3,1)) # plot ACFs
acf(gtemp, 48)
acf(resid(fit), 48)
acf(diff(gtemp), 48)


Comentarios