smoothEnds               package:stats               R Documentation

_E_n_d _P_o_i_n_t_s _S_m_o_o_t_h_i_n_g (_f_o_r _R_u_n_n_i_n_g _M_e_d_i_a_n_s)

_D_e_s_c_r_i_p_t_i_o_n:

     Smooth end points of a vector 'y' using subsequently smaller
     medians and Tukey's end point rule at the very end. (of odd span),

_U_s_a_g_e:

     smoothEnds(y, k = 3)

_A_r_g_u_m_e_n_t_s:

       y: dependent variable to be smoothed (vector).

       k: width of largest median window; must be odd.

_D_e_t_a_i_l_s:

     'smoothEnds' is used to only do the "end point smoothing", i.e.,
     change at most the observations closer to the beginning/end than
     half the window 'k'.  The first and last value are computed using
     "_Tukey's end point rule_", i.e., 'sm[1] = median(y[1], sm[2],
     3*sm[2] - 2*sm[3])'.

_V_a_l_u_e:

     vector of smoothed values, the same length as 'y'.

_A_u_t_h_o_r(_s):

     Martin Maechler

_R_e_f_e_r_e_n_c_e_s:

     John W. Tukey (1977) _Exploratory Data Analysis_, Addison.

     Velleman, P.F., and Hoaglin, D.C. (1981) _ABC of EDA
     (Applications, Basics, and Computing of Exploratory Data
     Analysis)_; Duxbury.

_S_e_e _A_l_s_o:

     'runmed(*, end.rule = "median")' which calls 'smoothEnds()'.

_E_x_a_m_p_l_e_s:

     y <- ys <- (-20:20)^2
     y [c(1,10,21,41)] <-  c(100, 30, 400, 470)
     s7k <- runmed(y,7, end = "keep")
     s7. <- runmed(y,7, end = "const")
     s7m <- runmed(y,7)
     col3 <- c("midnightblue","blue","steelblue")
     plot(y, main = "Running Medians -- runmed(*, k=7, end.rule = X)")
     lines(ys, col = "light gray")
     matlines(cbind(s7k,s7.,s7m), lwd= 1.5, lty = 1, col = col3)
     legend(1,470, paste("end.rule",c("keep","constant","median"),sep=" = "),
            col = col3, lwd = 1.5, lty = 1)

     stopifnot(identical(s7m, smoothEnds(s7k, 7)))

