This function provides an estimate of the non-parametric regression function with a shape constraint of convexity and smoothness constraint provided through square integral of second derivative.
cvx.pen.reg(x, y, lambda, w = NULL, tol = 1e-5, maxit = 1000)# S3 method for cvx.pen.reg
plot(x, ylab = quote(y ~ "and" ~ hat(y) ~ " values"),
main = sprintf("Convex Regression using\n Penalized Least Squares (lambda=%.4g)",
x$lambda),
pch = "*", cex = 1, lwd = 2, col2 = "red", ablty = 4, ...)
# S3 method for cvx.pen.reg
print(x, digits = getOption("digits"), ...)
# S3 method for cvx.pen.reg
predict(object, newdata = NULL,...)
An object of class cvx.pen.reg, basically a list including the elements
sorted x values provided as input.
corresponding y values in input.
corresponding fit values of same length as that of x.values.
corresponding values of the derivative of same length as that of x.values.
number of steps taken to complete the iterations.
residuals obtained from the fit.
minimum value of the objective function attained.
a numeric indicating the convergence of the code.
a numeric vector of length 2 less than x. This
represents the coefficients of the B-splines in the second derivative
of the estimator.
a numeric vector needed for predict function.
a numeric vector needed for predict function.
a numeric vector needed for predict function.
a numeric vector giving the values of the predictor variable.
For plot and print functions, x is an object of
class "cvx.pen.reg".
a numeric vector giving the values of the response variable.
a nonnegative number, the penalty value aka ‘smoothing parameter’.
an optional numeric vector of the same length as x; defaults to all 1.
non-negative number, the tolerance level for convergence.
an integer giving the maxmimum number of steps taken by the algorithm; defaults to 1000.
further optional argument to the
plot() method; the last two for the color and line type of
some plot components.
any additional arguments, passed, e.g., to lower level plotting functions.
the number of significant digits, for numbers in the
print() method.
an object of class "cvx.pen.reg"; for the predict() method.
a vector of new data points to be used in predict().
Arun Kumar Kuchibhotla, arunku@wharton.upenn.edu, Rohit Kumar Patra, rohit@stat.columbia.edu.
The function minimizes $$\sum_{i=1}^n w_i(y_i - f(x_i))^2 + \lambda\int\{f''(x)\}^2dx$$ subject to convexity constraint on \(f\).
plot function provides the scatterplot along with fitted curve; it
also includes some diagnostic plots for residuals. Predict function
returns a matrix containing the inputted newdata along with the function
values, derivatives and second derivatives.
args(cvx.pen.reg)
x <- runif(50,-1,1)
y <- x^2 + rnorm(50,0,0.3)
tmp <- cvx.pen.reg(x, y, lambda = 0.01)
print(tmp)
plot(tmp)
predict(tmp, newdata = rnorm(10,0,0.1))
Run the code above in your browser using DataLab