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

options("mboost_indexmin") and bhistx() gives errors in coef() #10

Closed
sbrockhaus opened this issue May 10, 2017 · 5 comments
Closed

options("mboost_indexmin") and bhistx() gives errors in coef() #10

sbrockhaus opened this issue May 10, 2017 · 5 comments

Comments

@sbrockhaus
Copy link
Member

@sbrockhaus sbrockhaus commented May 10, 2017

If internally an index is used for model fitting for a model containing bhistx() some methods, e.g., coef(), no longer work:

library(FDboost)

options("mboost_indexmin")

require(refund))
## simulate some data from a historical model
## the interaction effect is in this case not necessary
n <- 100
nygrid <- 35
data1 <- pffrSim(scenario = c("int", "ff"), limits = function(s,t){ s <= t }, 
                 n = n, nygrid = nygrid)
data1$X1 <- scale(data1$X1, scale = FALSE) ## center functional covariate                  
dataList <- as.list(data1)
dataList$tvals <- attr(data1, "yindex")

## create the hmatrix-object
X1h <- with(dataList, hmatrix(time = rep(tvals, each = n), id = rep(1:n, nygrid), 
                              x = X1, argvals = attr(data1, "xindex"), 
                              timeLab = "tvals", idLab = "wideIndex", 
                              xLab = "myX", argvalsLab = "svals"))
dataList$X1h <- I(X1h)   
dataList$svals <- attr(data1, "xindex")


#################################

options("mboost_indexmin" = 10000)

## do the model fit with main effect of bhistx() and interaction of bhistx() and bolsc()
mod <- FDboost(Y ~ bhistx(x = X1h, df = 5, knots = 5), 
               timeformula = ~ bbs(tvals, knots = 10), data = dataList)

coef_mod <- coef(mod)


###################################

options("mboost_indexmin" = 10)

## do the model fit with main effect of bhistx() and interaction of bhistx() and bolsc()
mod2 <- FDboost(Y ~ bhistx(x = X1h, df = 5, knots = 5), 
               timeformula = ~ bbs(tvals, knots = 10), data = dataList)

### breaks within predict
coef_mod2 <- coef(mod2)

@davidruegamer
Copy link
Member

@davidruegamer davidruegamer commented May 11, 2017

I still haven't figured out, where the rub is, but maybe we could just set options("mboost_indexmin" = 10000) in coef ? Because this does not throw an error:

options("mboost_indexmin" = 10000)

coef_mod2 <- coef(mod2)

even if mod2 was fitted using options("mboost_indexmin" = 10) 🙃

@davidruegamer
Copy link
Member

@davidruegamer davidruegamer commented May 11, 2017

PS: The error is due to the fact, that get_index does not work with hmatrix objects. In detail, if we use the mentioned option, we try to apply get_index to an object like this:

'data.frame':	1600 obs. of  4 variables:
 $ X1h    : AsIs [1:1600, 1:2] 0 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  ..- attr(*, "x")= num [1:40, 1:40] 39 0 0 0 0 0 0 0 0 0 ...
  ..- attr(*, "argvals")= num  0 0.0256 0.0513 0.0769 0.1026 ...
  ..- attr(*, "timeLab")= chr "t"
  ..- attr(*, "idLab")= chr "wideIndex"
  ..- attr(*, "xLab")= chr "x"
  ..- attr(*, "argvalsLab")= chr "s"
  ..- attr(*, "class")= chr  "AsIs" "hmatrix" "matrix"
 $ tvals  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ONEx   : num  1 1 1 1 1 1 1 1 1 1 ...
 $ ONEtime: num  1 1 1 1 1 1 1 1 1 1 ...
 - attr(*, "varnms")= chr  "svals" "tvals"
 - attr(*, "xm")= num  0 0.0256 0.0513 0.0769 0.1026 ...
 - attr(*, "ym")= num  0 0.0256 0.0513 0.0769 0.1026 ...
 - attr(*, "myargsHist")=List of 23

But you said something like that it isn't a problem for bhist (without x) baselearners? That would be odd.

@davidruegamer
Copy link
Member

@davidruegamer davidruegamer commented May 11, 2017

Since the error is caused by bl[[w]]$predict(ens[ix], newdata = newdata, aggregate = agg) in bl_lin, I think we do not have a choice, but to either redefine indexmin automatically when predict is called for such objects or throw an error and recommend to set indexmin to a larger value. All other options involve a complete restructuring of our hmatrix concept. A generic get_index function for hmatrixobjects, for example, won't work, as the object, which we pass to get_index is an ordinary data.frame.

@sbrockhaus
Copy link
Member Author

@sbrockhaus sbrockhaus commented May 11, 2017

For models with response in long format, "FDboostLong", even more methods break. bhist() is no problem as long as the model has a response matrix and not a response in long format.
As the option is not helpful for functional covariates (it uses ties in the data to speed up computations and ties seem very unlikely in case of functional covariates), we decided to set the option to +Inf within FDboost.

@sbrockhaus
Copy link
Member Author

@sbrockhaus sbrockhaus commented May 11, 2017

@sbrockhaus sbrockhaus closed this May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.