decreg                package:pastecs                R Documentation

_T_i_m_e _s_e_r_i_e_s _d_e_c_o_m_p_o_s_i_t_i_o_n _u_s_i_n_g _a _r_e_g_r_e_s_s_i_o_n _m_o_d_e_l

_D_e_s_c_r_i_p_t_i_o_n:

     Providing values coming from a regression on the original series,
     a 'tsd' object is created using the original series, the
     regression model and the residuals

_U_s_a_g_e:

     decreg(x, xreg, type="additive")

_A_r_g_u_m_e_n_t_s:

       x: a regular time series ('rts' under S+ and 'ts' under R) 

    xreg: a second regular time series or a vector of the same length
          as 'x' with corresponding values from the regression model 

    type: the type of model, either 'type="additive"' (by default), or
          'type="multiplicative"' 

_V_a_l_u_e:

     a 'tsd' object

_A_u_t_h_o_r(_s):

     Frdric Ibanez (ibanez@obs-vlfr.fr), Philippe Grosjean
     (phgrosjean@sciviews.org)

_R_e_f_e_r_e_n_c_e_s:

     Frontier, S., 1981. _Mthodes statistiques._ Masson, Paris. 246
     pp.

     Kendall, M., 1976. _Time-series._ Charles Griffin & Co Ltd. 197
     pp.

     Legendre, L. & P. Legendre, 1984. _Ecologie numrique. Tome 2: La
     structure des donnes cologiques._ Masson, Paris. 335 pp.

     Malinvaud, E., 1978. _Mthodes statistiques de l'conomtrie._
     Dunod, Paris. 846 pp.

     Sokal, R.R. & F.J. Rohlf, 1981. _Biometry._ Freeman & Co, San
     Francisco. 860 pp.

_S_e_e _A_l_s_o:

     'tsd', 'tseries', 'decaverage', 'deccensus', 'decdiff', 'decevf',
     'decmedian', 'decloess'

_E_x_a_m_p_l_e_s:

     data(marphy)
     density <- ts(marphy[, "Density"])
     plot(density)
     Time <- time(density)

     # Linear model to represent trend
     density.lin <- lm(density ~ Time)
     summary(density.lin)
     xreg <- predict(density.lin)
     lines(xreg, col=3)
     density.dec <- decreg(density, xreg)
     plot(density.dec, col=c(1, 3, 2), xlab="stations")

     # Order 2 polynomial to represent trend
     density.poly <- lm(density ~ Time + I(Time^2))
     summary(density.poly)
     xreg2 <- predict(density.poly)
     plot(density)
     lines(xreg2, col=3)
     density.dec2 <- decreg(density, xreg2)
     plot(density.dec2, col=c(1, 3, 2), xlab="stations")

     # Fit a sinusoidal model on seasonal (artificial) data
     tser <- ts(sin((1:100)/12*pi)+rnorm(100, sd=0.3), start=c(1998, 4),
             frequency=24)
     Time <- time(tser)
     tser.sin <- lm(tser ~ I(cos(2*pi*Time)) + I(sin(2*pi*Time)))
     summary(tser.sin)
     tser.reg <- predict(tser.sin)
     tser.dec <- decreg(tser, tser.reg)
     plot(tser.dec, col=c(1, 4), xlab="stations", stack=FALSE, resid=FALSE,
             lpos=c(0, 4))
     plot(tser.dec, col=c(1, 4, 2), xlab="stations")

     # One can also use nonlinear models (see 'nls')
     # or autoregressive models (see 'ar' and others in 'ts' library)

