18  R6 objects

library(rtemis)
  .:rtemis 0.98.25 🌊 aarch64-apple-darwin20

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:

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)
05-20-25 07:25:17 Hello, egenn :s_GLM

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

05-20-25 07:25:18 Training GLM... :s_GLM

.:GLM Regression Training Summary
    MSE = 0.93
   RMSE = 0.96
    MAE = 0.74
      r = 0.87 (p = 3.6e-62)
   R sq = 0.75
05-20-25 07:25:18 Completed in 0.01 minutes (Real: 0.41; User: 0.36; System: 0.03) :s_GLM

class(mod)
[1] "rtMod" "R6"   

18.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] 0.4994443 1.7767934 3.1745587 3.4170364 2.6233937 0.1951385
mod$error.train
    MSE = 0.93
   RMSE = 0.96
    MAE = 0.74
      r = 0.87 (p = 3.6e-62)
   R sq = 0.75

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         r          r.p      SSE
1 0.7382729 0.9296397 0.9641782 0.1045539 0.8681891 3.627177e-62 185.9279
       SSR      SST       Rsq    stderr
1 569.1167 755.0446 0.7537524 0.9641782

18.2 Methods

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