ComenzarEmpieza gratis

Removing trends in level by differencing

The first difference transformation of a time series \(z[t]\) consists of the differences (changes) between successive observations over time, that is \(z[t] - z[t-1]\).

Differencing a time series can remove a time trend. The function diff() will calculate the first difference or change series. A difference series lets you examine the increments or changes in a given time series. It always has one fewer observations than the original series.

The time series z has already been loaded, and is shown in the figure on the right.

Este ejercicio forma parte del curso

Time Series Analysis in R

Ver curso

Instrucciones del ejercicio

  • Apply the diff() function to z, saving the result as dz.
  • Use ts.plot() to view a time series plot of the transformed series dz.
  • Use two calls of length() to calculate the number of observations in z and dz, respectively.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Generate the first difference of z
dz <- 
  
# Plot dz


# View the length of z and dz, respectively


Editar y ejecutar código