@@ -172,7 +172,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
172172 stop(" The folds-matrix must have one row per observed trajectory." )
173173 }
174174
175- if (any(class( object ) == " FDboostLong" )){ # irregular response
175+ if (inherits( object , " FDboostLong" )){ # irregular response
176176 nObs <- length(unique(object $ id )) # number of curves
177177 Gy <- NULL # number of time-points per curve
178178 }else { # regular response / scalar response
@@ -201,7 +201,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
201201 }else {
202202
203203 if (numInt == " Riemann" ){ # use the integration scheme specified in applyFolds
204- if (! any(class( object ) == " FDboostLong" )){
204+ if (! inherits( object , " FDboostLong" )){
205205 integration_weights <- as.vector(integrationWeights(X1 = matrix (object $ response ,
206206 ncol = object $ ydim [2 ]), object $ yind ))
207207 }else {
@@ -216,7 +216,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
216216
217217 # ## get yind in long format
218218 yindLong <- object $ yind
219- if (! any(class( object ) == " FDboostLong" )){
219+ if (! inherits( object , " FDboostLong" )){
220220 yindLong <- rep(object $ yind , each = nObs )
221221 }
222222 # ## compute ("length of each trajectory")^-1 in the response
@@ -255,7 +255,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
255255 }
256256 }
257257
258- if (! any(class( object ) == " FDboostLong" ) && ! any(class( object ) == " FDboostScalar" )){
258+ if (! inherits( object , " FDboostLong" ) && ! inherits( object , " FDboostScalar" )){
259259 dathelp [[object $ yname ]] <- matrix (object $ response , ncol = object $ ydim [2 ])
260260 dathelp $ integration_weights <- matrix (integration_weights , ncol = object $ ydim [2 ])
261261 dathelp $ object_id <- object $ id
@@ -279,13 +279,13 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
279279 names_variables <- names_variables [names_variables != nameyind ]
280280 names_variables <- names_variables [names_variables != " ONEx" ]
281281 names_variables <- names_variables [names_variables != " ONEtime" ]
282- if (! any(class( object ) == " FDboostLong" )) names_variables <- c(object $ yname , " integration_weights" , names_variables )
282+ if (! inherits( object , " FDboostLong" )) names_variables <- c(object $ yname , " integration_weights" , names_variables )
283283
284- length_variables <- if (" FDboostScalar" %in% class( object ))
284+ length_variables <- if (inherits( object , " FDboostScalar" ))
285285 lapply(dathelp [names_variables ], length ) else
286286 lapply(dathelp [names_variables ], NROW )
287287 names_variables_long <- names_variables [ length_variables == length(object $ id ) ]
288- nothmatrix <- ! sapply(dathelp [names_variables_long ], function ( x ) any(class( x ) == " hmatrix" ) )
288+ nothmatrix <- ! sapply(dathelp [names_variables_long ], is. hmatrix )
289289 names_variables_long <- names_variables_long [ nothmatrix ]
290290 if (identical(names_variables_long , character (0 ))) names_variables_long <- NULL
291291
@@ -330,7 +330,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
330330 fitfct <- function (weights , oobweights ){
331331
332332 # # get data according to weights
333- if (any(class( object ) == " FDboostLong" )){
333+ if (inherits( object , " FDboostLong" )){
334334 dat_weights <- reweightData(data = dathelp , vars = names_variables ,
335335 longvars = c(object $ yname , nameyind , " integration_weights" , names_variables_long ),
336336 weights = weights , idvars = c(attr(object $ id , " nameid" ), index_names ),
@@ -403,7 +403,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
403403 }
404404
405405 # # get data according to oobweights
406- if (any(class( object ) == " FDboostLong" )){
406+ if (inherits( object , " FDboostLong" )){
407407 dathelp $ lengthTi1 <- c(lengthTi1 )
408408 dat_oobweights <- reweightData(data = dathelp , vars = c(names_variables , " lengthTi1" ),
409409 longvars = c(object $ yname , nameyind ,
@@ -449,7 +449,7 @@ applyFolds <- function(object, folds = cv(rep(1, length(unique(object$id))), typ
449449 invokeRestart( " muffleWarning" )
450450 }
451451
452- if (any(class( object ) == " FDboostLong" )){
452+ if (inherits( object , " FDboostLong" )){
453453
454454 if (numInt == " equal" ){
455455 oobwstand <- dat_oobweights $ integration_weights * (1 / sum(dat_oobweights $ integration_weights ))
@@ -715,7 +715,7 @@ validateFDboost <- function(object, response = NULL,
715715 stop(" The folds-matrix must have one row per observed trajectory." )
716716 }
717717
718- if (any(class( object ) == " FDboostLong" )){ # irregular response
718+ if (inherits( object , " FDboostLong" )){ # irregular response
719719 nObs <- length(unique(object $ id )) # number of curves
720720 Gy <- NULL # number of time-points per curve
721721 }else { # regular response / scalar response
@@ -739,7 +739,7 @@ validateFDboost <- function(object, response = NULL,
739739 # intWeights <- model.weights(object)
740740 # weights are rescaled in mboost, see mboost:::rescale_weights
741741 if (! is.null(object $ callEval $ numInt ) && object $ callEval $ numInt == " Riemann" ){
742- if (! any(class( object ) == " FDboostLong" )){
742+ if (! inherits( object , " FDboostLong" )){
743743 intWeights <- as.vector(integrationWeights(X1 = matrix (object $ response ,
744744 ncol = object $ ydim [2 ]), object $ yind ))
745745 }else {
@@ -761,7 +761,7 @@ validateFDboost <- function(object, response = NULL,
761761
762762 # ## get yind in long format
763763 yindLong <- object $ yind
764- if (! any(class( object ) == " FDboostLong" )){
764+ if (! inherits( object , " FDboostLong" )){
765765 yindLong <- rep(object $ yind , each = nObs )
766766 }
767767 # ## compute ("length of each trajectory")^-1 in the response
@@ -783,7 +783,7 @@ validateFDboost <- function(object, response = NULL,
783783 nameyind <- attr(object $ yind , " nameyind" )
784784 dathelp [[nameyind ]] <- object $ yind
785785
786- if (! any(class( object ) == " FDboostLong" ) && ! any(class( object ) == " FDboostScalar" )){
786+ if (! inherits( object , " FDboostLong" ) && ! inherits( object , " FDboostScalar" )){
787787 dathelp [[object $ yname ]] <- matrix (object $ response , ncol = Gy )
788788 }else {
789789 dathelp [[object $ yname ]] <- object $ response
@@ -801,7 +801,7 @@ validateFDboost <- function(object, response = NULL,
801801 # call$control <- boost_control(risk="oobag")
802802 # call$oobweights <- oobweights[id]
803803 if (refitSmoothOffset == FALSE && is.null(call $ offset ) ){
804- if (! any(class( object ) == " FDboostLong" )){
804+ if (! inherits( object , " FDboostLong" )){
805805 call $ offset <- matrix (object $ offset , ncol = Gy )[1 , ]
806806 }else {
807807 call $ offset <- object $ offset
@@ -908,7 +908,7 @@ validateFDboost <- function(object, response = NULL,
908908 # str(modRisk, max.level=5)
909909
910910 # check whether model fit worked in all iterations
911- modFitted <- sapply(modRisk , function ( x ) class( x ) == " list" )
911+ modFitted <- sapply(modRisk , is. list )
912912 if (any(! modFitted )){
913913
914914 # stop() or warning()?
@@ -962,7 +962,7 @@ validateFDboost <- function(object, response = NULL,
962962 oobpreds0 <- lapply(modRisk , function (x ) x $ predGrid )
963963 oobpreds <- matrix (nrow = nrow(oobpreds0 [[1 ]]), ncol = ncol(oobpreds0 [[1 ]]))
964964
965- if (any(class( object ) == " FDboostLong" )){
965+ if (inherits( object , " FDboostLong" )){
966966 for (i in seq_along(oobpreds0 )){ # i runs over observed trajectories, i.e. over id
967967 oobpreds [id == i , ] <- oobpreds0 [[i ]][id == i , ]
968968 }
@@ -1068,7 +1068,7 @@ validateFDboost <- function(object, response = NULL,
10681068 # offset is vector of length yind or numeric of length 1 for constant offset
10691069 ret <- modRisk [[g ]]$ mod [optimalMstop ]$ predictOffset(object $ yind )
10701070 # regular data or scalar response
1071- if (! any(class( object ) == " FDboostLong" )){
1071+ if (! inherits( object , " FDboostLong" )){
10721072 if ( length(ret ) == 1 ) ret <- rep(ret , modRisk [[1 ]]$ mod $ ydim [2 ])
10731073 # irregular data
10741074 }else {
@@ -1077,13 +1077,13 @@ validateFDboost <- function(object, response = NULL,
10771077 }else { # other effects
10781078 ret <- predict(modRisk [[g ]]$ mod [optimalMstop ], which = l - 1 ) # model g
10791079 if (! (l - 1 ) %in% selected(modRisk [[g ]]$ mod [optimalMstop ]) ){ # effect was never chosen
1080- if (! any(class( object ) == " FDboostLong" )){
1080+ if (! inherits( object , " FDboostLong" )){
10811081 ret <- matrix (0 , ncol = modRisk [[1 ]]$ mod $ ydim [2 ], nrow = modRisk [[1 ]]$ mod $ ydim [1 ])
10821082 }else {
10831083 ret <- matrix (0 , nrow = length(object $ id ), ncol = 1 )
10841084 }
10851085 }
1086- if (! any(class( object ) == " FDboostLong" )){
1086+ if (! inherits( object , " FDboostLong" )){
10871087 ret <- ret [g ,] # save g-th row = preds for g-th observations
10881088 }else {
10891089 ret <- ret [object $ id == g ] # save preds of g-th observations
@@ -1112,7 +1112,7 @@ validateFDboost <- function(object, response = NULL,
11121112 oobrisk0 = oobrisk0 ,
11131113 oobmse0 = oobmse0 ,
11141114 oobmrd0 = oobmrd0 ,
1115- format = if (any(class( object ) == " FDboostLong" )) " FDboostLong" else " FDboost" ,
1115+ format = if (inherits( object , " FDboostLong" )) " FDboostLong" else " FDboost" ,
11161116 fun_ret = if (is.null(fun )) NULL else lapply(modRisk , function (x ) x $ fun_ret ) )
11171117
11181118 rm(modRisk )
@@ -1354,7 +1354,7 @@ plotPredCoef <- function(x, which = NULL, pers = TRUE,
13541354 probs = c(0.25 , 0.5 , 0.75 ), # quantiles of variables to use for plotting
13551355 ylim = NULL , ... ){
13561356
1357- stopifnot(any(class( x ) == " validateFDboost" ))
1357+ stopifnot(inherits( x , " validateFDboost" ))
13581358
13591359 if (is.null(which )) which <- seq_along(x $ coefCV )
13601360
0 commit comments