Title: | Statistics in R Using Class-based Templates |
---|---|
Description: | Defines and includes a set of class-based templates for developing and implementing data processing and analysis workflows, with a strong emphasis on statistics and machine learning. The templates can be used and where needed extended to 'wrap' tools and methods from other packages into a common standardised structure to allow for effective and fast integration. Model objects can be combined into sequences, and sequences nested in iterators using overloaded operators to simplify and improve readability of the code. Ontology lookup has been integrated and implemented to provide standardised definitions for methods, inputs and outputs wrapped using the class-based templates. |
Authors: | Gavin Rhys Lloyd [aut, cre], Ralf Johannes Maria Weber [aut] |
Maintainer: | Gavin Rhys Lloyd <[email protected]> |
License: | GPL-3 |
Version: | 1.19.0 |
Built: | 2024-12-19 04:08:18 UTC |
Source: | https://github.com/bioc/struct |
This function returns slotnames for autocompletion when using $ syntax
## S3 method for class 'struct_class' .DollarNames(x, pattern = "") ## S4 method for signature 'struct_class' .DollarNames(x, pattern = "") ## S3 method for class 'chart' .DollarNames(x, pattern = "") ## S4 method for signature 'chart' .DollarNames(x, pattern = "") ## S3 method for class 'DatasetExperiment' .DollarNames(x, pattern = "") ## S4 method for signature 'DatasetExperiment' .DollarNames(x, pattern = "") ## S3 method for class 'model' .DollarNames(x, pattern = "") ## S4 method for signature 'model' .DollarNames(x, pattern = "") ## S3 method for class 'metric' .DollarNames(x, pattern = "") ## S4 method for signature 'metric' .DollarNames(x, pattern = "") ## S3 method for class 'iterator' .DollarNames(x, pattern = "") ## S4 method for signature 'iterator' .DollarNames(x, pattern = "") ## S3 method for class 'optimiser' .DollarNames(x, pattern = "") ## S4 method for signature 'optimiser' .DollarNames(x, pattern = "") ## S3 method for class 'preprocess' .DollarNames(x, pattern = "") ## S4 method for signature 'preprocess' .DollarNames(x, pattern = "") ## S3 method for class 'resampler' .DollarNames(x, pattern = "") ## S4 method for signature 'resampler' .DollarNames(x, pattern = "")
## S3 method for class 'struct_class' .DollarNames(x, pattern = "") ## S4 method for signature 'struct_class' .DollarNames(x, pattern = "") ## S3 method for class 'chart' .DollarNames(x, pattern = "") ## S4 method for signature 'chart' .DollarNames(x, pattern = "") ## S3 method for class 'DatasetExperiment' .DollarNames(x, pattern = "") ## S4 method for signature 'DatasetExperiment' .DollarNames(x, pattern = "") ## S3 method for class 'model' .DollarNames(x, pattern = "") ## S4 method for signature 'model' .DollarNames(x, pattern = "") ## S3 method for class 'metric' .DollarNames(x, pattern = "") ## S4 method for signature 'metric' .DollarNames(x, pattern = "") ## S3 method for class 'iterator' .DollarNames(x, pattern = "") ## S4 method for signature 'iterator' .DollarNames(x, pattern = "") ## S3 method for class 'optimiser' .DollarNames(x, pattern = "") ## S4 method for signature 'optimiser' .DollarNames(x, pattern = "") ## S3 method for class 'preprocess' .DollarNames(x, pattern = "") ## S4 method for signature 'preprocess' .DollarNames(x, pattern = "") ## S3 method for class 'resampler' .DollarNames(x, pattern = "") ## S4 method for signature 'resampler' .DollarNames(x, pattern = "")
x |
a struct_class object |
pattern |
the text used to compare against the slot names |
A vector of slot names
Dollar syntax can be used to as a shortcut for getting values for ontology_list objects.
## S4 method for signature 'ontology_list' x$name
## S4 method for signature 'ontology_list' x$name
x |
An ontology_term object |
name |
The name of the slot to access |
Slot value
## Not run: OL = ontology_list('STATO:0000555') OL$terms ## End(Not run)
## Not run: OL = ontology_list('STATO:0000555') OL$terms ## End(Not run)
Dollar syntax can be used to as a shortcut for getting values for ontology_term objects.
## S4 method for signature 'ontology_term' x$name
## S4 method for signature 'ontology_term' x$name
x |
An ontology_term object |
name |
The name of the slot to access |
Slot value
## Not run: OT = ontology_term(ontology='stato',id='STATO:0000555') ## End(Not run)
## Not run: OT = ontology_term(ontology='stato',id='STATO:0000555') ## End(Not run)
Dollar syntax can be used to as a shortcut for getting/setting input parameter and output values for struct objects.
## S4 method for signature 'struct_class' x$name
## S4 method for signature 'struct_class' x$name
x |
An object derived from struct_class |
name |
The name of the slot to access |
Parameter/output value
M = example_model() M$value_1 = 10 M$value_1 # 10
M = example_model() M$value_1 = 10 M$value_1 # 10
Dollar syntax can be used to as a shortcut for getting/setting input parameter and output values for struct objects.
## S4 replacement method for signature 'struct_class' x$name <- value
## S4 replacement method for signature 'struct_class' x$name <- value
x |
An object derived from struct_class |
name |
The name of the slot to access |
value |
The value to assign |
Parameter/output value
M = example_model() M$value_1 = 10 M$value_1 # 10
M = example_model() M$value_1 = 10 M$value_1 # 10
Most often used with univariate statistics to gather all the different outputs in a consistent format.
as_data_frame(M, ...)
as_data_frame(M, ...)
M |
a struct object |
... |
other inputs passed through this function |
a data.frame containing outputs from an object
Prints a block of code that can be used to replicate the input object.
as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'struct_class' as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'model_seq' as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'iterator' as.code(M, start = "M = ", mode = "compact", quiet = FALSE)
as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'struct_class' as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'model_seq' as.code(M, start = "M = ", mode = "compact", quiet = FALSE) ## S4 method for signature 'iterator' as.code(M, start = "M = ", mode = "compact", quiet = FALSE)
M |
a struct model, model_seq or iterator object |
start |
text prepended to the code. Default is "M = " |
mode |
"compact" will use the least amount of lines, "expanded" will put each object and input on a new line. "neat" will produce an output somewhere between "compact" and "expanded". |
quiet |
TRUE or FALSE to print code to console |
A string of code to reproduce the input object.
a string of code to reproduce the model
a string of code to reproduce the model sequence
a string of code to reproduce the iterator
M = example_model(value_1 = 10) as.code(M) M = example_model() as.code(M) M = example_model() as.code(M) M = example_model() as.code(M)
M = example_model(value_1 = 10) as.code(M) M = example_model() as.code(M) M = example_model() as.code(M) M = example_model() as.code(M)
Converts a SummarizedExperiment to DatasetExperiment. The assay data is transposed, and colData and rowData switched to match. struct specific slots such as "name" and "description" are extracted from the metaData.
as.DatasetExperiment(obj)
as.DatasetExperiment(obj)
obj |
a SummarizedExperiment object |
a DatasetExperiment object
The assay data is transposed, and colData and rowData switched to match. struct specific slots such as "name" and "description" are extracted from the metaData if available. NB Any additional metadata will be lost during this conversion.
## S4 method for signature 'SummarizedExperiment' as.DatasetExperiment(obj)
## S4 method for signature 'SummarizedExperiment' as.DatasetExperiment(obj)
obj |
a SummarizedExperiment object |
a DatasetExperiment object
Converts a DatasetExperiment to SummarizedExperiment. The assay data is transposed, and colData and rowData switched to match. struct specific slots such as "name" and "description" are stored in the metaData.
as.SummarizedExperiment(obj)
as.SummarizedExperiment(obj)
obj |
a DatasetExperiment object |
a SummarizedExperiment object
Converts a DatasetExperiment to SummarizedExperiment. The assay data is transposed, and colData and rowData switched to match. struct specific slots such as "name" and "description" are stored in the metaData.
## S4 method for signature 'DatasetExperiment' as.SummarizedExperiment(obj)
## S4 method for signature 'DatasetExperiment' as.SummarizedExperiment(obj)
obj |
a DatasetExperiment object |
a SummarizedExperiment object
ontology_lists can be catenated with other ontology lists or with ontology_items.
## S4 method for signature 'ontology_list' c(x, ...)
## S4 method for signature 'ontology_list' c(x, ...)
x |
an ontology_list() |
... |
any number of ontology_list() or ontology_item() objects to catenate |
an ontology_list()
A class for metrics to assess performance of e.g. models, iterators. Not intended to be called directly, this class should be inherited to provide functionality for method-specific classes.
calculate(obj, ...) value(obj) value(obj) <- value max_length(obj) <- value metric(...) ## S4 method for signature 'metric' calculate(obj, Y, Yhat) ## S4 method for signature 'metric' value(obj) ## S4 replacement method for signature 'metric' value(obj) <- value
calculate(obj, ...) value(obj) value(obj) <- value max_length(obj) <- value metric(...) ## S4 method for signature 'metric' calculate(obj, Y, Yhat) ## S4 method for signature 'metric' value(obj) ## S4 replacement method for signature 'metric' value(obj) <- value
obj |
a metric object |
... |
named slots and their values. |
value |
value |
Y |
the true class labels |
Yhat |
the predicted class labels |
value the calculated value of a metric
a metric object
MET = metric() calculate(MET) MET = metric() M = metric() calculate(M,Y,Yhat) MET = metric() value(MET) MET = metric() value(MET) = 10
MET = metric() calculate(MET) MET = metric() M = metric() calculate(M,Y,Yhat) MET = metric() value(MET) MET = metric() value(MET) = 10
A base class in the struct package. Should not be called directly.
chart(...)
chart(...)
... |
named slots and their values that get passed to struct_class |
The chart
class provides a template for figures, charts and plots
associated with other objects. For example, a DatasetExperiment object could have a
histogram plotted for a specified column.
Charts can have parameters but not outputs (other than the figure itself), as
chart objects are not intended to be used for calculations. The
chart_plot
method can be used to display a chart for an object, and
chart_names
can be used to list all chart objects associated with an
object.
Classes that inherit the stato
class have STATO integration enabled,
allowing stato_id to be set and formal names
and descriptions pulled from the STATO ontology database.
a chart object
a struct_class object
C = example_chart()
C = example_chart()
Returns a list of valid charts for a struct object
chart_names(obj, ret = "char") ## S4 method for signature 'struct_class' chart_names(obj, ret = "char")
chart_names(obj, ret = "char") ## S4 method for signature 'struct_class' chart_names(obj, ret = "char")
obj |
An object derived from the struct_class object |
ret |
A string indicating whether a list of objects ('obj') or a list of chart names ('char') is returned. 'char' is default. |
The chart_names method searches for chart objects associated with the unput object.
list of chart names, or a list of chart objects
M = example_model() chart_names(M) # 'example_chart' chart_names(M,'char') # as above chart_names(M,'obj') # returns a list of chart objects
M = example_model() chart_names(M) # 'example_chart' chart_names(M,'char') # as above chart_names(M,'obj') # returns a list of chart objects
Plots a chart object
chart_plot(obj, dobj, ...) ## S4 method for signature 'chart,ANY' chart_plot(obj, dobj)
chart_plot(obj, dobj, ...) ## S4 method for signature 'chart,ANY' chart_plot(obj, dobj)
obj |
A chart object |
dobj |
An object derived from struct_class |
... |
optional inputs |
The optional optional inputs depend on the input object/chart, but might include an additional dataset object or a second model object, for example.
a plot object
chart_plot(obj = chart, dobj = ANY)
:
C = example_chart() chart_plot(C,iris_DatasetExperiment())
C = example_chart() chart_plot(C,iris_DatasetExperiment())
All struct
objects have a "citations" slot, which is a list of
references in bibtex format. The citations
method gathers
citations from an object and all struct
objects that it inherits to generate
a complete list.
citations(obj) ## S4 method for signature 'struct_class' citations(obj)
citations(obj) ## S4 method for signature 'struct_class' citations(obj)
obj |
a struct object |
a character array of citations
D = iris_DatasetExperiment() D$citations # the list specifically defined for this object citations(D) # the list for this object and all inherited ones
D = iris_DatasetExperiment() D$citations # the list specifically defined for this object citations(D) # the list for this object and all inherited ones
An object for holding raw data and associated meta data
DatasetExperiment( data = data.frame(), sample_meta = data.frame(), variable_meta = data.frame(), ... ) ## S4 method for signature 'DatasetExperiment' x$name ## S4 replacement method for signature 'DatasetExperiment' x$name <- value
DatasetExperiment( data = data.frame(), sample_meta = data.frame(), variable_meta = data.frame(), ... ) ## S4 method for signature 'DatasetExperiment' x$name ## S4 replacement method for signature 'DatasetExperiment' x$name <- value
data |
A data frame with samples in rows and features in columns |
sample_meta |
A data frame with samples in rows and meta data in columns |
variable_meta |
A data frame with features in rows and meta data in columns |
... |
named slot values to pass through to struct_class |
x |
A DatasetExperiment object |
name |
DatasetExperiment slot to get/set |
value |
the value to assign to the named slot |
The DatasetExperiment object is an extension of the SummarizedExperiment object from the SummarizedExperiment package (found on Bioconductor). It incorporates the basic functionality of struct objects, containing fields such as Description, Name and Type with features of SummarizedExperiment such as subsetting.
There are some important differences between DatasetExperiment and SummarizedExperiment:
In DatasetExperiment data is stored as Samples (rows) x Features (columns)
DatasetExperiment currently only supports a single assay
length(DatasetExperiment) returns the number of samples
DatasetExperiment
name
Name of the dataset
description
Brief description of the dataset
type
The type of dataset e.g. single_block
A base class in the struct package. Should not be called directly.
entity_stato( name, description = character(0), type = "character", value = NULL, max_length = Inf, stato_id )
entity_stato( name, description = character(0), type = "character", value = NULL, max_length = Inf, stato_id )
name |
the name of the object |
description |
a description of the object |
type |
the type of the struct object |
value |
The value of the parameter/outputs |
max_length |
Maximum length of value vector (default 1) |
stato_id |
The STATO ID for the entity |
Extends the entity
class to include stato functionality.
an entity_stato object
Refer to entity
and stato
for further
info.
E = entity_stato( name = 'example', description = 'this is an example', type = 'numeric', value = 1, stato_id='XYZ000001' )
E = entity_stato( name = 'example', description = 'this is an example', type = 'numeric', value = 1, stato_id='XYZ000001' )
A base class in the struct package. Not normally called directly.
enum( name, description = character(0), type = "character", value = character(0), max_length = 1, allowed, ... ) ## S4 replacement method for signature 'enum' value(obj) <- value
enum( name, description = character(0), type = "character", value = character(0), max_length = 1, allowed, ... ) ## S4 replacement method for signature 'enum' value(obj) <- value
name |
the name of the object |
description |
a description of the object |
type |
the type of the struct object |
value |
value of the enum |
max_length |
Maximum length of value vector (default 1) |
allowed |
A list of allowed values |
... |
additional inputs to the struct_class object |
obj |
an enum object |
An enum object is a special type of entity object that ensures the value must be one from a list of allowed values.
Enum objects are usually defined in the prototype of another object, but
can be extracted using param_obj
and output_obj
.
an enum object
# Create a new enum object E = enum( name = 'example', description = 'this is an example', type = 'character', value = 'hello', allowed = c('hello','world') ) # Get/set the value of the entity object value(E) value(E) = 'world'
# Create a new enum object E = enum( name = 'example', description = 'this is an example', type = 'character', value = 'hello', allowed = c('hello','world') ) # Get/set the value of the entity object value(E) value(E) = 'world'
A base class in the struct package. Should not be called directly.
enum_stato( name, description = character(0), type = "character", value = character(0), max_length = 1, allowed, stato_id )
enum_stato( name, description = character(0), type = "character", value = character(0), max_length = 1, allowed, stato_id )
name |
the name of the object |
description |
a description of the object |
type |
the type of the struct object |
value |
The value of the parameter/outputs |
max_length |
Maximum length of value vector (default 1) |
allowed |
A list of allowed values |
stato_id |
The STATO ID for the entity |
Extends the enum
class to include stato functionality.
an enum_stato object
Refer to enum
and stato
for further
info.
E = enum_stato( name='example', allowed=list('choice_1','choice_2'), value='choice_1', type='character', stato_id='XYZ000001' )
E = enum_stato( name='example', allowed=list('choice_1','choice_2'), value='choice_1', type='character', stato_id='XYZ000001' )
an example of a chart object for documentation purposes
example_chart(...) ## S4 method for signature 'example_chart,example_model' chart_plot(obj, dobj)
example_chart(...) ## S4 method for signature 'example_chart,example_model' chart_plot(obj, dobj)
... |
named slots and their values. |
obj |
a chart object |
dobj |
a example_model object |
a chart object
C = example_chart() chart_plot(C,example_model())
C = example_chart() chart_plot(C,example_model())
An example iterator for testing
runs the example iterator, which just returns a value of 3.142
## S4 method for signature 'example_iterator,DatasetExperiment,metric' run(I, D, MET)
## S4 method for signature 'example_iterator,DatasetExperiment,metric' run(I, D, MET)
I |
example_iterator object |
D |
dataset object |
MET |
metric object |
test iterator object
dataset object
I = example_iterator() I = example_iterator() D = iris_DatasetExperiment() MET = metric() I = run(I,D,MET)
I = example_iterator() I = example_iterator() D = iris_DatasetExperiment() MET = metric() I = run(I,D,MET)
An example model for testing. Training this model adds value_1 to a data set, and prediction using this model adds value_2.
trains the example model, which adds value_1 to the raw data of a dataset
predicts using the example model, which adds value_2 to the raw data of a dataset
example_model(value_0 = 0, value_1 = 10, value_2 = 20, ...) ## S4 method for signature 'example_model,DatasetExperiment' model_train(M, D) ## S4 method for signature 'example_model,DatasetExperiment' model_predict(M, D)
example_model(value_0 = 0, value_1 = 10, value_2 = 20, ...) ## S4 method for signature 'example_model,DatasetExperiment' model_train(M, D) ## S4 method for signature 'example_model,DatasetExperiment' model_predict(M, D)
value_0 |
a numeric value |
value_1 |
a numeric value |
value_2 |
a numeric value |
... |
named slots and their values. |
M |
A struct model object |
D |
A DatasetExperiment object |
modified example_model object
dataset object
dataset object
M = example_model() M = example_model(value_1 = 10, value_2 = 20) D = iris_DatasetExperiment() M = example_model(value_1 = 10, value_2 = 20) M = model_train(M,D) D = iris_DatasetExperiment() M = example_model(value_1 = 10, value_2 = 20) M = model_predict(M,D)
M = example_model() M = example_model(value_1 = 10, value_2 = 20) D = iris_DatasetExperiment() M = example_model(value_1 = 10, value_2 = 20) M = model_train(M,D) D = iris_DatasetExperiment() M = example_model(value_1 = 10, value_2 = 20) M = model_predict(M,D)
Exports a dataset object to an excel file with sheets for data, sample_meta and variable_meta
export_xlsx(object, outfile, transpose = TRUE) ## S4 method for signature 'DatasetExperiment' export_xlsx(object, outfile, transpose = TRUE)
export_xlsx(object, outfile, transpose = TRUE) ## S4 method for signature 'DatasetExperiment' export_xlsx(object, outfile, transpose = TRUE)
object |
a dataset object |
outfile |
the filename (including path) to write the data to |
transpose |
TRUE (default) or FALSE to transpose the output data |
an excel file with sheets for data and meta data
## Not run: D = iris_DatasetExperiment() # example dataset export_xlsx(D,'iris_DatasetExperiment.xlsx') ## End(Not run)
## Not run: D = iris_DatasetExperiment() # example dataset export_xlsx(D,'iris_DatasetExperiment.xlsx') ## End(Not run)
This function is to help developers including struct objects in their own R packages, and isnt intended for general use. Use with roxygen 2 '@eval' tags this function generates a detailed description of a struct object generated by extracting names, descriptions etc from slots in a suitable format.
get_description(id)
get_description(id)
id |
(character) the name of a struct object to generate documentation for |
a character string of roxygen formatted documentation for the object
get_description('example_model')
get_description('example_model')
Fisher's Iris data as a DatasetExperiment object
iris_DatasetExperiment()
iris_DatasetExperiment()
DatasetExperiment object
D = iris_DatasetExperiment()
D = iris_DatasetExperiment()
Verify that the name of a output is valid for an object
is_output(obj, name) ## S4 method for signature 'struct_class' is_output(obj, name)
is_output(obj, name) ## S4 method for signature 'struct_class' is_output(obj, name)
obj |
A model or iterator object derived from the *struct* class |
name |
Name of output |
TRUE if output name is valid, FALSE if not
M = example_model() is_output(M,'result_1') # TRUE is_output(M,'result_0') # FALSE
M = example_model() is_output(M,'result_1') # TRUE is_output(M,'result_0') # FALSE
Verify that the input name is a valid input parameter for an object
is_param(obj, name) ## S4 method for signature 'struct_class' is_param(obj, name)
is_param(obj, name) ## S4 method for signature 'struct_class' is_param(obj, name)
obj |
An object derived from struct_class |
name |
Name of parameter |
TRUE if parameter name is valid, FALSE if not
M = example_model() is_param(M,'value_1') # TRUE is_param(M,'alpha') # FALSE
M = example_model() is_param(M,'value_1') # TRUE is_param(M,'alpha') # FALSE
All struct
objects have a "libraries" slot, which is a character array of
libraries required to use the object. The libraries
method gathers
libraries from an object and all struct
objects that it inherits to generate
a complete list.
libraries(obj) ## S4 method for signature 'struct_class' libraries(obj)
libraries(obj) ## S4 method for signature 'struct_class' libraries(obj)
obj |
a struct object |
a character array of R packages needed by the object
M = example_model() libraries(M)
M = example_model() libraries(M)
A base class in the struct package. Not normally called directly. An entity object is used to store information about a parameter or output_ The standard 'name','description' and 'type' slots are included, along with 'value' for storing the value of the parameter and 'max_length' for restricting the length of 'value' if needed.
max_length(obj) entity( name, description = character(0), type = "character", value = NULL, max_length = Inf, ... ) ## S4 method for signature 'entity' value(obj) ## S4 replacement method for signature 'entity' value(obj) <- value ## S4 method for signature 'entity' max_length(obj) ## S4 replacement method for signature 'entity' max_length(obj) <- value
max_length(obj) entity( name, description = character(0), type = "character", value = NULL, max_length = Inf, ... ) ## S4 method for signature 'entity' value(obj) ## S4 replacement method for signature 'entity' value(obj) <- value ## S4 method for signature 'entity' max_length(obj) ## S4 replacement method for signature 'entity' max_length(obj) <- value
obj |
An entity object |
name |
the name of the object |
description |
a description of the object |
type |
the type of the struct object |
value |
The value of the parameter/outputs |
max_length |
Maximum length of value vector (default 1) |
... |
additional inputs to the struct_class object |
Entity objects are usually defined in the prototype of another object, but
can be extracted using param_obj
and output_obj
.
max value vector length for an entity
An entity object
# Create a new entity object E = entity( name = 'example', description = 'this is an example', type = 'numeric', value = 1 ) # Get/set the value of the entity object value(E) value(E) = 10
# Create a new entity object E = entity( name = 'example', description = 'this is an example', type = 'numeric', value = 1 ) # Get/set the value of the entity object value(E) value(E) = 10
A class for models that can be trained/applied to datasets e.g. PCA, PLS etc. Also used for preprocessing steps that require application to test sets. not intended to be called directly, this class should be inherited to provide functionality for method-specific classes.
model( predicted = character(0), seq_in = "data", seq_fcn = function(x) { return(x) }, ... ) ## S4 method for signature 'model,DatasetExperiment' model_train(M, D) ## S4 method for signature 'model,DatasetExperiment' model_predict(M, D) ## S4 method for signature 'model,DatasetExperiment' model_apply(M, D) ## S4 method for signature 'model,DatasetExperiment' model_reverse(M, D) ## S4 method for signature 'model' predicted(M) ## S4 method for signature 'model' seq_in(M) ## S4 replacement method for signature 'model,character' seq_in(M) <- value ## S4 method for signature 'model' predicted_name(M) ## S4 replacement method for signature 'model,character' predicted_name(M) <- value
model( predicted = character(0), seq_in = "data", seq_fcn = function(x) { return(x) }, ... ) ## S4 method for signature 'model,DatasetExperiment' model_train(M, D) ## S4 method for signature 'model,DatasetExperiment' model_predict(M, D) ## S4 method for signature 'model,DatasetExperiment' model_apply(M, D) ## S4 method for signature 'model,DatasetExperiment' model_reverse(M, D) ## S4 method for signature 'model' predicted(M) ## S4 method for signature 'model' seq_in(M) ## S4 replacement method for signature 'model,character' seq_in(M) <- value ## S4 method for signature 'model' predicted_name(M) ## S4 replacement method for signature 'model,character' predicted_name(M) <- value
predicted |
The name of an output slot to return when using |
seq_in |
the name of an output slot to connect with the "predicted" output of another model (see details) |
seq_fcn |
a function to apply to seq_in before inputting into the next model. Typically used to extract a single column, or convert from factor to char etc. |
... |
named slots and their values. |
M |
A struct model object |
D |
A DatasetExperiment object |
value |
The value to assign |
trained model object
model object with test set results
trained model object
dataset dataset object with the reverse model applied
the predicted output, as specified by predicted_name
the id of the input parameter to be replaced by the predicted
output of the previous model in a model sequence. Reserved keyword 'data'
means that the input data used by model_train
, model_apply
etc is used.
seq_in = 'data'
is the default setting.
the modified model object
the id of the output returned by predicted()
the modified model object
predicted
slotThe "predicted" slot is a slots for use by users to control the flow of model
sequences. The predicted()
function is used to return a default output and
from a model. Typically it is a DatasetExperiment object that is passed directly
into the next model in a sequence as the data for that model.
seq_in
slotIn a sequence of models (see model_seq) the "predicted" slot is connected to the
DatasetExperiment input of the next model. seq_in
can be used to control
flow and connect the "predicted" output to the input parameter of the next model.
Default is the keyword 'data', and can otherwise be replaced by any input slot
from the model. The slot seq_fcn
can be used to apply a transformation to
the output before it is used as an input. This allows you to e.g. convert between types,
extract a single column from a data.frame etc.
M = model() D = DatasetExperiment() M = model() M = model_train(M,D) D = DatasetExperiment() M = model() M = model_train(M,D) M = model_predict(M,D) D = DatasetExperiment() M = model() M = model_apply(M,D) D = DatasetExperiment() M = model() M = model_train(M,D) M = model_predict(M,D) M = model_reverse(M,D) D = DatasetExperiment() M = example_model() M = model_train(M,D) M = model_predict(M,D) p = predicted(M) D = DatasetExperiment() M = example_model() seq_in(M) = 'data' M = example_model() seq_in(M) = 'value_1' M = example_model() predicted_name(M) M = example_model() predicted_name(M) = 'result_2'
M = model() D = DatasetExperiment() M = model() M = model_train(M,D) D = DatasetExperiment() M = model() M = model_train(M,D) M = model_predict(M,D) D = DatasetExperiment() M = model() M = model_apply(M,D) D = DatasetExperiment() M = model() M = model_train(M,D) M = model_predict(M,D) M = model_reverse(M,D) D = DatasetExperiment() M = example_model() M = model_train(M,D) M = model_predict(M,D) p = predicted(M) D = DatasetExperiment() M = example_model() seq_in(M) = 'data' M = example_model() seq_in(M) = 'value_1' M = example_model() predicted_name(M) M = example_model() predicted_name(M) = 'result_2'
Applies a method to the input dataset
model_apply(M, D, ...)
model_apply(M, D, ...)
M |
a 'method' object |
D |
another object used by the first |
... |
other optional inputs |
Returns a modified method object
M = example_model() M = model_apply(M,iris_DatasetExperiment())
M = example_model() M = model_apply(M,iris_DatasetExperiment())
Apply a model using the input dataset. Assumes the model is trained first.
model_predict(M, D, ...)
model_predict(M, D, ...)
M |
a model object |
D |
a dataset object |
... |
other optional inputs |
Returns a modified model object
M = example_model() M = model_predict(M,iris_DatasetExperiment())
M = example_model() M = model_predict(M,iris_DatasetExperiment())
Reverse the effect of a preprocessing step on a dataset_
model_reverse(M, D, ...)
model_reverse(M, D, ...)
M |
a model object |
D |
a dataset object |
... |
other optional inputs |
Returns a modified dataset object
M = example_model() D = model_reverse(M,iris_DatasetExperiment())
M = example_model() D = model_reverse(M,iris_DatasetExperiment())
A class for (ordered) lists of models
model_seq(...) ## S4 method for signature 'model_seq,DatasetExperiment' model_train(M, D) ## S4 method for signature 'model_seq,DatasetExperiment' model_predict(M, D) ## S4 method for signature 'model_seq,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'model_seq,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'model_seq' models(ML) ## S4 replacement method for signature 'model_seq,list' models(ML) <- value ## S4 method for signature 'model_seq' length(x) ## S4 method for signature 'model,model_seq' e1 + e2 ## S4 method for signature 'model_seq,model' e1 + e2 ## S4 method for signature 'model,model' e1 + e2 ## S4 method for signature 'model_seq' predicted(M) ## S4 method for signature 'model_seq,DatasetExperiment' model_apply(M, D)
model_seq(...) ## S4 method for signature 'model_seq,DatasetExperiment' model_train(M, D) ## S4 method for signature 'model_seq,DatasetExperiment' model_predict(M, D) ## S4 method for signature 'model_seq,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'model_seq,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'model_seq' models(ML) ## S4 replacement method for signature 'model_seq,list' models(ML) <- value ## S4 method for signature 'model_seq' length(x) ## S4 method for signature 'model,model_seq' e1 + e2 ## S4 method for signature 'model_seq,model' e1 + e2 ## S4 method for signature 'model,model' e1 + e2 ## S4 method for signature 'model_seq' predicted(M) ## S4 method for signature 'model_seq,DatasetExperiment' model_apply(M, D)
... |
named slots and their values. |
M |
a model object |
D |
a dataset object |
x |
a model_seq object |
i |
index |
value |
value |
ML |
a model_seq object |
e1 |
a model or model_seq object |
e2 |
a model or model_seq object |
model sequence
model sequence
model at the given index in the sequence
model sequence with the model at index i replaced
a list of models in the sequence
a model sequence containing the input models
the number of models in the sequence
a model sequence with the additional model appended to the front of the sequence
a model sequence with the additional model appended to the end of the sequence
a model sequence
the predicted output of the last model in the sequence
MS = model_seq() MS = model() + model() MS = example_model() + example_model() MS = model_train(MS,DatasetExperiment()) D = DatasetExperiment() MS = example_model() + example_model() MS = model_train(MS,D) MS = model_predict(MS,D) MS = model() + model() MS[2] MS = model() + model() MS[3] = model() MS = model() + model() L = models(MS) MS = model_seq() L = list(model(),model()) models(MS) = L MS = model() + model() length(MS) # 2 MS = model() + model() M = model() MS = M + MS MS = model() + model() M = model() MS = MS + M MS = model() + model() D = DatasetExperiment() M = example_model() M = model_train(M,D) M = model_predict(M,D) p = predicted(M) D = DatasetExperiment() MS = example_model() + example_model() MS = model_apply(MS,D)
MS = model_seq() MS = model() + model() MS = example_model() + example_model() MS = model_train(MS,DatasetExperiment()) D = DatasetExperiment() MS = example_model() + example_model() MS = model_train(MS,D) MS = model_predict(MS,D) MS = model() + model() MS[2] MS = model() + model() MS[3] = model() MS = model() + model() L = models(MS) MS = model_seq() L = list(model(),model()) models(MS) = L MS = model() + model() length(MS) # 2 MS = model() + model() M = model() MS = M + MS MS = model() + model() M = model() MS = MS + M MS = model() + model() D = DatasetExperiment() M = example_model() M = model_train(M,D) M = model_predict(M,D) p = predicted(M) D = DatasetExperiment() MS = example_model() + example_model() MS = model_apply(MS,D)
Trains a model using the input dataset
model_train(M, D, ...)
model_train(M, D, ...)
M |
a model object |
D |
a dataset object |
... |
other optional inputs |
Returns a modified model object
M = example_model() M = model_train(M,iris_DatasetExperiment())
M = example_model() M = model_train(M,iris_DatasetExperiment())
Returns the list of models in a model_seq object
models(ML) models(ML) <- value
models(ML) models(ML) <- value
ML |
a model_seq object |
value |
a list containing only model objects |
models(ML)
returns a list of models in the model sequence
models(ML)<-
sets the list of models in the model sequence
# Create a model sequence ML = model_seq() models(ML) = list(example_model(), example_model()) models(ML)
# Create a model sequence ML = model_seq() models(ML) = list(example_model(), example_model()) models(ML)
This function creates a newly allocated object from the class identified by
the first argument. It works almost identically to new
but is specific
to objects from the struct package and ensures that entity
slots have
their values assigned correctly. This function is usually called by class
constructors and not used directly.
new_struct(class, ...)
new_struct(class, ...)
class |
The class of struct object to create |
... |
named slots and values to assign |
An object derived from struct_class
S = new_struct('struct_class')
S = new_struct('struct_class')
All struct
objects have an "ontology" slot, which is a list of
ontology items for the object. The ontology
method gathers
ontology items from an object and all struct
objects that it inherits to generate
a complete list.
A base class in the struct package. Stores ontology information e.g. term, description, id etc for struct objects and provides methods for populating these fields using the 'rols' package.
A base class in the struct package. Stores multiple 'ontology_term' objects.
ontology(obj, cache = NULL) ontology_term( id, ontology = character(), label = character(), description = character(), iri = character(), rols = TRUE ) ontology_list(terms = list()) ## S4 method for signature 'ontology_list,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'ontology_list,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'ontology_list' length(x) ## S4 method for signature 'struct_class' ontology(obj, cache = NULL)
ontology(obj, cache = NULL) ontology_term( id, ontology = character(), label = character(), description = character(), iri = character(), rols = TRUE ) ontology_list(terms = list()) ## S4 method for signature 'ontology_list,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'ontology_list,ANY,ANY,ANY' x[i] <- value ## S4 method for signature 'ontology_list' length(x) ## S4 method for signature 'struct_class' ontology(obj, cache = NULL)
obj |
a struct object |
cache |
a named list of ontology_terms for offline use. Terms from the cache are search based on the name of the list items matching the ontology id. If cache=NULL then the OLS API is used to lookup terms. |
id |
(character) The ontology term id e.g. 'STATO:0000555' |
ontology |
(character) The ontology the term is a member of e.g. 'stato' |
label |
(character) The label for the ontology term |
description |
(character) The description of the term |
iri |
(character) The Internationalized Resource Identifier for the term |
rols |
(logical) TRUE or FALSE to query the Ontology Lookup Service for missing label, description or iri if not provided as input. Default rols = TRUE |
terms |
A list of ontology_term objects. |
x |
the list |
i |
The list item index |
value |
an ontology_term() object |
model at the given index in the sequence
model sequence with the model at index i replaced
the number of models in the sequence
M = example_model() ontology(M,cache=NULL) ## Not run: OT = ontology_term(id='STATO:0000555') ## End(Not run) ## Not run: OT = ontology_list(terms=list( ontology_term(ontology='obi',id = 'OBI:0200051'), ontology_term(ontology='stato',id ='STATO:0000555') ) ## End(Not run) ## Not run: OL = ontology_list('STATO:0000555') OL[1] ## End(Not run) ## Not run: OL = ontology_list('STATO:0000555') OL[1] = ontology_term('STATO:0000302') ## End(Not run) ## Not run: OL = ontology_list() length(OL) # 0 ## End(Not run)
M = example_model() ontology(M,cache=NULL) ## Not run: OT = ontology_term(id='STATO:0000555') ## End(Not run) ## Not run: OT = ontology_list(terms=list( ontology_term(ontology='obi',id = 'OBI:0200051'), ontology_term(ontology='stato',id ='STATO:0000555') ) ## End(Not run) ## Not run: OL = ontology_list('STATO:0000555') OL[1] ## End(Not run) ## Not run: OL = ontology_list('STATO:0000555') OL[1] = ontology_term('STATO:0000302') ## End(Not run) ## Not run: OL = ontology_list() length(OL) # 0 ## End(Not run)
A special class of iterator for selecting optimal parameter values not intended to be called directly, this class should be inherited to provide functionality for method-specific classes.
optimiser(...)
optimiser(...)
... |
named slots and their values. |
an optimiser object
OPT = optimiser()
OPT = optimiser()
return a list of valid output ids for an object
output_ids(obj) ## S4 method for signature 'struct_class' output_ids(obj)
output_ids(obj) ## S4 method for signature 'struct_class' output_ids(obj)
obj |
A model or iterator object derived from the *struct* class |
list of output ids
M = example_model() output_ids(M)
M = example_model() output_ids(M)
get/set a named list of outputs and their current value for an object
output_list(obj) output_list(obj) <- value ## S4 method for signature 'struct_class' output_list(obj) ## S4 replacement method for signature 'struct_class,list' output_list(obj) <- value
output_list(obj) output_list(obj) <- value ## S4 method for signature 'struct_class' output_list(obj) ## S4 replacement method for signature 'struct_class,list' output_list(obj) <- value
obj |
An object derived from struct_class |
value |
A named list of outputs and corresponding values |
A named list of outputs and corresponding values
struct object
M = example_model() L = output_list(M) M = example_model() output_list(M) = list('result_1' = DatasetExperiment(),'result_2' = DatasetExperiment())
M = example_model() L = output_list(M) M = example_model() output_list(M) = list('result_1' = DatasetExperiment(),'result_2' = DatasetExperiment())
return a the name for a output, if available
output_name(obj, name) ## S4 method for signature 'struct_class,character' output_name(obj, name)
output_name(obj, name) ## S4 method for signature 'struct_class,character' output_name(obj, name)
obj |
A model or iterator object derived from the *struct* class |
name |
Name of output |
name of output
M = example_model() output_name(M,'result_1')
M = example_model() output_name(M,'result_1')
Gets or sets the object of an output e.g. to an entity() object.
output_obj(obj, name) output_obj(obj, name) <- value ## S4 method for signature 'struct_class,character' output_obj(obj, name) ## S4 replacement method for signature 'struct_class,character' output_obj(obj, name) <- value
output_obj(obj, name) output_obj(obj, name) <- value ## S4 method for signature 'struct_class,character' output_obj(obj, name) ## S4 replacement method for signature 'struct_class,character' output_obj(obj, name) <- value
obj |
A model or iterator object derived from the *struct* class |
name |
Name of output |
value |
A valid value for the output being set |
output_obj(M,name)
returns the named output as an object
output_obj(M,name)<-
sets the named output of an object
the modified object
# get the output as an object M = example_model() obj = output_obj(M, 'result_1') # set a output as an object output_obj(M, 'result_1') = entity(value = 15,type = 'numeric',name = 'result_1')
# get the output as an object M = example_model() obj = output_obj(M, 'result_1') # set a output as an object output_obj(M, 'result_1') = entity(value = 15,type = 'numeric',name = 'result_1')
get/set the values for an output_
output_value(obj, name) output_value(obj, name) <- value ## S4 method for signature 'struct_class,character' output_value(obj, name) ## S4 replacement method for signature 'struct_class,character' output_value(obj, name) <- value
output_value(obj, name) output_value(obj, name) <- value ## S4 method for signature 'struct_class,character' output_value(obj, name) ## S4 replacement method for signature 'struct_class,character' output_value(obj, name) <- value
obj |
A model or iterator object derived from the *struct* class |
name |
Name of output |
value |
A valid value for the output being set |
Value of output
struct object
M = example_model() output_value(M,'result_1') M = example_model() output_value(M,'result_1') = DatasetExperiment()
M = example_model() output_value(M,'result_1') M = example_model() output_value(M,'result_1') = DatasetExperiment()
return a list of valid parameter ids for an object
param_ids(obj) ## S4 method for signature 'struct_class' param_ids(obj)
param_ids(obj) ## S4 method for signature 'struct_class' param_ids(obj)
obj |
An object derived from struct_class |
list of parameter ids
M = example_model() param_ids(M)
M = example_model() param_ids(M)
get/set a named list of parameters and thier current value for an object
param_list(obj) param_list(obj) <- value ## S4 method for signature 'struct_class' param_list(obj) ## S4 replacement method for signature 'struct_class,list' param_list(obj) <- value
param_list(obj) param_list(obj) <- value ## S4 method for signature 'struct_class' param_list(obj) ## S4 replacement method for signature 'struct_class,list' param_list(obj) <- value
obj |
An object derived from struct_class |
value |
A named list of parameters and corresponding values |
A named list of parameters names and corresponding values
M = example_model() L = param_list(M) M = example_model() param_list(M) = list('value_1' = 15,'value_2' = 20)
M = example_model() L = param_list(M) M = example_model() param_list(M) = list('value_1' = 15,'value_2' = 20)
Returns the name for a parameter, if available
param_name(obj, name) ## S4 method for signature 'struct_class,character' param_name(obj, name)
param_name(obj, name) ## S4 method for signature 'struct_class,character' param_name(obj, name)
obj |
An object derived from struct_class |
name |
Name of parameter |
name of parameter
M = example_model() param_name(M,'value_1')
M = example_model() param_name(M,'value_1')
Gets or sets the object of a parameter e.g. to an entity() object.
param_obj(obj, name) param_obj(obj, name) <- value ## S4 replacement method for signature 'struct_class,character' param_obj(obj, name) <- value ## S4 method for signature 'struct_class,character' param_obj(obj, name)
param_obj(obj, name) param_obj(obj, name) <- value ## S4 replacement method for signature 'struct_class,character' param_obj(obj, name) <- value ## S4 method for signature 'struct_class,character' param_obj(obj, name)
obj |
An object derived from struct_class |
name |
Name of parameter |
value |
A valid value for the parameter being set |
param_obj(M,name)
Returns the named parameter as an object
param_obj(M,name)<-
Sets the named parameter of an object
# get the parameter as an object M = example_model() obj = param_obj(M, 'value_0') # set a parameter as an object param_obj(M, 'value_0') = entity(value = 15,type = 'numeric',name='value_0')
# get the parameter as an object M = example_model() obj = param_obj(M, 'value_0') # set a parameter as an object param_obj(M, 'value_0') = entity(value = 15,type = 'numeric',name='value_0')
get/set the values for a parameter.
param_value(obj, name) param_value(obj, name) <- value ## S4 method for signature 'struct_class,character' param_value(obj, name) ## S4 replacement method for signature 'struct_class,character' param_value(obj, name) <- value
param_value(obj, name) param_value(obj, name) <- value ## S4 method for signature 'struct_class,character' param_value(obj, name) ## S4 replacement method for signature 'struct_class,character' param_value(obj, name) <- value
obj |
A model or iterator object derived from structclass |
name |
Name of parameter |
value |
A valid value for the parameter being set |
Value of parameter
M = example_model() param_value(M,'value_1') M = example_model() param_value(M,'value_1') = 0.95
M = example_model() param_value(M,'value_1') M = example_model() param_value(M,'value_1') = 0.95
returns the prediction output for a model_ This is supplied as input to the next model when used in a model_seq
predicted(M)
predicted(M)
M |
a model object |
The value returned varies depending on the output_
M = example_model() M = model_train(M, iris_DatasetExperiment()) M = model_predict(M, iris_DatasetExperiment()) predicted(M)
M = example_model() M = model_train(M, iris_DatasetExperiment()) M = model_predict(M, iris_DatasetExperiment()) predicted(M)
get/set the prediction output for a model_ This determines which outputs from this model are supplied as inputs to the next model when used in a model_seq
predicted_name(M) predicted_name(M) <- value
predicted_name(M) predicted_name(M) <- value
M |
a model object |
value |
name of an output for this model |
predicted_name
returns the name of the predicted output
predicted_name<-
sets the name of the predicted output
M = example_model() predicted_name(M) predicted_name(M) = 'result_2'
M = example_model() predicted_name(M) predicted_name(M) = 'result_2'
A class used for preprocessing steps that require application to test sets. not intended to be called directly, this class should be inherited to provide functionality for method-specific classes.
preprocess(...) ## S4 method for signature 'preprocess,DatasetExperiment' model_reverse(M, D)
preprocess(...) ## S4 method for signature 'preprocess,DatasetExperiment' model_reverse(M, D)
... |
named slots and their values. |
M |
a model object |
D |
a dataset object |
dataset object
M = preprocess() D = DatasetExperiment() M = model() D2 = model_reverse(M,D)
M = preprocess() D = DatasetExperiment() M = model() D2 = model_reverse(M,D)
A class for resampling methods such as cross-validation. not intended to be called directly.
resampler(...)
resampler(...)
... |
named slots and their values. |
a resampler object
R = resampler()
R = resampler()
Returns the results of an iterator. This is used to control model flow in a
similar way to predict
for model and model_seq objects.
result(M)
result(M)
M |
an iterator object |
the returned output varies with the algorithm implemented
D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run result(I)
D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run result(I)
get/set the prediction output for a model_ This determines which outputs from this model are supplied as inputs to the next model when used in a model_seq
result_name(M) result_name(I) <- value
result_name(M) result_name(I) <- value
M |
an iterator object |
I |
an iterator object |
value |
name of an output for iterator M |
result_name(M)
returns the name of the output for this iterator
(equivalent to predicted
for model objects)
result_name(I)<-
sets the default output for an iterator
I = example_iterator() # initialise iterator result_name(I) result_name(I) = 'result_1'
I = example_iterator() # initialise iterator result_name(I) result_name(I) = 'result_1'
Runs an iterator, applying the chosen model multiple times.
Evaluates an iterator by e.g. averaging over all iterations. May be
deprecated in a future release as evaluate
is applied by run
anyway.
A class for iterative approaches that involve the training/prediction of a model multiple times. Not intended to be called directly, this class should be inherited to provide functionality for method-specific classes.
run(I, D, MET) evaluate(I, MET) iterator(...) ## S4 method for signature 'iterator,DatasetExperiment,metric' run(I, D, MET = NULL) ## S4 method for signature 'iterator,metric' evaluate(I, MET) ## S4 method for signature 'iterator' models(ML) ## S4 replacement method for signature 'iterator,model_OR_iterator' models(ML) <- value ## S4 replacement method for signature 'iterator,character' result_name(I) <- value ## S4 method for signature 'iterator' result(M) ## S4 method for signature 'iterator' result_name(M) ## S4 method for signature 'iterator,model_OR_iterator' e1 * e2 ## S4 method for signature 'iterator,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'iterator,ANY,ANY,ANY' x[i] <- value
run(I, D, MET) evaluate(I, MET) iterator(...) ## S4 method for signature 'iterator,DatasetExperiment,metric' run(I, D, MET = NULL) ## S4 method for signature 'iterator,metric' evaluate(I, MET) ## S4 method for signature 'iterator' models(ML) ## S4 replacement method for signature 'iterator,model_OR_iterator' models(ML) <- value ## S4 replacement method for signature 'iterator,character' result_name(I) <- value ## S4 method for signature 'iterator' result(M) ## S4 method for signature 'iterator' result_name(M) ## S4 method for signature 'iterator,model_OR_iterator' e1 * e2 ## S4 method for signature 'iterator,ANY,ANY,ANY' x[i] ## S4 replacement method for signature 'iterator,ANY,ANY,ANY' x[i] <- value
I |
an iterator object |
D |
a dataset object |
MET |
a metric object |
... |
named slots and their values. |
ML |
a model sequence object |
value |
value |
M |
a model object |
e1 |
an iterator object |
e2 |
an iterator or a model object |
x |
a sequence object |
i |
index into sequence |
Running an iterator will apply the iterator a number of times to a dataset_ For example, in cross-validation the same model is applied multiple times to the same data, splitting it into training and test sets. The input metric object can be calculated and collected for each iteration as an output_
Modified iterator object
Modified iterator object
the modified model object
model at the given index in the sequence
iterator with the model at index i replaced
D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run I = evaluate(I,MET) # evaluate I = iterator() I = iterator() * model() D = DatasetExperiment() MET = metric() I = iterator() * model() I = run(I,D,MET) I = iterator() result_name(I) = 'example' MS = model() + model() I = iterator() * MS I[2] # returns the second model() object MS = model() + model() I = iterator() * MS I[2] = model() # sets the second model to model()
D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run D = iris_DatasetExperiment() # get some data MET = metric() # use a metric I = example_iterator() # initialise iterator models(I) = example_model() # set the model I = run(I,D,MET) # run I = evaluate(I,MET) # evaluate I = iterator() I = iterator() * model() D = DatasetExperiment() MET = metric() I = iterator() * model() I = run(I,D,MET) I = iterator() result_name(I) = 'example' MS = model() + model() I = iterator() * MS I[2] # returns the second model() object MS = model() + model() I = iterator() * MS I[2] = model() # sets the second model to model()
get/set the input parameter replaced by the output of the previous model in
a model sequence. Default is "data" which passes the output as the data input
for methods such as model_train
and model_apply
.
seq_in(M) seq_in(M) <- value
seq_in(M) seq_in(M) <- value
M |
a model object |
value |
name of an output for this model |
seq_in
returns the name of the input parameter replaced when used in a model sequence
seq_in<-
sets the name of the input parameter replaced when used in a model sequence
M = example_model() seq_in(M) seq_in(M) = 'value_1'
M = example_model() seq_in(M) seq_in(M) = 'value_1'
a helper function to update methods for a struct object
set_obj_method( class_name, method_name, definition, where = topenv(parent.frame()), signature = c(class_name, "DatasetExperiment") )
set_obj_method( class_name, method_name, definition, where = topenv(parent.frame()), signature = c(class_name, "DatasetExperiment") )
class_name |
the name of the to update the method for |
method_name |
the name of the method to update. Must be an existing method for the object. |
definition |
the function to replace the method with. This function will be used when the method is called on the object. |
where |
the environment to create the object in. default where = topenv(parent.frame()) |
signature |
a list of classes that this object requires as inputs. Default is c(class_name,'DatasetExperiment') |
a method is created in the specified environment
set_struct_obj( class_name = 'add_two_inputs', struct_obj = 'model', params = c(input_1 = 'numeric', input_2 = 'numeric'), outputs = c(result = 'numeric'), prototype = list( input_1 = 0, input_2 = 0, name = 'Add two inputs', description = 'example class that adds two values together') )
set_struct_obj( class_name = 'add_two_inputs', struct_obj = 'model', params = c(input_1 = 'numeric', input_2 = 'numeric'), outputs = c(result = 'numeric'), prototype = list( input_1 = 0, input_2 = 0, name = 'Add two inputs', description = 'example class that adds two values together') )
a helper function to update the show method for a struct object
set_obj_show(class_name, extra_string, where = topenv(parent.frame()))
set_obj_show(class_name, extra_string, where = topenv(parent.frame()))
class_name |
the name of the to update the method for |
extra_string |
a function that returns an extra string using the input object as an input e.g. function(object)return = 'extra_string' |
where |
the environment to create the object in. default where = topenv(parent.frame()) |
a method is created in the specified environment
# create an example object first set_struct_obj( class_name = 'add_two_inputs', struct_obj = 'model', params = c(input_1 = 'numeric', input_2 = 'numeric'), outputs = c(result = 'numeric'), prototype = list( input_1 = 0, input_2 = 0, name = 'Add two inputs', description = 'example class that adds two values together') ) # now update the method set_obj_show( class_name = 'add_two_inputs', extra_string = function(object) {return('The extra text')} )
# create an example object first set_struct_obj( class_name = 'add_two_inputs', struct_obj = 'model', params = c(input_1 = 'numeric', input_2 = 'numeric'), outputs = c(result = 'numeric'), prototype = list( input_1 = 0, input_2 = 0, name = 'Add two inputs', description = 'example class that adds two values together') ) # now update the method set_obj_show( class_name = 'add_two_inputs', extra_string = function(object) {return('The extra text')} )
a helper function to create new struct objects
set_struct_obj( class_name, struct_obj, params = character(0), outputs = character(0), private = character(0), prototype = list() )
set_struct_obj( class_name, struct_obj, params = character(0), outputs = character(0), private = character(0), prototype = list() )
class_name |
the name of the new class to create |
struct_obj |
the struct obj to inherit e.g. 'model', 'metric' etc |
params |
a named character vector of input parameters where each element specifies the type of value that will be in the slot e.g. c(example = 'character') |
outputs |
a named character vector of outputs where each element specifies the type of value that will be in the slot e.g. c(example = 'character') |
private |
a named character vector of private slots where each element specifies the type of value that will be in the slot e.g. c(example = 'character'). These are intended for internal use by the object and generally not available to the user. |
prototype |
a named list with initial values for slots. |
a new class definition. to create a new object from this class use X = new_class_name()
A base class in the struct package. Provides several fundamental methods and should not be called directly.
stato_id(obj) stato_name(obj) stato_definition(obj) stato_summary(obj) stato(stato_id) ## S4 method for signature 'stato' stato_id(obj) ## S4 method for signature 'stato' stato_name(obj) ## S4 method for signature 'stato' stato_definition(obj) ## S4 method for signature 'stato' stato_summary(obj)
stato_id(obj) stato_name(obj) stato_definition(obj) stato_summary(obj) stato(stato_id) ## S4 method for signature 'stato' stato_id(obj) ## S4 method for signature 'stato' stato_name(obj) ## S4 method for signature 'stato' stato_definition(obj) ## S4 method for signature 'stato' stato_summary(obj)
obj |
An object derived from the stato object |
stato_id |
A STATO ID e.g. OBI:0000001 |
STATO is the statistical methods ontology. It contains concepts and properties related to statistical methods, probability distributions and other concepts related to statistical analysis, including relationships to study designs and plots (see http://stato-ontology.org/).
This class provides access to a version of the STATO ontology database that can be searched by ontology id to provide formal names and definitions for methods, models, iterators, metrics and charts.
This class makes use of the ontologyIndex
package to search a copy of
the STATO database included in this package.
id the stato id
name the stato name
def the stato description
Value returned depends on the method used.
M = example_model() stato_id(M) stato_name(M) stato_definition(M) stato_summary(M) # an example stato object M = example_model() # the stato id assigned to object M stato_id(M) # OBI:0000011 # the name associated with that id stato_name(M) # the STATO definition for that id stato_definition(M) # a summary of the STATO database entry for the id, and any parameters or # outputs that also have stato ids. stato_summary(M)
M = example_model() stato_id(M) stato_name(M) stato_definition(M) stato_summary(M) # an example stato object M = example_model() # the stato id assigned to object M stato_id(M) # OBI:0000011 # the name associated with that id stato_name(M) # the STATO definition for that id stato_definition(M) # a summary of the STATO database entry for the id, and any parameters or # outputs that also have stato ids. stato_summary(M)
Creates a new struct_class object and populates the slots. Not intended for direct use.
struct_class( name = character(0), description = character(0), type = character(0), citations = list(), ontology = character(0) )
struct_class( name = character(0), description = character(0), type = character(0), citations = list(), ontology = character(0) )
name |
the name of the object |
description |
a description of the object |
type |
the type of the struct object |
citations |
a list of citations for the object in "bibentry" format |
ontology |
a list of ontology items for the object in "ontology_item" format |
a struct_class object
struct_class
object definitionDefines the struct class base template. This class is inherited by other objects and not intended for direct use. It defines slots and methods common to all struct objects.
Returns a struct object
Public slots can be accessed using shorthand $ notation and are intended for users building workflows.
name
character()
A short descriptive name of the struct object
description
character()
A longer description of the struct object and what it does
type
character()
A keyword that describes the type of struct object
libraries
character()
A (read only) list of R packages used by this struct object
citations
list of bibentry
A (read only) list of citations relevant to this struct object,
in Bibtex format.
Private slots are not readily accessible to users and are intended for developers creating their own struct objects. Any slot not listed within '.params' or '.outputs' is considered a private slot.
.params
character()
A list of additional slot names that can be get/set by the user
for a specific struct object. These are used as input parameters for different methods.
.outputs
character()
a list of additional slot names that can be get by the user. These are
used to store the results of a method.
S = struct_class(name = 'Example',description = 'An example object')
S = struct_class(name = 'Example',description = 'An example object')
Create a struct template
struct_template( template = "model", output, in_editor = TRUE, overwrite = FALSE )
struct_template( template = "model", output, in_editor = TRUE, overwrite = FALSE )
template |
the type of object you want a template for e.g. 'model' |
output |
the name/path of the output file |
in_editor |
TRUE/FALSE to open the created file in the default editor |
overwrite |
= TRUE/FALSE to overwrite file if exists already |
A template is created at the output location specified
## Not run: struct_template('model','example.R',FALSE) ## End(Not run)
## Not run: struct_template('model','example.R',FALSE) ## End(Not run)
An example metric for testing
calculates a metric, which just returns a value of 3.142
## S4 method for signature 'test_metric' calculate(obj)
## S4 method for signature 'test_metric' calculate(obj)
obj |
metric object |
test metric object
dataset object
MET = test_metric() MET = test_metric() MET = calculate(MET)
MET = test_metric() MET = test_metric() MET = calculate(MET)