Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monotonic interactions with ordinal variables #73

Open
hofnerb opened this issue Mar 13, 2017 · 0 comments
Open

Fix monotonic interactions with ordinal variables #73

hofnerb opened this issue Mar 13, 2017 · 0 comments

Comments

@hofnerb
Copy link
Member

hofnerb commented Mar 13, 2017

## monotonicity with interaction and factor
library("mboost")

## simulate some data
set.seed(1234)
x1 <- rnorm(1000)
x2 <- sample(1:5, 1000, replace = TRUE)
y <- -x1^3 * (6 - x2) + rnorm(1000, sd = 0.1)
x2 <- as.factor(x2)

## Works with numeric values
x2 <- as.numeric(x2)
mod <- mboost(y ~ bmono(x1, x2, df = 5, constraint = list("decreasing", "increasing")), 
              control = boost_control(trace = TRUE, mstop = 10))
plot(mod)

## Interaction currently does not work with ordinals
x2 <- as.ordered(x2)

## Does work as single effect
mod2 <- mboost(y ~ bmono(x2, constraint = "decreasing"))
plot(mod2)

## Doesn't work
mod3 <- mboost(y ~ bmono(x1, x2, df = 5, constraint = list("decreasing", "increasing")), 
               control = boost_control(trace = TRUE, mstop = 10))
##  Error in seq.default(boundary.knots[1] - degree * dx, boundary.knots[1],  : 
##  'from' cannot be NA, NaN or infinite 

Of note:

x1 <- as.ordered(x1)
x2 <- as.ordered(x2)
mod <- mboost(y ~ bmono(x1, x2, constraint = list("decreasing", "increasing")))
##  Error in bl_mono(ret, Xfun = X_ols, args = args) : 
##  Bivariate monotonic effects currently not implemented for ordered factors 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant