10 R6 objects

library(rtemis)
  .:rtemis 0.8.0: Welcome, egenn
  [x86_64-apple-darwin17.0 (64-bit): Defaulting to 4/4 available cores]
  Documentation & vignettes: https://rtemis.netlify.com

rtemis makes extensive use of R6 classes. (Early in development, methods were created for all available class systems - S3, S4, RC, R6 - and R6 was the winner).
The following classes are defined - you don’t need to learn or remember these, they are created automatically, as appropriate:

  • rtMod: Supervised model class

    • rtModClass: Inherits from rtMod and adds support for classification models
    • rtModBag: Inherits from rtMod and adds support for bagged models
    • rtMeta: Inherits from rtMod and adds support for meta models
  • rtModLite: A “lite”, bare-bones version of rtMod, used internally in some applications

  • rtModCV: Cross-validated models

    • rtModCVclass: Inherits from rtModCV and adds support for cross-validated classification models
  • rtClust: Clustering class

  • rtDecom: Decomposition class

  • rtXDecom: Cross-decomposition class

  • rtMeta: Meta model class

One of the advantages of such a class system is that it allows storing both attributes (e.g. data like fitted values) and methods (functions that can be performed on the object, like plotting) in an object. Regular R methods (like predict, summary, etc), known as S3 generics, are fully compatible with the R6 system.
Let’s look at an example object.

x <- rnormmat(200, 5)
w <- rnorm(5)
y <- x %*% w + rnorm(200)
mod <- s.GLM(x, y)
[2020-06-23 08:20:04 s.GLM] Hello, egenn 
Warning in if (class(y) == "character") {: the condition has length > 1 and only
the first element will be used

[[ Regression Input Summary ]]
   Training features: 200 x 5 
    Training outcome: 200 x 1 
    Testing features: Not available
     Testing outcome: Not available

[2020-06-23 08:20:06 s.GLM] Training GLM... 

[[ GLM Regression Training Summary ]]
    MSE = 0.79 (82.91%)
   RMSE = 0.89 (58.66%)
    MAE = 0.73 (57.94%)
      r = 0.91 (p = 7e-78)
    rho = 0.90 (p = 0.00)
   R sq = 0.83

[2020-06-23 08:20:06 s.GLM] Run completed in 0.03 minutes (Real: 1.97; User: 1.29; System: 0.12) 
class(mod)
[1] "rtMod" "R6"   

10.1 Attributes

Let’s look at some of the object attributes Remember, in rtemis, fitted refers to the estimated values for the training set and predicted referes to the estimated values for the test set.

head(mod$fitted)
[1] -2.6379925 -2.2195520 -0.8471822 -0.4195429  2.5574202  0.7663661
mod$error.train
    MSE = 0.79 (82.91%)
   RMSE = 0.89 (58.66%)
    MAE = 0.73 (57.94%)
      r = 0.91 (p = 7e-78)
    rho = 0.90 (p = 0.00)
   R sq = 0.83

By the way - you notice the error was custom printed.

class(mod$error.train)
[1] "regError"   "data.frame"

It is a simple S3 object of class regError to allow this pretty-printing. You can view the data.frame itself too. In this case, it holds some more information.

as.data.frame(mod$error.train)
        MAE       MSE      RMSE      NRMSE  MAE.EXP   MAE.RED  MSE.EXP
1 0.7292019 0.7892884 0.8884191 0.07295911 1.733774 0.5794135 4.617578
    MSE.RED RMSE.EXP  RMSE.RED         r          r.p      SSE      SSR
1 0.8290687 2.148855 0.5865616 0.9105321 6.960655e-78 157.8577 765.6578
       SST       Rsq    stderr     rho rho.p
1 923.5155 0.8290687 0.8884191 0.89847     0

10.2 Functions

mod$describe()
Generalized Linear Model was used for regression. Training R-squared was 0.83.
mod$plot()