Description Usage Arguments Details Value Author(s) References See Also Examples
The regression model y_i = f(t_i) + x_i'β + \varepsilon_i, i = 1,…,n is considered, where the only assumptions about f concern its shape. The vector expression for the model is y = θ + Xβ + \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, increasingconvex, increasingconcave, decreasingconvex, and decreasingconcave. This routine employs a single cone projection to find θ and β simultaneously.
1 
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 n. A predictor can be a nonparametrically modelled variable with a shape restriction or a parametrically modelled unconstrained covariate. In terms of a nonparametrically modelled predictor, the user is supposed to indicate the relationship between E(y) and a predictor t in the following way:

data 
An optional data frame, list or environment containing the variables in the model. The default is data = NULL. 
weights 
An optional nonnegative 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 pvalue for the E_{01} test. The default is 1e+4. 
This routine constrains θ in the equation y = θ + Xβ + \varepsilon by a shape parameter.
The constraint cone C has the form \{φ: φ = v + ∑ b_iδ_i, i = 1,…,m, b_1,…, b_m ≥ 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: φ is in V versus H_1: φ is in C is an exact onesided test, and the test statistic is E_{01} = (SSE_0  SSE_1)/(SSE_0), which has a mixtureofbetas 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 pvalue is roughly between 4 seconds.
This routine calls coneB for the cone projection part.
coefs 
The estimated coefficients for X, i.e., the estimation for the vector β. Note that even if the user does not provide a constant vector in X, the coefficient for the intercept will be returned. 
constr.fit 
The shaperestricted fit over the constraint cone C of the form \{φ: φ = v + ∑ b_iδ_i, i = 1,…,m, b_1,…, b_m ≥ 0 \}, v is in V. 
linear.fit 
The leastsquares regression of y on V, i.e., the linear space contained in the constraint cone. If shape is 3 or shape is 4, V is spanned by X and t. Otherwise, it is spanned by X. X must be full column rank, and the matrix formed by combining X and t must also be full column rank. 
se.beta 
The standard errors for the estimation of the vector β. The degree of freedom is returned by coneB and is multiplied by 1.5. Note that even if the user does not provide a constant vector in X, the standard error for the intercept will be returned. 
pval 
The pvalue for the hypothesis test H_0: φ is in V versus H_1: φ is in C. C is the constraint cone of the form \{φ: φ = v + ∑ b_iδ_i, i = 1,…,m, b_1,…, b_m ≥ 0 \}, v is in V, and V is the linear space contained in the constraint cone. If test == TRUE, a pvalue is returned. Otherwise, the test is skipped and no pvalue is returned. 
pvals.beta 
The approximate pvalues for the estimation of the vector β. A tdistribution is used as the approximate distribution. Note that even if the user does not provide a constant vector in X, the approximate pvalue for the intercept will be returned. 
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. See the official help page (http://stat.ethz.ch/Rmanual/Rpatched/library/stats/html/terms.html) of the terms function for more details. 
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 shaperestricted 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. 
Mary C. Meyer and Xiyue Liao
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 primaldual 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 shaperestricted 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  # 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)

Call:
shapereg(formula = w ~ incr(l) + factor(s))
Coefficients:
Estimate StdErr t.value p.value
(Intercept) 9.1106 0.0996 91.4416 <2e16 ***
factor(s)G 0.2428 0.1493 1.6266 0.1172

Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
++
 SSE.Linear vs SSE.Full 
++
SSE.Linear SSE.Full
8.5221 4.251
Call:
shapereg(formula = w ~ incr(l) + factor(s), test = TRUE, nloop = 1000)
Coefficients:
Estimate StdErr t.value p.value
(Intercept) 9.1106 0.0996 91.4416 <2e16 ***
factor(s)G 0.2428 0.1493 1.6266 0.1172

Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
++
 SSE.Linear vs SSE.Full 
++
SSE.Linear SSE.Full P.value.f(t)
8.5221 4.2513 0.0001513 ***

Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.