Learn R Programming

simest (version 0.4)

cvx.pen.reg:

Description

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.

Usage

cvx.pen.reg(x, y, lambda, w = NULL, tol = 1e-05, maxit = 1000,...)
# S3 method for default
cvx.pen.reg(x, y, lambda, w = NULL, tol = 1e-05, maxit = 1000,...)
# S3 method for cvx.pen.reg
plot(x,...)
# S3 method for cvx.pen.reg
print(x,...)
# S3 method for cvx.pen.reg
predict(object, newdata = NULL,...)

Arguments

x
a numeric vector giving the values of the predictor variable. For plot and print functions, x represents an object of class cvx.pen.reg.
y
a numeric vector giving the values of the response variable.
lambda
a numeric value giving the penalty value.
w
an optional numeric vector of the same length as x; Defaults to all 1.
maxit
an integer giving the maxmimum number of steps taken by the algorithm; defaults to 1000.
tol
a numeric providing the tolerance level for convergence.
...
any additional arguments.
object
An object of class `cvx.pen.reg'. This is for predict function.
newdata
a vector of new data points to be used in the predict function.

Value

An object of class `cvx.pen.reg', basically a list including the elements
x.values
sorted `x' values provided as input.
y.values
corresponding `y' values in input.
fit.values
corresponding fit values of same length as that of `x.values'.
deriv
corresponding values of the derivative of same length as that of `x.values'.
iter
number of steps taken to complete the iterations.
residuals
residuals obtained from the fit.
minvalue
minimum value of the objective function attained.
convergence
a numeric indicating the convergence of the code.
alpha
a numeric vector of length 2 less than `x'. This represents the coefficients of the B-splines in the second derivative of the estimator.
AlphaMVal
a numeric vector needed for predict function.
lower
a numeric vector needed for predict function.
upper
a numeric vector needed for predict function.

Details

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.

Examples

Run this code
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