# load auto data
data(auto)
# additive effects
x <- rk.model.matrix(mpg ~ ., data = auto)
dim(x) # check dimensions
attr(x, "assign") # check group assignments
attr(x, "term.labels") # check term labels
# two-way interactions
x <- rk.model.matrix(mpg ~ . * ., data = auto)
dim(x) # check dimensions
attr(x, "assign") # check group assignments
attr(x, "term.labels") # check term labels
# specify df for horsepower, weight, and acceleration
# note: default df = 5 is used for displacement and model.year
df <- list(horsepower = 6, weight = 7, acceleration = 8)
x <- rk.model.matrix(mpg ~ ., data = auto, df = df)
sapply(attr(x, "knots"), length) # check df
# specify knots for model.year
# note: default knots are selected for other variables
knots <- list(model.year = c(1970, 1974, 1978, 1982))
x <- rk.model.matrix(mpg ~ ., data = auto, knots = knots)
sapply(attr(x, "knots"), length) # check df
Run the code above in your browser using DataLab