knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This notebook shows how to use the monad ERTMon provided by this package.

Set-up

Clear all R-session definitions:

rm(list=ls())

Load the package from the GitHub repository:

library(devtools)
install_github("antononcube/ERTMon-R")
library(ERTMon)

Data ingestion

dirName <- if( grepl("vignettes", getwd()) ) { file.path( getwd(), "..", "data", "FakeData") } else { file.path( getwd(), "data", "FakeData")}
dirName

Event records

Here we read the event records data and display a sample of it.

fakeEventRecords <- read.csv( file = file.path( dirName, "eventRecords.csv"), stringsAsFactors = FALSE)
head(fakeEventRecords)

Entity attributes

Here we read the entity attributes data and display a sample of it.

fakeEntityAttributes <- read.csv( file = file.path( dirName, "entityAttributes.csv"), stringsAsFactors = FALSE)
fakeEntityAttributes

Computation specification

Here we read the computation specification.

fakeCompSpec <- read.csv( file = file.path( dirName, "computationSpecification.csv"), stringsAsFactors = FALSE)
fakeCompSpec

Main pipeline

With the main pipeline we take event records data and transform that data into a feature matrix.

Each row of the feature matrix corresponds to an entity; each column to a feature.

A feature is combination of a variable name, aggregation function name, and a time cell index.

Setting data

Initialize the monad and set the event records, entity attributes, and computation specification.

ertmon1 <-
  ERTMonUnit() %>%
  ERTMonSetEventRecords( fakeEventRecords ) %>%
  ERTMonSetEntityAttributes( fakeEntityAttributes ) %>%
  ERTMonSetComputationSpecification( fakeCompSpec )

Process event records

The pipeline function that does the heavy lifting.

ertmon1 <-
  ertmon1 %>%
  ERTMonProcessEventRecords()

Here we get the feature sub-matrices. Each feature sub-matrix corresponds to a variable and an aggregation function name. (Derived from the computation specification.)

smats <- ertmon1 %>% ERTMonTakeContingencyMatrices()
names(smats)

Examples of transformed matrices

smats[["HR.Mean"]][1:12,]

Plot the feature matrix

image(ertmon1 %>% ERTMonTakeFeatureMatrix)

Time cells interpretation

ertmon1 %>% ERTMonTakeTimeCellsInterpretation

Export the feature matrix

ertmon1 %>% ERTMonExportToCSVFeatureMatrix( fileName = file.path( dirName, "featureMatrix.csv") )


antononcube/ERTMon-R documentation built on Oct. 14, 2021, 2:27 p.m.