concon             package:DierckxSpline             R Documentation

_C_u_r_v_e _f_i_t_t_i_n_g _w_i_t_h _c_o_n_v_e_x_i_t_y _c_o_n_s_t_r_a_i_n_t_s

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

     General curve fitting with splines with convexity constraints.
     Wrapper for the Fortran function CONCON.

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

     concon(x, ...)
     ## Default S3 method:
     concon(x, y = NULL, w = NULL, v = 0, s = 0, ...)

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

       x: A 'data.frame', 'matrix', or 'numeric' vector. See details.

       y: Optional numeric vector. See details.

       w: Optional vector of weights

       v: Convexity constraints. See details.

       s: Smoothing parameter

     ...: Additional arguments used only in 'update.concon'. Otherwise,
          ignored.

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

     As with 'smooth.spline', the 'x' vector should contain at least
     four distinct values. _Distinct_ here means ``distinct after
     rounding to 6 significant digits'', i.e., 'x' will be transformed
     to 'unique(sort(signif(x, 6)))', and 'y', 'w', and 'v' are pooled
     accordingly.

     For the default method, arguments 'x' and 'y' are supplied to
     'xy.coords' to determine abscissa and ordinate values. The actual
     function used is 'DierckxSpline:::xyw.coords' which is not
     exported in the 'NAMESPACE'.

     'concon' determines a smooth cubic spline approximation 's(x)'.
     See chapters 1 and 3 in the reference for definition of symbols.

     The vector 'v' should be the same length as 'x'. 'v[i]' must be
     set to '1' if 's(x)' must be locally concave at 'x[i]', to '-1' if
     's(x)' must be locally convex at 'x[i]' and to '0' if no convexity
     constraint is imposed at 'x[i]'. If all 'v' are 0 (no consraints)
     an error is thrown suggesting the use of 'curfit' instead.

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

     An object of class 'dierckx' with the following components: 

    iopt: method used

       m: length of 'x'

       x: abscissa values

       y: ordinate values

       w: input weights

       s: input smoothing parameter

    nest: Estimated number of knots

       n: Actual number of knots

   knots: Knot locations. Do NOT modify before call to 'update.dierckx'

       g: Number of interior knots

    coef: b-Spline coefficients. Use 'coef.dierckx' to extract.

      fp: sum of squares residuals. Use 'deviance.dierckx' to extract.

     wrk: Work space. Do NOT modify before call to 'update.dierckx'

    lwrk: Length of 'wrk'. Do NOT modify before call to
          'update.dierckx'

    iwrk: Integer work space. Do NOT modify before call to
          'update.dierckx'

    kwrk: Length of 'iwrk'. Do NOT modify before call to
          'update.dierckx'

    bind: Indicates the knots where 's''(x)=0'. Do NOT modify before
          call to 'update.dierckx'

      sx: Indicates the knots where 's''(x)=0'. Do NOT modify before
          call to 'update.dierckx'

     ier: Error code. Should always be zero.

  method: input 'method' value

       k: Always 3 (cubic spline)

periodic: Always 'FALSE'

 routine: Always 'concon.default'

    xlab: The x-label determined from 'deparse(substitute(x)).' 

    ylab: The y-label determined from 'deparse(substitute(y)).' 

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

     Sundar Dorai-Raj

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

     Dierckx, P. (1991) _Curve and Surface Fitting with Splines_,
     Oxford Science Publications.

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

     'curfit', 'spline', 'smooth.spline'

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

     data(moisture)
     f1 <- with(moisture, concon(x, y, w, v, s = 0.2))
     f2 <- update(f1, s = 0.04)
     f3 <- update(f1, s = 0.0002)
     g1 <- with(moisture, curfit(x, y, w, knots = knots(f1, interior=FALSE)))
     #must include end knots, via interior = FALSE 
     g2 <- update(g1, knots = knots(f2, FALSE))
     g3 <- update(g1, knots = knots(f3, FALSE))

     newx <- with(moisture, seq(min(x), max(x), length = 100))
     method <- c("Convexity Constrained", "Unconstrained Least Squares")
     group <- c("0 interior knots", "1 interior knot", "3 interior knots")
     out <- data.frame(x = rep(newx, times = 6),
              y = c(predict(f1, newx), predict(f2, newx),
                    predict(f3, newx), predict(g1, newx),
                    predict(g2, newx), predict(g3, newx)),
              group = rep(group, each = 100, times = 2),
              method = rep(method, each = 3 * 100))

     library(lattice)
     xyplot(y ~ x | method, out, groups = group, panel = function(...) {
              panel.superpose(...)
              panel.xyplot(moisture$x, moisture$y,
                           col = "#800000", pch = 16, cex = 1.2)
            },
            xlim = c(-1, 11), xlab = "", ylab = "", layout = c(1, 2),
            as.table = TRUE, scales = list(cex = 1.2), 
            par.strip.text = list(cex = 1.5), type = "l", lwd = 3,
            key = list(space = "top", cex = 1.2, columns = 3,
              text = list(levels(out$group)),
              lines = list(lwd = 3, col = trellis.par.get("superpose.line")$col[1:3])))

