A symbolic routine to indicate that a predictor is included as a non-parametrically modelled predictor in a formula argument to ShapeSelect.
shapes(x, set = "s.9")
A numeric predictor which has the same length as the response vector.
A character or a numeric vector indicating all possible shapes defined for x. For example, we are not only interested in modeling the relationship between the growth of an organism (dependent variable y) and time (independent variable x), but we are also interested in the shape of the growth curve. Suppose we know a priori that the shape could be flat, increasing, increasing concave, or increasing convex, and we further know that the curve is smooth, we can write y ~ shapes(x, set = c("flat", "s.incr", "s.incr.conc", "s.incr.conv")) in a formula to impose the four possible shape constraints on the growth curve and model it with splines.
To be more specific, the user can choose to specify this argument as following
The default is set = "s.9".
The vector x with three attributes, i.e., nm: the name of x; shape: a numeric vector ranging from 0 to 16 to indicate possible shapes imposed on the relationship between the response and x; type: "nparam", i.e., x is non-parametrically modelled.
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
## Not run: # Example 1. n <- 100 # generate predictors, x is non-parametrically modelled # and z is parametrically modelled x <- runif(n) z <- rep(0:1, 50) # E(y) is generated as correlated to both x and z # the relationship between E(y) and x is smoothly increasing-convex y <- x^2 + 2 * I(z == 1) + rnorm(n, sd = 1) # call ShapeSelect to find the best model by the genetic algorithm fit <- ShapeSelect(y ~ shapes(x) + in.or.out(factor(z)), genetic = TRUE) # Example 2. n <- 100 z <- rep(c("A","B"), n / 2) x <- runif(n) # y0 is generated as correlated to z with a tree-ordering in it # y0 is smoothly increasing-convex in x y0 <- x^2 + I(z == "B") * 1.5 y <- y0 + rnorm(n, 1) fit <- ShapeSelect(y ~ s.incr(x) + shapes(z, set = "tree"), genetic = FALSE) # check the best fit in terms of z fit$top ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.