library(dplyr) library(Matrix) library(ERTMon)
This notebook demonstrates the application of formula specification data frame onto a features matrix.
The exposition has to be improved with easier to plot example results.
Run the notebook "Event-records-transformations-main-use-case.Rmd" first.
(Better with the parameter categoricalMatricesQ
set to FALSE
.)
Here we take the feature matrix (sparse) sub-matrices from data transformation object (dtObj
):
fakeMon <- ERTMonUnit() %>% ERTMonReadDataFromDirectory( "../data/FakeData/" ) %>% ERTMonProcessEventRecords(echoStepsQ = FALSE)
smats <- fakeMon %>% ERTMonTakeContingencyMatrices() names(smats)
Here we make a fake formula specification for the fake medical data:
formulaSpecDF <- data.frame( "FormulaID" = c(1), "TermID" = c(1,1,1,2,2), "TermCoefficient" = c( 0.5, 0.5, 0.5, 1.2, 1.2), "FeatureName" = c("HR.Mean", "NBP.M.Mean", "RR.Mean", "NBP.M.Range", "NBP.M.Mean"), "ReduceFunction" = c( "+", "+", "+", "*", "*"), "Coefficient" = c(1, 1, 1, 1, 1.6), "Exponent" = c(1, 1, 2, 1, 1), "RatioPart" = c( "Numerator", "Denominator", "Denominator", "Numerator", "Denominator"), stringsAsFactors = FALSE) formulaSpecDF
Each term in the formula specification has its own reduce function: "+" (summation) or "*" (multiplication).
Here is the interpretation (per term):
$$formulaMat = \frac{reduceFunc[ { Coefficient[i] * smats[ FeatureName[i] ] ^ {Exponent[i]} : i \in NumeratorRows } ]}{reduceFunc[ { Coefficient[i] * smats[ FeatureName[i] ] ^ {Exponent[i]} : i \in DenominatorRows } ] }$$
The application of the formula specification is done with function ApplyFormulaSpecification
.
fakeMon <- fakeMon %>% ERTMonComputeFormula( formulaSpec = formulaSpecDF ) resMat <- fakeMon %>% ERTMonTakeValue()
image(resMat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.