| 1 | #' @include b_Algorithm.R |
| 2 | |
| 3 | #' @title Generalized Additive Model |
| 4 | #' |
| 5 | #' @description Generalized Additive Model using the \code{gam} package. |
| 6 | #' Inherits \code{\link{Algorithm}} |
| 7 | #' |
| 8 | #' @field family Family of the distribution to be used. Default: gaussian(). |
| 9 | #' |
| 10 | GeneralizedAdditive = setRefClass( |
| 11 | Class = "GeneralizedAdditive", |
| 12 | |
| 13 | fields = c( |
| 14 | "family" #class "family" |
| 15 | ), |
| 16 | |
| 17 | contains = "Algorithm", |
| 18 | |
| 19 | methods = list( |
| 20 | initialize = function(...) |
| 21 | { |
| 22 | callSuper(...) |
| 23 | if (class(family) == "uninitializedField") |
| 24 | family <<- gaussian() |
| 25 | }, |
| 26 | predict_noNA = function(XY, x) |
| 27 | { |
| 28 | #GAM need some data to provide reliable results |
| 29 | if (nrow(XY) < 30) |
| 30 | { |
| 31 | X = XY[,names(XY) != "Measure"] |
| 32 | Y = XY[,"Measure"] |
| 33 | weight = ridgeSolve(X, Y, LAMBDA) |
| 34 | return (matricize(x) %*% weight) |
| 35 | } |
| 36 | |
| 37 | suppressPackageStartupMessages( require(gam) ) |
| 38 | g = gam(Measure ~ ., data=XY, family=family) |
| 39 | return (stats::predict(g, x)) |
| 40 | } |
| 41 | ) |
| 42 | ) |