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(*, endrule = "median")' which calls 'smoothEnds()'.

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

     require(graphics)

     y <- ys <- (-20:20)^2
     y [c(1,10,21,41)] <-  c(100, 30, 400, 470)
     s7k <- runmed(y,7, endrule = "keep")
     s7. <- runmed(y,7, endrule = "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("endrule",c("keep","constant","median"),sep=" = "),
            col = col3, lwd = 1.5, lty = 1)

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

