monoreg               package:fdrtool               R Documentation

_M_o_n_o_t_o_n_e _R_e_g_r_e_s_s_i_o_n: _I_s_o_t_o_n_i_c _R_e_g_r_e_s_s_i_o_n _a_n_d _A_n_t_i_t_o_n_i_c _R_e_g_r_e_s_s_i_o_n

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

     'monoreg' performs monotone regression (either isotonic or
     antitonic) with weights.

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

     monoreg(x, y=NULL, w=rep(1, length(x)), type=c("isotonic", "antitonic"))

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

    x, y: coordinate vectors of the regression points.  Alternatively a
          single "plotting" structure can be specified: see
          'xy.coords'.

       w: data weights (default values: 1).

    type: fit a monotonely increasing ("isotonic") or  monotonely
          decreasing ("antitonic") function.

_D_e_t_a_i_l_s:

     'monoreg' is similar to 'isoreg', with the addition that 'monoreg'
     accepts weights.

     If several identical 'x' values are given as input, the 
     corresponding 'y' values and the weights 'w' are automatically
     merged, and a warning is issued.

     The 'plot.monoreg' function optionally plots the cumulative sum
     diagram with the greatest convex minorant (isotonic regression) or
     the least concave majorant (antitonic regression), see the
     examples below.

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

     A list with the following entries:

       x: the sorted and unique x values

       y: the corresponding y values

       w: the corresponding weights

      yf: the fitted y values

    type: the type of monotone regression ("isotonic" or "antitonic"

    call: the function call

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

     Korbinian Strimmer (<URL: http://strimmerlab.org>).

     Part of this function is C code that has been ported from R code
     originally written by Kaspar Rufibach.

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

     Robertson, T., F. T. Wright, and R. L. Dykstra. 1988.  Order
     restricted statistical inference. John Wiley and Sons.

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

     'isoreg'.

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

     # load "fdrtool" library
     library("fdrtool")

     # an example with weights

     # Example 1.1.1. (dental study) from Robertson, Wright and Dykstra (1988)
     age = c(14, 14, 8, 8, 8, 10, 10, 10, 12, 12, 12)
     size = c(23.5, 25, 21, 23.5, 23, 24, 21, 25, 21.5, 22, 19)

     mr = monoreg(age, size)

     # sorted x values
     mr$x # 8 10 12 14
     # weights and merged y values
     mr$w  # 3 3 3 2
     mr$y #  22.50000 23.33333 20.83333 24.25000
     # fitted y values
     mr$yf # 22.22222 22.22222 22.22222 24.25000
     fitted(mr)
     residuals(mr)

     plot(mr, ylim=c(18, 26))  # this shows the averaged data points
     points(age, size, pch=2)  # add original data points

     ###

     y = c(1,0,1,0,0,1,0,1,1,0,1,0)
     x = 1:length(y)
     mr = monoreg(y)

     # plot with greatest convex minorant
     plot(mr, plot.type="row.wise")  

     # this is the same
     mr = monoreg(x,y)
     plot(mr)

     # antitonic regression and least concave majorant
     mr = monoreg(-y, type="a")
     plot(mr, plot.type="row.wise")  

     # the fit yf is independent of the location of x and y
     plot(monoreg(x + runif(1, -1000, 1000), 
                  y +runif(1, -1000, 1000)) )

     ###

     y = c(0,0,2/4,1/5,2/4,1/2,4/5,5/8,7/11,10/11)
     x = c(5,9,13,18,22,24,29,109,120,131)

     mr = monoreg(x,y)
     plot(mr, plot.type="row.wise")

     # the fit (yf) only depends on the ordering of x
     monoreg(1:length(y), y)$yf 
     monoreg(x, y)$yf 

