3
3
# ' Partial least squares (PLS) fold change estimates
4
4
# ' @export PLSFC
5
5
# ' @importFrom pls plsr scores
6
+ # ' @include fold_change_class.R
6
7
PLSFC <- setClass(
7
8
" PLSFC" ,
8
- contains = ' method ' ,
9
+ contains = ' fold_change ' ,
9
10
slots = c(
10
- params.factor_name = ' character' ,
11
- params.number_components = ' entity' ,
12
- params.control_group = ' character' ,
13
- outputs.fold_change = ' entity'
11
+ params.number_components = ' entity'
14
12
),
15
13
prototype = list (name = ' Partial least squares discriminant analysis' ,
16
14
type = " classification" ,
@@ -52,6 +50,7 @@ setMethod(f="method.apply",
52
50
53
51
D $ sample_meta [[M $ factor_name ]]= ordered(D $ sample_meta [[M $ factor_name ]])
54
52
BHAT = matrix (0 ,nrow = n ,ncol = ncol(X ))
53
+ SE = BHAT
55
54
# for all pairs of groups
56
55
for (A in 1 : (length(L )- 1 )) {
57
56
for (B in (A + 1 ): (length(L ))) {
@@ -76,6 +75,7 @@ setMethod(f="method.apply",
76
75
P = model.predict(P ,S )
77
76
sy = P $ design_matrix [,1 ]
78
77
sx = as.matrix(MC [2 ]$ scores )
78
+
79
79
# get regression coefficients
80
80
b = P $ reg_coeff [,1 ]
81
81
for (j in 1 : ncol(sx )) {
@@ -92,6 +92,15 @@ setMethod(f="method.apply",
92
92
Vx = as.matrix(MC [2 ]$ loadings )
93
93
bhat = t(bhat )%*% t(Vx )
94
94
95
+ # guestimate confidence intervals
96
+ x = MC [1 ]$ centred $ data
97
+ xhat = sy %*% (bhat )
98
+ ssx = (x - xhat )^ 2
99
+ ssx = apply(ssx ,2 ,sum ) # for each column of x
100
+ ssy = sum(sy ^ 2 ) # y_bar is zero by design
101
+ SE [counter ,]= (sqrt(ssx )/ (sqrt(ssy )* sqrt((nrow(x )- 2 ))))* qt(0.975 ,nrow(x )- 2 )* 2
102
+
103
+
95
104
BHAT [counter ,]= bhat * 2
96
105
97
106
counter = counter + 1
@@ -102,12 +111,16 @@ setMethod(f="method.apply",
102
111
}
103
112
104
113
FC = as.data.frame(t(BHAT ))
105
-
114
+ SE = as.data.frame(t( SE ))
106
115
colnames(FC )= comp
116
+ colnames(SE )= comp
107
117
108
118
rownames(FC )= colnames(D $ data )
119
+ rownames(SE )= colnames(D $ data )
109
120
110
121
M $ fold_change = 2 ^ FC
122
+ M $ upper_ci = 2 ^ (FC + SE )
123
+ M $ lower_ci = 2 ^ (FC - SE )
111
124
112
125
return (M )
113
126
}
0 commit comments