|
1 | | -# This script includes functions for fitting GAM and HGAM models |
2 | | - |
3 | | -# Setting lists of required packages & installing it |
4 | | -# rpackages <- c("mgcv", "raster", "PresenceAbsence") |
5 | | -# |
6 | | -# # rJava, rgeos, maps |
7 | | -# which_not_installed <- which(rpackages %in% rownames(installed.packages()) == FALSE) |
8 | | -# |
9 | | -# if (length(which_not_installed) > 1) { |
10 | | -# install.packages(rpackages[which_not_installed], dep = TRUE) |
11 | | -# } |
12 | | -# rm(rpackages, which_not_installed) |
13 | | -# |
14 | | -# require(mgcv) |
15 | | -# require(raster) |
16 | | -# require(PresenceAbsence) |
17 | | - |
18 | | - |
19 | 1 | #' Make a GAM formula |
20 | 2 | #' |
21 | 3 | #' @description Improved version designed to use the tables produced by the Autodetect functions |
|
27 | 9 | #' @return Returns a formula object, or list of formulas for hgam |
28 | 10 | #' @export |
29 | 11 | #' |
30 | | -#' |
31 | 12 | #' @examples |
32 | 13 | AssembleGAMFormula <- function(yvar, gam.table, hgam = F) { |
33 | 14 |
|
@@ -123,6 +104,13 @@ AssembleGAMFormula <- function(yvar, gam.table, hgam = F) { |
123 | 104 | #' @export |
124 | 105 | #' |
125 | 106 | #' @examples |
| 107 | +#' gam.form <- formula("a_atf ~ s(lon,lat,bs = 'ds',m=c(1,.5), k=10) + s(bdepth, bs='tp',m=1,k=4) + s(btemp, bs='tp',m=1,k=4) + s(slope, bs='tp',m=1,k=4) + offset(logarea)") |
| 108 | +#' data("region_data_all") |
| 109 | +#' region_data_all$sponge <- as.integer(region_data_all$sponge > 0) |
| 110 | +#' region_data_all$logarea <- log(region_data_all$area) |
| 111 | +#' |
| 112 | +#' poisson.model <- FitGAM(gam.formula = gam.form, data = region_data_all, family.gam = "poisson") |
| 113 | + |
126 | 114 | FitGAM <- function(data, |
127 | 115 | gam.formula = NULL, |
128 | 116 | reduce = F, |
@@ -496,7 +484,7 @@ AutodetectGAMTerms <- function(model, hgam = "all") { |
496 | 484 | #' @param model a GAM model object |
497 | 485 | #' @param data a data frame; usually the same one used to fit the GAM model |
498 | 486 | #' |
499 | | -#' @return a named vector of decimal values indicating the percent contribution |
| 487 | +#' @return a named vector of decimal values indicating the percent contribution to deviance explained |
500 | 488 | #' @export |
501 | 489 | #' |
502 | 490 | #' @examples |
@@ -560,7 +548,7 @@ GAMStats <- function(model, # a gam model |
560 | 548 | # update progress bar |
561 | 549 | utils::setTxtProgressBar(pb, i) |
562 | 550 | } else { |
563 | | - utils::setTxtProgressBar(pb, length(gam.terms)) |
| 551 | + utils::setTxtProgressBar(pb, length(gam.terms)) # maybe change this to just 'terms'? |
564 | 552 | print("Deviance could not be estimated for model; returning NAs") |
565 | 553 | break |
566 | 554 | } |
|
0 commit comments