R: Specify a Unimodal Category in a CHANGEPT Formula
tp
R Documentation
Specify a Unimodal Category in a CHANGEPT Formula
Description
A symbolic routine to define that the underlying mean curve is unimodal, i.e., it has a turn-around point, in the formula argument to changept.
Usage
tp(x, sh = 1)
Arguments
x
The predictor vector.
sh
If sh is 1, then the estimated curve is increasing-decreasing; if sh is -1, it is decreasing-increasing.
Value
"tp" returns the vector "x" with three attributes, i.e., nm: the name of x; categ: the category of the change-point, "mode"; sh: the shape constraint on the estimated curve: 1 (increasing-decreasing) or -1 (decreasing-increasing).
The nm and categ attributes are used in the plot routine; the sh attribute is used to set up a shape-constrained regression.
Author(s)
Xiyue Liao
See Also
ip, jp
Examples
# the underlying mean curve is unimodal with a mode at .8
n = 100
x = seq(1/n, 1, length = n)
# a categorical covariate z with two levels (0 and 1)
z = rep(0:1, 50)
set.seed(123)
y = 30 * x^4 * (1 - x) + (z == 1) * .5 + rnorm(n, sd = 1)
ans = changept(y ~ tp(x) + factor(z), family = gaussian())
plot(ans)
legend("topleft", "constrained fit for z == 1", bty = "n", col = "skyblue", lty = 2, lwd = 2)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(ShapeChange)
Loading required package: coneproj
Loading required package: quadprog
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ShapeChange/tp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: tp
> ### Title: Specify a Unimodal Category in a CHANGEPT Formula
> ### Aliases: tp
> ### Keywords: symbolic routine
>
> ### ** Examples
>
> # the underlying mean curve is unimodal with a mode at .8
> n = 100
> x = seq(1/n, 1, length = n)
>
> # a categorical covariate z with two levels (0 and 1)
> z = rep(0:1, 50)
>
> set.seed(123)
> y = 30 * x^4 * (1 - x) + (z == 1) * .5 + rnorm(n, sd = 1)
> ans = changept(y ~ tp(x) + factor(z), family = gaussian())
>
> plot(ans)
> legend("topleft", "constrained fit for z == 1", bty = "n", col = "skyblue", lty = 2, lwd = 2)
>
>
>
>
>
> dev.off()
null device
1
>