bug in bhist() when limits are specified within bhist()
sbrockhaus opened this issue · 3 comments
sbrockhaus commented
@davidruegamer raised the following bug that only occurs in bhist()
when limits
is specified as function within bhist()
and the argument s
is not called s, see
library(FDboost)
library(refund)
############################################
# model with functional historical effect, use bhist()
# Y(t) = f(t) + \int_0^t X1(s)\beta(s,t)ds + eps
set.seed(2121)
mylimits <- function(s, t){
(s < t) | (s == t)
}
data2 <- pffrSim(scenario = "ff", n = 40, limits = mylimits)
data2$X1 <- scale(data2$X1, scale = FALSE)
dat2_list <- as.list(data2)
dat2_list$myt <- attr(data2, "yindex")
dat2_list$mys <- attr(data2, "xindex")
## works
m1 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = mylimits),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
## bug
m2 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(s, t){(s < t) | (s == t)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
sbrockhaus commented
The problem is that in a check, s and t cannot be found. A solution is to rename the arguments of the limits-function.
## works
m2 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5,
limits = function(mys, myt){(mys < myt) | (mys == myt)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
sbrockhaus commented
Make sure that all the following code works.
library(FDboost)
library(refund)
############################################
# model with functional historical effect, use bhist()
# Y(t) = f(t) + \int_0^t X1(s)\beta(s,t)ds + eps
set.seed(2121)
mylimits <- function(s, t){
(s < t) | (s == t)
}
data2 <- pffrSim(scenario = "ff", n = 40, limits = mylimits)
data2$X1 <- scale(data2$X1, scale = FALSE)
dat2_list <- as.list(data2)
dat2_list$myt <- attr(data2, "yindex")
dat2_list$mys <- attr(data2, "xindex")
dat2_list$X2 <- scale(data2$X1, scale = FALSE) + rnorm(40*40)
dat2_list$myt2 <- attr(data2, "yindex")
dat2_list$mys2 <- attr(data2, "xindex")
### with one bhist-bl
m1 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = mylimits),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m2 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(s, t){(s < t)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m3 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5,
limits = function(mys, myt){(mys < myt) | (mys == myt)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m4 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(xx, yy){(xx < yy)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m5 <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(mys, yy){(mys < yy)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
### with two bhist-bl
m1b <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = mylimits) +
bhist(x = X2, s = mys2, time = myt2, knots = 5, limits = mylimits),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m2b <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(s, t){(s < t)}) +
bhist(x = X2, s = mys, time = myt, knots = 5, limits = function(s, t){(s < t)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m3b <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5,
limits = function(mys, myt){(mys < myt) | (mys == myt)})
+ bhist(x = X2, s = mys2, time = myt, knots = 5,
limits = function(mys, myt){(mys < myt) | (mys == myt)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m4b <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(xx, yy){(xx < yy)})
+ bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(xx, yy){(xx < yy)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m4c <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(xx, yy){(xx < yy)})
+ bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(xx2, yy2){(xx2 < yy2)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
m5b <- FDboost(Y ~ 1 + bhist(x = X1, s = mys, time = myt, knots = 5, limits = function(mys, yy){(mys < yy)})
+ bhist(x = X2, s = mys, time = myt, knots = 5, limits = function(mys, yy){(mys < yy)}),
timeformula = ~ bbs(myt, knots = 5), data = dat2_list,
control = boost_control(mstop = 40))
sbrockhaus commented
still TODO: fix the same issue for bhistx()