Skip to content

Commit a175213

Browse files
committed
add r2 to outputs
1 parent 801f46b commit a175213

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Collate:
2525
'blank_filter_class.R'
2626
'classical_lsq_class.R'
2727
'confounders_clsq_class.R'
28+
'corr_coef_class.R'
2829
'd_ratio_filter_class.R'
2930
'dataset_chart_classes.R'
3031
'factor_barchart_class.R'

R/classical_lsq_class.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ classical_lsq<-setClass(
3434
# OUTPUTS
3535
outputs.coefficients='entity',
3636
outputs.p_value='entity.stato',
37-
outputs.significant='entity'
37+
outputs.significant='entity',
38+
outputs.r_squared='entity',
39+
outputs.adj_r_squared='entity'
3840
),
3941
prototype = list(name='Univariate Classical Least Squares Regression',
4042
description='classical least squares, where y is the response and x is the design matrix, applied to each feature individually.',
@@ -76,6 +78,14 @@ classical_lsq<-setClass(
7678
outputs.significant=entity(name='Significant features',
7779
type='data.frame',
7880
description='TRUE if the calculated p-value is less than the supplied threhold (alpha)'
81+
),
82+
outputs.r_squared=entity(name='R Squared',
83+
description='The value of R Squared for the fitted model.',
84+
type='data.frame'
85+
),
86+
outputs.adj_r_squared=entity(name='Adjusted R Squared',
87+
description='The value ofAdjusted R Squared for the fitted model.',
88+
type='data.frame'
7989
)
8090
)
8191
)
@@ -149,6 +159,12 @@ setMethod(f="method.apply",
149159

150160
M$p_value=df2
151161

162+
df3=data.frame('r_squared'=unlist(lapply(out,function(x){return(x$r.squared)})))
163+
df4=data.frame('adj_r_squared'=unlist(lapply(out,function(x){return(x$adj.r.squared)})))
164+
rownames(df3)=rownames(df)
165+
rownames(df4)=rownames(df)
166+
M$r_squared=df3
167+
M$adj_r_squared=df4
152168

153169
# fdr correct the p-values
154170
M$p_value=as.data.frame(apply(M$p_value,2,FUN=function(x) {p.adjust(x,M$mtc)}))

R/linear_model_class.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ linear_model<-setClass(
2020
outputs.coefficients='entity',
2121
outputs.residuals='entity',
2222
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'
2426

2527
),
2628
prototype = list(name='Linear Model',
@@ -64,6 +66,14 @@ linear_model<-setClass(
6466
outputs.predicted_values=entity(name='Predicted values',
6567
description='The predicted values for new data using the fitted model.',
6668
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'
6777
)
6878
)
6979
)
@@ -82,6 +92,10 @@ setMethod(f="model.train",
8292
M$coefficients=coefficients(M$lm)
8393
M$residuals=residuals(M$lm)
8494
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+
8599
return(M)
86100
}
87101
)

0 commit comments

Comments
 (0)