Browse code

Release 3 12 candidate (#32)

* fix base=10 regardless of input (see #15)

class constructor was always setting base to 10 instead of the input value

* merge bug fix 1.01 into dev (#19)

* bug fix issue #7

Correctly re-order the sample_meta column for colouring samples in the dendrogram plot

* version bump

bug fix issue #7

* fix for https://github.com/computational-metabolomics/structToolbox/issues/18 (#20)

correctly reorder the factor labels so that the control group always ends up in the denominator for the fold change calculation.

* fix for https://github.com/computational-metabolomics/structToolbox/issues/18

fixed incorrect length check on matching class labels.

* Issue 17 ttest factor (#21)

* convert to factor if not one already

fix for issue #17

* update roxygen version

* fix for issue #9 (#22)

changed from lapply to vapply and used drop=FALSE to ensure compatibility with a single factor.

* allow user to set lambda (#24)

- lambda changed to input parameter. NULL = uses pmp optimisation
- model_predict now uses the set value of lambda, or lambda_opt if used.
- documentation updated

* Feature non parametric fold change (#26)

* add "median" method

based on DOI: 10.1080/00949650212140 can now calcuate fold changes equivalent to using medians and corresponding confidence intervals

* update documentation

* update median method

now correctly calculates ratio of medians

* use wilcox for paired median intervals

make use of wilcox.test to estimate intervals for the median when using median for paired samples

* Issue 23 filter by name (#27)

* fix for #23

moved all model_apply functionality to model_predict so that model_train and model_predict can be used as well as model_apply

* update documentation

* Update mean_of_medians.R (#29)

fix for #28
- correctly loop over all levels in the named factor

* Feature documentation 3 12 (#31)

* update documentation

Description and inputs now pulled from the object definitions for consistency.

* fix definition of label_features

allows NULL and description updated

* replace non ascii characters

* export mixed_effect object

* use correct object name to generate documentation

* export mixed_effect object

* remove non ascii characters

* update tests with new object name

* add import for capture.output

* add import for capture.output

* use pca_biplot in tests

chart was renamed

* add utils import

* update struct dependency version

* update documentation

* update news, version bump

Gavin Rhys Lloyd authored on 25/10/2020 08:50:13 • GitHub committed on 25/10/2020 08:50:13
Showing 1 changed files
... ...
@@ -1,14 +1,5 @@
1
-#'linear model class
2
-#'
3
-#' Wrapper for R lm. See \code{lm} for details.
4
-#'
1
+#' @eval get_description('linear_model')
5 2
 #' @import struct
6
-#' @param formula The formula to use.
7
-#' @param na_action The action to take when missing values are present. Can any
8
-#' one of 'na.omit','na.fail','na.exclude' or 'na.pass'. Default is 'na.omit'.
9
-#' @param contrasts The contrasts for this model. If zero length then the default contrasts are used.
10
-#' @param ... additional slots and values passed to struct_class
11
-#' @return struct object
12 3
 #' @export linear_model
13 4
 #' @examples
14 5
 #' D = iris_DatasetExperiment()
... ...
@@ -43,27 +34,30 @@ linear_model = function(formula,na_action='na.omit',contrasts=list(),...) {
43 34
         adj_r_squared='entity'
44 35
 
45 36
     ),
46
-    prototype = list(name='Linear Model',
47
-        description='Used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.',
37
+    prototype = list(name='Linear model',
38
+        description=paste0(
39
+            'Linear models can be used to carry out ',
40
+            'regression, single stratum analysis of variance and analysis ',
41
+            'of covariance.'),
48 42
         type="regression",
49 43
         predicted='predicted_values',
50 44
         .params=c('formula','na_action','contrasts'),
51 45
         .outputs=c('lm','coefficients','residuals','fitted_values','predicted_values','r_squared','adj_r_squared'),
52
-
53
-        formula=entity(name='Model Formula',
54
-            description='Compact symbolic form of the equation to be fitted using a linear model_',
55
-            value=y~x,
56
-            type='formula',
57
-            max_length=Inf
58
-        ),
59
-        na_action=enum(name='NA Action',
60
-            description='The action to be taken when encoutering NA',
46
+        libraries='stats',
47
+        formula=ents$formula,
48
+        na_action=enum(name='NA action',
49
+            description=c(
50
+                'na.omit' = 'Incomplete cases are removed.',
51
+                'na.fail' = 'An error is thrown if NA are present.',
52
+                'na.exclude'='Incomplete cases are removed, and the output result is padded to the correct size using NA.',
53
+                'na.pass' = 'Does not apply a linear model if NA are present.'
54
+            ),
61 55
             value='na.omit',
62 56
             type='character',
63 57
             allowed=c('na.omit','na.fail','na.exclude','na.pass')
64 58
         ),
65 59
         contrasts=entity(name='Contrasts',
66
-            description='The contrasts associated with a factor. If zero length then the default contrasts are used.',
60
+            description='The contrasts associated with a factor.',
67 61
             type='list'
68 62
         ),
69 63
 
Browse code

fix/update examples

Gavin Rhys Lloyd authored on 07/02/2020 17:02:22
Showing 1 changed files
... ...
@@ -11,7 +11,9 @@
11 11
 #' @return struct object
12 12
 #' @export linear_model
13 13
 #' @examples
14
-#' M = linear_model()
14
+#' D = iris_DatasetExperiment()
15
+#' M = linear_model(formula = y~Species)
16
+#'
15 17
 linear_model = function(formula,na_action='na.omit',contrasts=list(),...) {
16 18
     out=struct::new_struct('linear_model',
17 19
         formula=formula,
Browse code

fix/update tests

Gavin Rhys Lloyd authored on 07/02/2020 09:54:30
Showing 1 changed files
... ...
@@ -12,10 +12,10 @@
12 12
 #' @export linear_model
13 13
 #' @examples
14 14
 #' M = linear_model()
15
-linear_model = function(formula,na_action='na_omit',contrasts=list(),...) {
15
+linear_model = function(formula,na_action='na.omit',contrasts=list(),...) {
16 16
     out=struct::new_struct('linear_model',
17 17
         formula=formula,
18
-        na_action=nna_action,
18
+        na_action=na_action,
19 19
         contrasts=contrasts,
20 20
         ...)
21 21
     return(out)
Browse code

update to use new struct class constructors

Gavin Rhys Lloyd authored on 06/02/2020 13:51:52
Showing 1 changed files
... ...
@@ -1,16 +1,23 @@
1 1
 #'linear model class
2 2
 #'
3
-#' wrapper for R lm.
3
+#' Wrapper for R lm. See \code{lm} for details.
4 4
 #'
5 5
 #' @import struct
6
+#' @param formula The formula to use.
7
+#' @param na_action The action to take when missing values are present. Can any
8
+#' one of 'na.omit','na.fail','na.exclude' or 'na.pass'. Default is 'na.omit'.
9
+#' @param contrasts The contrasts for this model. If zero length then the default contrasts are used.
6 10
 #' @param ... additional slots and values passed to struct_class
7 11
 #' @return struct object
8 12
 #' @export linear_model
9 13
 #' @examples
10 14
 #' M = linear_model()
11
-linear_model = function(...) {
12
-    out=.linear_model()
13
-    out=struct::new_struct(out,...)
15
+linear_model = function(formula,na_action='na_omit',contrasts=list(),...) {
16
+    out=struct::new_struct('linear_model',
17
+        formula=formula,
18
+        na_action=nna_action,
19
+        contrasts=contrasts,
20
+        ...)
14 21
     return(out)
15 22
 }
16 23
 
... ...
@@ -38,6 +45,8 @@ linear_model = function(...) {
38 45
         description='Used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.',
39 46
         type="regression",
40 47
         predicted='predicted_values',
48
+        .params=c('formula','na_action','contrasts'),
49
+        .outputs=c('lm','coefficients','residuals','fitted_values','predicted_values','r_squared','adj_r_squared'),
41 50
 
42 51
         formula=entity(name='Model Formula',
43 52
             description='Compact symbolic form of the equation to be fitted using a linear model_',
... ...
@@ -87,7 +96,6 @@ linear_model = function(...) {
87 96
     )
88 97
 )
89 98
 
90
-#' @param ... additional slots and values passed to struct_class
91 99
 #' @export
92 100
 #' @template model_train
93 101
 setMethod(f="model_train",
... ...
@@ -111,7 +119,6 @@ setMethod(f="model_train",
111 119
     }
112 120
 )
113 121
 
114
-#' @param ... additional slots and values passed to struct_class
115 122
 #' @export
116 123
 #' @template model_predict
117 124
 setMethod(f="model_predict",
Browse code

incremental changes to use struct class constructors

Gavin Rhys Lloyd authored on 04/02/2020 17:18:11
Showing 1 changed files
... ...
@@ -3,7 +3,7 @@
3 3
 #' wrapper for R lm.
4 4
 #'
5 5
 #' @import struct
6
-#' @param ... slots and values for the new object
6
+#' @param ... additional slots and values passed to struct_class
7 7
 #' @return struct object
8 8
 #' @export linear_model
9 9
 #' @examples
... ...
@@ -87,7 +87,7 @@ linear_model = function(...) {
87 87
     )
88 88
 )
89 89
 
90
-#' @param ... slots and values for the new object
90
+#' @param ... additional slots and values passed to struct_class
91 91
 #' @export
92 92
 #' @template model_train
93 93
 setMethod(f="model_train",
... ...
@@ -111,7 +111,7 @@ setMethod(f="model_train",
111 111
     }
112 112
 )
113 113
 
114
-#' @param ... slots and values for the new object
114
+#' @param ... additional slots and values passed to struct_class
115 115
 #' @export
116 116
 #' @template model_predict
117 117
 setMethod(f="model_predict",
Browse code

remove all params_ and outputs_ tags

also fix resulting duplicate slot name 'type' for mixed_effects

Gavin Rhys Lloyd authored on 04/02/2020 10:28:42
Showing 1 changed files
... ...
@@ -10,7 +10,7 @@
10 10
 #' M = linear_model()
11 11
 linear_model = function(...) {
12 12
     out=.linear_model()
13
-    out=struct::.initialize_struct_class(out,...)
13
+    out=struct::new_struct(out,...)
14 14
     return(out)
15 15
 }
16 16
 
... ...
@@ -20,18 +20,18 @@ linear_model = function(...) {
20 20
     contains='model',
21 21
     slots=c(
22 22
         # INPUTS
23
-        params_formula='entity',
24
-        params_na_action='enum',
25
-        params_contrasts='entity',
23
+        formula='entity',
24
+        na_action='enum',
25
+        contrasts='entity',
26 26
 
27 27
         # OUTPUTS
28
-        outputs_lm='entity',
29
-        outputs_coefficients='entity',
30
-        outputs_residuals='entity',
31
-        outputs_fitted_values='entity',
32
-        outputs_predicted_values='entity',
33
-        outputs_r_squared='entity',
34
-        outputs_adj_r_squared='entity'
28
+        lm='entity',
29
+        coefficients='entity',
30
+        residuals='entity',
31
+        fitted_values='entity',
32
+        predicted_values='entity',
33
+        r_squared='entity',
34
+        adj_r_squared='entity'
35 35
 
36 36
     ),
37 37
     prototype = list(name='Linear Model',
... ...
@@ -39,48 +39,48 @@ linear_model = function(...) {
39 39
         type="regression",
40 40
         predicted='predicted_values',
41 41
 
42
-        params_formula=entity(name='Model Formula',
42
+        formula=entity(name='Model Formula',
43 43
             description='Compact symbolic form of the equation to be fitted using a linear model_',
44 44
             value=y~x,
45 45
             type='formula',
46 46
             max_length=Inf
47 47
         ),
48
-        params_na_action=enum(name='NA Action',
48
+        na_action=enum(name='NA Action',
49 49
             description='The action to be taken when encoutering NA',
50 50
             value='na.omit',
51 51
             type='character',
52 52
             allowed=c('na.omit','na.fail','na.exclude','na.pass')
53 53
         ),
54
-        params_contrasts=entity(name='Contrasts',
54
+        contrasts=entity(name='Contrasts',
55 55
             description='The contrasts associated with a factor. If zero length then the default contrasts are used.',
56 56
             type='list'
57 57
         ),
58 58
 
59
-        outputs_lm=entity(name='Linear model object',
59
+        lm=entity(name='Linear model object',
60 60
             description='The lm object for this model_',
61 61
             type='lm'
62 62
         ),
63
-        outputs_coefficients=entity(name='Model coefficients',
63
+        coefficients=entity(name='Model coefficients',
64 64
             description='The coefficients for the fitted model_',
65 65
             type='numeric'
66 66
         ),
67
-        outputs_residuals=entity(name='Residuals',
67
+        residuals=entity(name='Residuals',
68 68
             description='The residuals for the fitted model_',
69 69
             type='numeric'
70 70
         ),
71
-        outputs_fitted_values=entity(name='Fitted values',
71
+        fitted_values=entity(name='Fitted values',
72 72
             description='The fitted values for the data used to train the model_',
73 73
             type='numeric'
74 74
         ),
75
-        outputs_predicted_values=entity(name='Predicted values',
75
+        predicted_values=entity(name='Predicted values',
76 76
             description='The predicted values for new data using the fitted model_',
77 77
             type='numeric'
78 78
         ),
79
-        outputs_r_squared=entity(name='R Squared',
79
+        r_squared=entity(name='R Squared',
80 80
             description='The value of R Squared for the fitted model_',
81 81
             type='numeric'
82 82
         ),
83
-        outputs_adj_r_squared=entity(name='Adjusted R Squared',
83
+        adj_r_squared=entity(name='Adjusted R Squared',
84 84
             description='The value ofAdjusted  R Squared for the fitted model_',
85 85
             type='numeric'
86 86
         )
Browse code

change "list" to "allowed" for enums

Gavin Rhys Lloyd authored on 04/02/2020 10:21:36
Showing 1 changed files
... ...
@@ -3,7 +3,7 @@
3 3
 #' wrapper for R lm.
4 4
 #'
5 5
 #' @import struct
6
-#' @param ... slots and values for the new object 
6
+#' @param ... slots and values for the new object
7 7
 #' @return struct object
8 8
 #' @export linear_model
9 9
 #' @examples
... ...
@@ -49,7 +49,7 @@ linear_model = function(...) {
49 49
             description='The action to be taken when encoutering NA',
50 50
             value='na.omit',
51 51
             type='character',
52
-            list=c('na.omit','na.fail','na.exclude','na.pass')
52
+            allowed=c('na.omit','na.fail','na.exclude','na.pass')
53 53
         ),
54 54
         params_contrasts=entity(name='Contrasts',
55 55
             description='The contrasts associated with a factor. If zero length then the default contrasts are used.',
... ...
@@ -87,7 +87,7 @@ linear_model = function(...) {
87 87
     )
88 88
 )
89 89
 
90
-#' @param ... slots and values for the new object 
90
+#' @param ... slots and values for the new object
91 91
 #' @export
92 92
 #' @template model_train
93 93
 setMethod(f="model_train",
... ...
@@ -111,7 +111,7 @@ setMethod(f="model_train",
111 111
     }
112 112
 )
113 113
 
114
-#' @param ... slots and values for the new object 
114
+#' @param ... slots and values for the new object
115 115
 #' @export
116 116
 #' @template model_predict
117 117
 setMethod(f="model_predict",
Browse code

add @return to documentation

Gavin Rhys Lloyd authored on 19/12/2019 15:14:02
Showing 1 changed files
... ...
@@ -4,6 +4,7 @@
4 4
 #'
5 5
 #' @import struct
6 6
 #' @param ... slots and values for the new object 
7
+#' @return struct object
7 8
 #' @export linear_model
8 9
 #' @examples
9 10
 #' M = linear_model()
Browse code

fix broken tests and...

...update some documentation

Gavin Rhys Lloyd authored on 17/12/2019 17:24:38
Showing 1 changed files
... ...
@@ -3,6 +3,7 @@
3 3
 #' wrapper for R lm.
4 4
 #'
5 5
 #' @import struct
6
+#' @param ... slots and values for the new object 
6 7
 #' @export linear_model
7 8
 #' @examples
8 9
 #' M = linear_model()
... ...
@@ -85,6 +86,7 @@ linear_model = function(...) {
85 86
     )
86 87
 )
87 88
 
89
+#' @param ... slots and values for the new object 
88 90
 #' @export
89 91
 #' @template model_train
90 92
 setMethod(f="model_train",
... ...
@@ -108,6 +110,7 @@ setMethod(f="model_train",
108 110
     }
109 111
 )
110 112
 
113
+#' @param ... slots and values for the new object 
111 114
 #' @export
112 115
 #' @template model_predict
113 116
 setMethod(f="model_predict",
Browse code

use class contructors and...

...rename all function with dot to underscore
replace dataset with DatasetExperiment

Gavin Rhys Lloyd authored on 17/12/2019 15:48:01
Showing 1 changed files
... ...
@@ -6,23 +6,30 @@
6 6
 #' @export linear_model
7 7
 #' @examples
8 8
 #' M = linear_model()
9
-linear_model<-setClass(
9
+linear_model = function(...) {
10
+    out=.linear_model()
11
+    out=struct::.initialize_struct_class(out,...)
12
+    return(out)
13
+}
14
+
15
+
16
+.linear_model<-setClass(
10 17
     "linear_model",
11 18
     contains='model',
12 19
     slots=c(
13 20
         # INPUTS
14
-        params.formula='entity',
15
-        params.na_action='enum',
16
-        params.contrasts='entity',
21
+        params_formula='entity',
22
+        params_na_action='enum',
23
+        params_contrasts='entity',
17 24
 
18 25
         # OUTPUTS
19
-        outputs.lm='entity',
20
-        outputs.coefficients='entity',
21
-        outputs.residuals='entity',
22
-        outputs.fitted_values='entity',
23
-        outputs.predicted_values='entity',
24
-        outputs.r_squared='entity',
25
-        outputs.adj_r_squared='entity'
26
+        outputs_lm='entity',
27
+        outputs_coefficients='entity',
28
+        outputs_residuals='entity',
29
+        outputs_fitted_values='entity',
30
+        outputs_predicted_values='entity',
31
+        outputs_r_squared='entity',
32
+        outputs_adj_r_squared='entity'
26 33
 
27 34
     ),
28 35
     prototype = list(name='Linear Model',
... ...
@@ -30,49 +37,49 @@ linear_model<-setClass(
30 37
         type="regression",
31 38
         predicted='predicted_values',
32 39
 
33
-        params.formula=entity(name='Model Formula',
34
-            description='Compact symbolic form of the equation to be fitted using a linear model.',
40
+        params_formula=entity(name='Model Formula',
41
+            description='Compact symbolic form of the equation to be fitted using a linear model_',
35 42
             value=y~x,
36 43
             type='formula',
37 44
             max_length=Inf
38 45
         ),
39
-        params.na_action=enum(name='NA Action',
46
+        params_na_action=enum(name='NA Action',
40 47
             description='The action to be taken when encoutering NA',
41 48
             value='na.omit',
42 49
             type='character',
43 50
             list=c('na.omit','na.fail','na.exclude','na.pass')
44 51
         ),
45
-        params.contrasts=entity(name='Contrasts',
52
+        params_contrasts=entity(name='Contrasts',
46 53
             description='The contrasts associated with a factor. If zero length then the default contrasts are used.',
47 54
             type='list'
48 55
         ),
49 56
 
50
-        outputs.lm=entity(name='Linear model object',
51
-            description='The lm object for this model.',
57
+        outputs_lm=entity(name='Linear model object',
58
+            description='The lm object for this model_',
52 59
             type='lm'
53 60
         ),
54
-        outputs.coefficients=entity(name='Model coefficients',
55
-            description='The coefficients for the fitted model.',
61
+        outputs_coefficients=entity(name='Model coefficients',
62
+            description='The coefficients for the fitted model_',
56 63
             type='numeric'
57 64
         ),
58
-        outputs.residuals=entity(name='Residuals',
59
-            description='The residuals for the fitted model.',
65
+        outputs_residuals=entity(name='Residuals',
66
+            description='The residuals for the fitted model_',
60 67
             type='numeric'
61 68
         ),
62
-        outputs.fitted_values=entity(name='Fitted values',
63
-            description='The fitted values for the data used to train the model.',
69
+        outputs_fitted_values=entity(name='Fitted values',
70
+            description='The fitted values for the data used to train the model_',
64 71
             type='numeric'
65 72
         ),
66
-        outputs.predicted_values=entity(name='Predicted values',
67
-            description='The predicted values for new data using the fitted model.',
73
+        outputs_predicted_values=entity(name='Predicted values',
74
+            description='The predicted values for new data using the fitted model_',
68 75
             type='numeric'
69 76
         ),
70
-        outputs.r_squared=entity(name='R Squared',
71
-            description='The value of R Squared for the fitted model.',
77
+        outputs_r_squared=entity(name='R Squared',
78
+            description='The value of R Squared for the fitted model_',
72 79
             type='numeric'
73 80
         ),
74
-        outputs.adj_r_squared=entity(name='Adjusted R Squared',
75
-            description='The value ofAdjusted  R Squared for the fitted model.',
81
+        outputs_adj_r_squared=entity(name='Adjusted R Squared',
82
+            description='The value ofAdjusted  R Squared for the fitted model_',
76 83
             type='numeric'
77 84
         )
78 85
     )
... ...
@@ -80,8 +87,8 @@ linear_model<-setClass(
80 87
 
81 88
 #' @export
82 89
 #' @template model_train
83
-setMethod(f="model.train",
84
-    signature=c("linear_model",'dataset'),
90
+setMethod(f="model_train",
91
+    signature=c("linear_model",'DatasetExperiment'),
85 92
     definition=function(M,D)
86 93
     {
87 94
         X=cbind(D$data,D$sample_meta)
... ...
@@ -103,8 +110,8 @@ setMethod(f="model.train",
103 110
 
104 111
 #' @export
105 112
 #' @template model_predict
106
-setMethod(f="model.predict",
107
-    signature=c("linear_model",'dataset'),
113
+setMethod(f="model_predict",
114
+    signature=c("linear_model",'DatasetExperiment'),
108 115
     definition=function(M,D)
109 116
     {
110 117
         X=cbind(D$data,D$sample_meta)
Browse code

update documentation and roxygen templates

grlloyd authored on 23/09/2019 14:26:49
Showing 1 changed files
... ...
@@ -102,6 +102,7 @@ setMethod(f="model.train",
102 102
 )
103 103
 
104 104
 #' @export
105
+#' @template model_predict
105 106
 setMethod(f="model.predict",
106 107
     signature=c("linear_model",'dataset'),
107 108
     definition=function(M,D)
Browse code

use model_train roxygen template

grlloyd authored on 23/09/2019 13:04:49
Showing 1 changed files
... ...
@@ -79,6 +79,7 @@ linear_model<-setClass(
79 79
 )
80 80
 
81 81
 #' @export
82
+#' @template model_train
82 83
 setMethod(f="model.train",
83 84
     signature=c("linear_model",'dataset'),
84 85
     definition=function(M,D)
Browse code

add r2 to outputs

grlloyd authored on 12/09/2019 14:02:34
Showing 1 changed files
... ...
@@ -20,7 +20,9 @@ linear_model<-setClass(
20 20
         outputs.coefficients='entity',
21 21
         outputs.residuals='entity',
22 22
         outputs.fitted_values='entity',
23
-        outputs.predicted_values='entity'
23
+        outputs.predicted_values='entity',
24
+        outputs.r_squared='entity',
25
+        outputs.adj_r_squared='entity'
24 26
 
25 27
     ),
26 28
     prototype = list(name='Linear Model',
... ...
@@ -64,6 +66,14 @@ linear_model<-setClass(
64 66
         outputs.predicted_values=entity(name='Predicted values',
65 67
             description='The predicted values for new data using the fitted model.',
66 68
             type='numeric'
69
+        ),
70
+        outputs.r_squared=entity(name='R Squared',
71
+            description='The value of R Squared for the fitted model.',
72
+            type='numeric'
73
+        ),
74
+        outputs.adj_r_squared=entity(name='Adjusted R Squared',
75
+            description='The value ofAdjusted  R Squared for the fitted model.',
76
+            type='numeric'
67 77
         )
68 78
     )
69 79
 )
... ...
@@ -82,6 +92,10 @@ setMethod(f="model.train",
82 92
         M$coefficients=coefficients(M$lm)
83 93
         M$residuals=residuals(M$lm)
84 94
         M$fitted_values=fitted(M$lm)
95
+
96
+        M$r_squared=summary(M$lm)$r.squared
97
+        M$adj_r_squared=summary(M$lm)$adj.r.squared
98
+
85 99
         return(M)
86 100
     }
87 101
 )
Browse code

stricter typing of slots for entity objects

due to update in struct base package

grlloyd authored on 10/09/2019 15:49:10
Showing 1 changed files
... ...
@@ -41,7 +41,7 @@ linear_model<-setClass(
41 41
             list=c('na.omit','na.fail','na.exclude','na.pass')
42 42
         ),
43 43
         params.contrasts=entity(name='Contrasts',
44
-            description='The contrasts associated with a factor. If NULL then the default contrasts are used.',
44
+            description='The contrasts associated with a factor. If zero length then the default contrasts are used.',
45 45
             type='list'
46 46
         ),
47 47
 
... ...
@@ -74,7 +74,7 @@ setMethod(f="model.train",
74 74
     definition=function(M,D)
75 75
     {
76 76
         X=cbind(D$data,D$sample_meta)
77
-        if (is.null(M$contrasts)) {
77
+        if (length(M$contrasts)==0) {
78 78
             M$lm=lm(formula = M$formula, na.action = M$na_action,data=X) # default contrasts
79 79
         } else {
80 80
             M$lm=lm(formula = M$formula, na.action = M$na_action, contrasts = M$contrasts,data=X)
Browse code

update 'type' and matching 'value' for prototype entity objects

grlloyd authored on 09/09/2019 14:35:21
Showing 1 changed files
... ...
@@ -31,7 +31,8 @@ linear_model<-setClass(
31 31
         params.formula=entity(name='Model Formula',
32 32
             description='Compact symbolic form of the equation to be fitted using a linear model.',
33 33
             value=y~x,
34
-            type='formula'
34
+            type='formula',
35
+            max_length=Inf
35 36
         ),
36 37
         params.na_action=enum(name='NA Action',
37 38
             description='The action to be taken when encoutering NA',
Browse code

update documentation and minor bioccheck fixes

grlloyd authored on 05/07/2019 13:06:15
Showing 1 changed files
... ...
@@ -4,7 +4,8 @@
4 4
 #'
5 5
 #' @import struct
6 6
 #' @export linear_model
7
-
7
+#' @examples
8
+#' M = linear_model()
8 9
 linear_model<-setClass(
9 10
     "linear_model",
10 11
     contains='model',
Browse code

change indentation for biocCheck

grlloyd authored on 24/05/2019 13:53:08
Showing 1 changed files
... ...
@@ -6,93 +6,93 @@
6 6
 #' @export linear_model
7 7
 
8 8
 linear_model<-setClass(
9
-  "linear_model",
10
-  contains='model',
11
-  slots=c(
12
-    # INPUTS
13
-    params.formula='entity',
14
-    params.na_action='enum',
15
-    params.contrasts='entity',
9
+    "linear_model",
10
+    contains='model',
11
+    slots=c(
12
+        # INPUTS
13
+        params.formula='entity',
14
+        params.na_action='enum',
15
+        params.contrasts='entity',
16 16
 
17
-    # OUTPUTS
18
-    outputs.lm='entity',
19
-    outputs.coefficients='entity',
20
-    outputs.residuals='entity',
21
-    outputs.fitted_values='entity',
22
-    outputs.predicted_values='entity'
17
+        # OUTPUTS
18
+        outputs.lm='entity',
19
+        outputs.coefficients='entity',
20
+        outputs.residuals='entity',
21
+        outputs.fitted_values='entity',
22
+        outputs.predicted_values='entity'
23 23
 
24
-  ),
25
-  prototype = list(name='Linear Model',
26
-                   description='Used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.',
27
-                   type="regression",
28
-                   predicted='predicted_values',
24
+    ),
25
+    prototype = list(name='Linear Model',
26
+        description='Used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.',
27
+        type="regression",
28
+        predicted='predicted_values',
29 29
 
30
-                   params.formula=entity(name='Model Formula',
31
-                                         description='Compact symbolic form of the equation to be fitted using a linear model.',
32
-                                         value=y~x,
33
-                                         type='formula'
34
-                   ),
35
-                   params.na_action=enum(name='NA Action',
36
-                                         description='The action to be taken when encoutering NA',
37
-                                         value='na.omit',
38
-                                         type='character',
39
-                                         list=c('na.omit','na.fail','na.exclude','na.pass')
40
-                   ),
41
-                   params.contrasts=entity(name='Contrasts',
42
-                                           description='The contrasts associated with a factor. If NULL then the default contrasts are used.',
43
-                                           type='list'
44
-                   ),
30
+        params.formula=entity(name='Model Formula',
31
+            description='Compact symbolic form of the equation to be fitted using a linear model.',
32
+            value=y~x,
33
+            type='formula'
34
+        ),
35
+        params.na_action=enum(name='NA Action',
36
+            description='The action to be taken when encoutering NA',
37
+            value='na.omit',
38
+            type='character',
39
+            list=c('na.omit','na.fail','na.exclude','na.pass')
40
+        ),
41
+        params.contrasts=entity(name='Contrasts',
42
+            description='The contrasts associated with a factor. If NULL then the default contrasts are used.',
43
+            type='list'
44
+        ),
45 45
 
46
-                   outputs.lm=entity(name='Linear model object',
47
-                                     description='The lm object for this model.',
48
-                                     type='lm'
49
-                   ),
50
-                   outputs.coefficients=entity(name='Model coefficients',
51
-                                               description='The coefficients for the fitted model.',
52
-                                               type='numeric'
53
-                   ),
54
-                   outputs.residuals=entity(name='Residuals',
55
-                                            description='The residuals for the fitted model.',
56
-                                            type='numeric'
57
-                   ),
58
-                   outputs.fitted_values=entity(name='Fitted values',
59
-                                                description='The fitted values for the data used to train the model.',
60
-                                                type='numeric'
61
-                   ),
62
-                   outputs.predicted_values=entity(name='Predicted values',
63
-                                                   description='The predicted values for new data using the fitted model.',
64
-                                                   type='numeric'
65
-                   )
66
-  )
46
+        outputs.lm=entity(name='Linear model object',
47
+            description='The lm object for this model.',
48
+            type='lm'
49
+        ),
50
+        outputs.coefficients=entity(name='Model coefficients',
51
+            description='The coefficients for the fitted model.',
52
+            type='numeric'
53
+        ),
54
+        outputs.residuals=entity(name='Residuals',
55
+            description='The residuals for the fitted model.',
56
+            type='numeric'
57
+        ),
58
+        outputs.fitted_values=entity(name='Fitted values',
59
+            description='The fitted values for the data used to train the model.',
60
+            type='numeric'
61
+        ),
62
+        outputs.predicted_values=entity(name='Predicted values',
63
+            description='The predicted values for new data using the fitted model.',
64
+            type='numeric'
65
+        )
66
+    )
67 67
 )
68 68
 
69 69
 #' @export
70 70
 setMethod(f="model.train",
71
-          signature=c("linear_model",'dataset'),
72
-          definition=function(M,D)
73
-          {
74
-            X=cbind(D$data,D$sample_meta)
75
-            if (is.null(M$contrasts)) {
76
-              M$lm=lm(formula = M$formula, na.action = M$na_action,data=X) # default contrasts
77
-            } else {
78
-              M$lm=lm(formula = M$formula, na.action = M$na_action, contrasts = M$contrasts,data=X)
79
-            }
80
-            M$coefficients=coefficients(M$lm)
81
-            M$residuals=residuals(M$lm)
82
-            M$fitted_values=fitted(M$lm)
83
-            return(M)
84
-          }
71
+    signature=c("linear_model",'dataset'),
72
+    definition=function(M,D)
73
+    {
74
+        X=cbind(D$data,D$sample_meta)
75
+        if (is.null(M$contrasts)) {
76
+            M$lm=lm(formula = M$formula, na.action = M$na_action,data=X) # default contrasts
77
+        } else {
78
+            M$lm=lm(formula = M$formula, na.action = M$na_action, contrasts = M$contrasts,data=X)
79
+        }
80
+        M$coefficients=coefficients(M$lm)
81
+        M$residuals=residuals(M$lm)
82
+        M$fitted_values=fitted(M$lm)
83
+        return(M)
84
+    }
85 85
 )
86 86
 
87 87
 #' @export
88 88
 setMethod(f="model.predict",
89
-          signature=c("linear_model",'dataset'),
90
-          definition=function(M,D)
91
-          {
92
-            X=cbind(D$data,D$sample_meta)
93
-            M$predicted_values(predict(M$lm,newdata = X))
94
-            return(M)
95
-          }
89
+    signature=c("linear_model",'dataset'),
90
+    definition=function(M,D)
91
+    {
92
+        X=cbind(D$data,D$sample_meta)
93
+        M$predicted_values(predict(M$lm,newdata = X))
94
+        return(M)
95
+    }
96 96
 )
97 97
 
98 98
 
Browse code

initial commit

Gavin Rhys Lloyd authored on 20/03/2019 15:54:08
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,103 @@
1
+#'linear model class
2
+#'
3
+#' wrapper for R lm.
4
+#'
5
+#' @import struct
6
+#' @export linear_model
7
+
8
+linear_model<-setClass(
9
+  "linear_model",
10
+  contains='model',
11
+  slots=c(
12
+    # INPUTS
13
+    params.formula='entity',
14
+    params.na_action='enum',
15
+    params.contrasts='entity',
16
+
17
+    # OUTPUTS
18
+    outputs.lm='entity',
19
+    outputs.coefficients='entity',
20
+    outputs.residuals='entity',
21
+    outputs.fitted_values='entity',
22
+    outputs.predicted_values='entity'
23
+
24
+  ),
25
+  prototype = list(name='Linear Model',
26
+                   description='Used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.',
27
+                   type="regression",
28
+                   predicted='predicted_values',
29
+
30
+                   params.formula=entity(name='Model Formula',
31
+                                         description='Compact symbolic form of the equation to be fitted using a linear model.',
32
+                                         value=y~x,
33
+                                         type='formula'
34
+                   ),
35
+                   params.na_action=enum(name='NA Action',
36
+                                         description='The action to be taken when encoutering NA',
37
+                                         value='na.omit',
38
+                                         type='character',
39
+                                         list=c('na.omit','na.fail','na.exclude','na.pass')
40
+                   ),
41
+                   params.contrasts=entity(name='Contrasts',
42
+                                           description='The contrasts associated with a factor. If NULL then the default contrasts are used.',
43
+                                           type='list'
44
+                   ),
45
+
46
+                   outputs.lm=entity(name='Linear model object',
47
+                                     description='The lm object for this model.',
48
+                                     type='lm'
49
+                   ),
50
+                   outputs.coefficients=entity(name='Model coefficients',
51
+                                               description='The coefficients for the fitted model.',
52
+                                               type='numeric'
53
+                   ),
54
+                   outputs.residuals=entity(name='Residuals',
55
+                                            description='The residuals for the fitted model.',
56
+                                            type='numeric'
57
+                   ),
58
+                   outputs.fitted_values=entity(name='Fitted values',
59
+                                                description='The fitted values for the data used to train the model.',
60
+                                                type='numeric'
61
+                   ),
62
+                   outputs.predicted_values=entity(name='Predicted values',
63
+                                                   description='The predicted values for new data using the fitted model.',
64
+                                                   type='numeric'
65
+                   )
66
+  )
67
+)
68
+
69
+#' @export
70
+setMethod(f="model.train",
71
+          signature=c("linear_model",'dataset'),
72
+          definition=function(M,D)
73
+          {
74
+            X=cbind(D$data,D$sample_meta)
75
+            if (is.null(M$contrasts)) {
76
+              M$lm=lm(formula = M$formula, na.action = M$na_action,data=X) # default contrasts
77
+            } else {
78
+              M$lm=lm(formula = M$formula, na.action = M$na_action, contrasts = M$contrasts,data=X)
79
+            }
80
+            M$coefficients=coefficients(M$lm)
81
+            M$residuals=residuals(M$lm)
82
+            M$fitted_values=fitted(M$lm)
83
+            return(M)
84
+          }
85
+)
86
+
87
+#' @export
88
+setMethod(f="model.predict",
89
+          signature=c("linear_model",'dataset'),
90
+          definition=function(M,D)
91
+          {
92
+            X=cbind(D$data,D$sample_meta)
93
+            M$predicted_values(predict(M$lm,newdata = X))
94
+            return(M)
95
+          }
96
+)
97
+
98
+
99
+
100
+
101
+
102
+
103
+