shapereg {coneproj} | R Documentation |
Shape-Restricted Regression
Description
The regression model y_i = f(t_i) + x_i'\beta + \varepsilon_i, i = 1,\ldots,n
is considered, where the only assumptions about f
concern its shape. The vector expression for the model is y = \theta + X\beta + \varepsilon
. X
represents a parametrically modelled covariate, which could be a categorical covariate or a linear term. The shapereg function allows eight shapes: increasing, decreasing, convex, concave, increasing-convex, increasing-concave, decreasing-convex, and decreasing-concave. This routine employs a single cone projection to find \theta
and \beta
simultaneously.
Usage
shapereg(formula, data = NULL, weights = NULL, test = FALSE, nloop = 1e+4)
Arguments
formula |
A formula object which gives a symbolic description of the model to be fitted. It has the form "response ~ predictor". The response is a vector of length
|
data |
An optional data frame, list or environment containing the variables in the model. The default is data = NULL. |
weights |
An optional non-negative vector of "replicate weights" which has the same length as the response vector. If weights are not given, all weights are taken to equal 1. The default is weights = NULL. |
test |
The test parameter given by the user. |
nloop |
The number of simulations used to get the p-value for the |
Details
This routine constrains \theta
in the equation y = \theta + X\beta + \varepsilon
by a shape parameter.
The constraint cone C
has the form \{\phi: \phi = v + \sum b_i\delta_i, i = 1,\ldots,m, b_1,\ldots, b_m \ge 0 \}
, v
is in V
. The column vectors of X
are in V
, i.e., the linear space contained in the constraint cone.
The hypothesis test H_0: \phi
is in V
versus H_1: \phi
is in C
is an exact one-sided test, and the test statistic is E_{01} = (SSE_0 - SSE_1)/(SSE_0)
, which has a mixture-of-betas distribution when H_0
is true and \varepsilon
is a vector following a standard multivariate normal distribution with mean 0. The mixing parameters are found through simulations. The number of simulations used to obtain the mixing distribution parameters for the test is 10,000. Such simulations usually take some time. For the "feet" data set used as an example in this section, whose sample size is 39, the time to get a p-value is roughly between 4 seconds.
This routine calls coneB for the cone projection part.
Value
coefs |
The estimated coefficients for |
constr.fit |
The shape-restricted fit over the constraint cone |
linear.fit |
The least-squares regression of |
se.beta |
The standard errors for the estimation of the vector |
pval |
The p-value for the hypothesis test |
pvals.beta |
The approximate p-values for the estimation of the vector |
test |
The test parameter given by the user. |
SSE0 |
The sum of squared residuals for the linear part. |
SSE1 |
The sum of squared residuals for the full model. |
shape |
A number showing the shape constraint given by the user in a shapereg fit. |
tms |
The terms objects extracted by the generic function terms from a shapereg fit. |
zid |
A vector keeping track of the position of the parametrically modelled covariate. |
vals |
A vector storing the levels of each variable used as a factor. |
zid1 |
A vector keeping track of the beginning position of the levels of each variable used as a factor. |
zid2 |
A vector keeping track of the end position of the levels of each variable used as a factor. |
tnm |
The name of the shape-restricted predictor. |
ynm |
The name of the response variable. |
znms |
A vector storing the name of the parametrically modelled covariate. |
is_param |
A logical scalar showing if or not a variable is a parametrically modelled covariate, which could be a factor or a linear term. |
is_fac |
A logical scalar showing if or not a variable is a factor. |
xmat |
A matrix whose columns represent the parametrically modelled covariate. |
call |
The matched call. |
Author(s)
Mary C. Meyer and Xiyue Liao
References
Raubertas, R. F., C.-I. C. Lee, and E. V. Nordheim (1986) Hypothesis tests for normals means constrained by linear inequalities. Communications in Statistics - Theory and Methods 15 (9), 2809–2833.
Robertson, T., F. Wright, and R. Dykstra (1988) Order Restricted Statistical Inference New York: John Wiley and Sons.
Fraser, D. A. S. and H. Massam (1989) A mixed primal-dual bases algorithm for regression under inequality constraints application to concave regression. Scandinavian Journal of Statistics 16, 65–74.
Meyer, M. C. (2003) A test for linear vs convex regression function using shape-restricted regression. Biometrika 90(1), 223–232.
Cheng, G.(2009) Semiparametric additive isotonic regression. Journal of Statistical Planning and Inference 139, 1980–1991.
Meyer, M.C.(2013a) Semiparametric additive constrained regression. Journal of Nonparametric Statistics 25(3), 715–743.
Liao, X. and M. C. Meyer (2014) coneproj: An R package for the primal or dual cone projections with routines for constrained regression. Journal of Statistical Software 61(12), 1–22.
See Also
Examples
# load the feet data set
data(feet)
# extract the continuous and constrained predictor
l <- feet$length
# extract the continuous response
w <- feet$width
# extract the categorical covariate: sex
s <- feet$sex
# make an increasing fit with test set as FALSE
ans <- shapereg(w ~ incr(l) + factor(s))
# check the summary table
summary(ans)
# make an increasing fit with test set as TRUE
ans <- shapereg(w ~ incr(l) + factor(s), test = TRUE, nloop = 1e+3)
# check the summary table
summary(ans)
# make a plot comparing the unconstrained fit and the constrained fit
par(mar = c(4, 4, 1, 1))
ord <- order(l)
plot(sort(l), w[ord], type = "n", xlab = "foot length (cm)", ylab = "foot width (cm)")
title("Shapereg Example Plot")
# sort l according to sex
ord1 <- order(l[s == "G"])
ord2 <- order(l[s == "B"])
# make the scatterplot of l vs w for boys and girls
points(sort(l[s == "G"]), w[s == "G"][ord1], pch = 21, col = 1)
points(sort(l[s == "B"]), w[s == "B"][ord2], pch = 24, col = 2)
# make an unconstrained fit to boys and girls
fit <- lm(w ~ l + factor(s))
# plot the unconstrained fit
lines(sort(l), (coef(fit)[1] + coef(fit)[2] * l + coef(fit)[3])[ord], lty = 2)
lines(sort(l), (coef(fit)[1] + coef(fit)[2] * l)[ord], lty = 2, col = 2)
legend(21.5, 9.8, c("boy","girl"), pch = c(24, 21), col = c(2, 1))
# plot the constrained fit
lines(sort(l), (ans$constr.fit - ans$linear.fit + coef(ans)[1])[ord], col = 1)
lines(sort(l), (ans$constr.fit - ans$linear.fit + coef(ans)[1] + coef(ans)[2])[ord], col = 2)