Skip to content

Commit

Permalink
Addition of default glm() engine and adoption in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Jung committed Dec 10, 2023
1 parent 00ae3d9 commit 43500e1
Show file tree
Hide file tree
Showing 25 changed files with 1,015 additions and 50 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Collate:
'engine_bart.R'
'engine_breg.R'
'engine_gdb.R'
'engine_glm.R'
'engine_glmnet.R'
'utils-inla.R'
'engine_inla.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export(emptyraster)
export(engine_bart)
export(engine_breg)
export(engine_gdb)
export(engine_glm)
export(engine_glmnet)
export(engine_inla)
export(engine_inlabru)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# ibis.iSDM 0.1.1 (current dev branch)

#### New features
* Added default `engine_glm()` for dependency-free inference and projection.
* Harmonized controls settings and added option to contrain extrapolation `add_control_extrapolation()`

#### Minor improvements and bug fixes
* Switch to `engine_glm()` in many of the unittests for better coverage.
* Several bug fixes and improvements in `thin_observations`
* `global`, `probs`, and `centers` argument for better control of `thin_observations`
* Harmonization of parameters for `spartial()` and addressing #80
Expand Down
29 changes: 29 additions & 0 deletions R/bdproto-distributionmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ DistributionModel <- bdproto(
"")
))

} else if(inherits(self, 'GLM-Model')) {
obj <- self$get_data('fit_best')

# Summarise coefficients within 1 standard deviation
ms <- tidy_glm_summary(obj)

message(paste0(
'Trained ',class(self)[1],' (',self$show(),')',
'\n \033[1mStrongest summary effects:\033[22m',
'\n \033[34mPositive:\033[39m ', name_atomic(ms$variable[ms$mean>0]),
'\n \033[31mNegative:\033[39m ', name_atomic(ms$variable[ms$mean<0]),
ifelse(has_prediction,
paste0("\n Prediction fitted: ",text_green("yes")),
""),
ifelse(!is.na(has_threshold),
paste0("\n Threshold created: ",text_green("yes")),
"")
))

} else {
message(paste0(
'Trained distribution model (',self$show(),')',
Expand Down Expand Up @@ -267,6 +286,8 @@ DistributionModel <- bdproto(
xgboost::xgb.importance(model = self$get_data(obj))
} else if(inherits(self, 'GLMNET-Model')){
tidy_glmnet_summary(self$get_data(obj))
} else if(inherits(self, 'GLM-Model')){
tidy_glm_summary(self$get_data(obj))
}
},
# Model convergence check
Expand Down Expand Up @@ -302,6 +323,14 @@ DistributionModel <- bdproto(
} else if(inherits(self, 'INLA-Model')) {
plot_inla_marginals(self$get_data(x),what = what)
} else if(inherits(self, 'GLMNET-Model')) {
if(what == "fixed"){
ms <- tidy_glm_summary(mod)
graphics::dotchart(ms$mean,
labels = ms$variable,
frame.plot = FALSE,
color = "grey20")
} else{ plot(self$get_data(x)) }
} else if(inherits(self, 'GLM-Model')) {
if(what == "fixed"){
glmnet:::plot.glmnet(self$get_data(x)$glmnet.fit, xvar = "lambda") # Deviance explained
} else{ plot(self$get_data(x)) }
Expand Down
Loading

0 comments on commit 43500e1

Please sign in to comment.