@@ -71,15 +71,15 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
7171
7272 # SPECIAL CASE HANDLING: y ~ 1, intercept only ######################
7373 # A numeric vector will be created wit the mean, with the same length as the row number in newdataname
74- special_case <- length(attr(terms(formula(model_formula )), " term.labels" )) == 0
74+ special_case <- length(attr(stats :: terms(stats :: formula(model_formula )), " term.labels" )) == 0
7575
7676 if (special_case ){
7777 intercept <- coefficients
7878
7979 # If the input is just a numeric vector, get the length
80- if (class( newdf ) == " numeric" ){
80+ if (all(c( " numeric" ) %in% class( newdf )) ){
8181 predictions.f <- rep(intercept , length(newdf ))
82- } else if (class( newdf ) == " data.frame" ){
82+ } else if (all(c( " data.frame" ) %in% class( newdf )) ){
8383 predictions.f <- rep(intercept , nrow(newdf )) # Otherwise use the number of rows
8484 } else {
8585 stop(" Invalid input: The object called 'newdataname' must be either a numeric vector or a data.frame." ,, call. = FALSE )
@@ -95,7 +95,7 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
9595 predictions.f <- exp(predictions.f )
9696 } else if (family_name == " binomial" ) {
9797 # logit
98- predictions.f <- plogis(predictions.f )
98+ predictions.f <- stats :: plogis(predictions.f )
9999 } else {
100100 stop(" Unsupported family for intercept-only prediction: Family must be either Gaussian, Poisson, or Binomial." , call. = FALSE )
101101 }
@@ -121,18 +121,17 @@ predictDS <- function(newdataname, traindataname, type = c("response", "link"),
121121 na.action.fun <- match.fun(na.action )
122122
123123 # Use a dummy glm object with the correct formula and family
124- dummy_fit <- glm(model_formula ,
125- data = traindata ,
126- family = family_obj ,
127- control = glm.control(maxit = 1 ))
124+ dummy_fit <- stats :: glm(model_formula ,
125+ data = traindata ,
126+ family = family_obj ,
127+ control = stats :: glm.control(maxit = 1 ))
128128
129129 # Change its coefficients with the correct ones
130130 names(coefficients ) <- names(dummy_fit $ coefficients )
131131 dummy_fit $ coefficients <- coefficients
132132
133133 # New predictions
134- prediction <- predict(dummy_fit , newdata = newdf , type = type , na.action = na.action.fun )
134+ prediction <- stats :: predict(dummy_fit , newdata = newdf , type = type , na.action = na.action.fun )
135135
136136 return (prediction )
137137}
138-
0 commit comments