if (FALSE) {
n <- 100
# x is a continuous predictor
x <- runif(n)
# generate z and to include it as a categorical predictor
z <- rep(0:1, 50)
# y is generated as correlated to both x and z
# the relationship between 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
# factor(z) may be in or out of the model
fit <- ShapeSelect(y ~ shapes(x) + in.or.out(factor(z)), genetic = TRUE)
# factor(z) isn't chosen and is included in the model
fit <- ShapeSelect(y ~ shapes(x) + factor(z), genetic = TRUE)
}
Run the code above in your browser using DataLab