# NOT RUN {
data("BostonHousing2", package = "mlbench")
### unconstrained regression coefficients
### BoxCox calls tram internally
m1 <- BoxCox(cmedv ~ chas + crim + zn + indus + nox +
rm + age + dis + rad + tax + ptratio + b + lstat,
data = BostonHousing2)
### now with two constraints on regression coefficients
m2 <- BoxCox(cmedv ~ chas + crim + zn + indus + nox +
rm + age + dis + rad + tax + ptratio + b + lstat,
data = BostonHousing2,
constraints = c("crim >= 0", "chas1 + rm >= 1.5"))
coef(m1)
coef(m2)
K <- matrix(0, nrow = 2, ncol = length(coef(m2)))
colnames(K) <- names(coef(m2))
K[1, "crim"] <- 1
K[2, c("chas1", "rm")] <- 1
m3 <- BoxCox(cmedv ~ chas + crim + zn + indus + nox +
rm + age + dis + rad + tax + ptratio + b + lstat,
data = BostonHousing2,
constraints = list(K, c(0, 1.5)))
all.equal(coef(m2), coef(m3))
# }
Run the code above in your browser using DataLab