Skip to content

Commit e81abe5

Browse files
authored
just use RMSE
Just use RMSE since some time it could oppositive results with Q values
1 parent a2754a1 commit e81abe5

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

R/o2plscv.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ o2cv<-function(X, Y, nc, nx, ny, group=NULL, nr_folds = 5, ncores=1,
7272
res <- do.call("c",res)
7373
results <- as.data.frame(t(sapply(res, function(x)unlist(x))))
7474
results <- results%>%group_by(nc,nx,ny)%>%
75-
summarise(Qx=mean(Qx),Qy=mean(Qy),Px=mean(Px),Py=mean(Py),Rx=mean(Rx),Ry=mean(Ry))%>%
76-
mutate(RMSE=Rx+Ry,Qxy=sqrt(Qx^2+Qy^2))%>%arrange(desc(Qxy))
75+
summarise(Px=mean(Px),Py=mean(Py),Rx=mean(Rx),Ry=mean(Ry))%>%
76+
mutate(RMSE=Rx+Ry)%>%arrange(RMSE)
7777

7878
### results <- results%>%filter(Qx>=0,Qy>=0)
7979
### not sure if meaningful
8080
nc <- as.data.frame(results)[1,1]
8181
nx <- as.data.frame(results)[1,2]
8282
ny <- as.data.frame(results)[1,3]
83-
Qxy <- as.data.frame(results)[1,11]
84-
RMSE <- as.data.frame(results)[1,10]
83+
# Qxy <- as.data.frame(results)[1,11]
84+
RMSE <- as.data.frame(results)[1,8]
8585
message("#####################################")
8686
message("The best parameters are nc = ",nc,", nx = ",nx,", ny = ",ny)
8787
message("#####################################")
88-
message("The Qxy is ",Qxy, " and the RMSE is: ", RMSE)
88+
message("The the RMSE is: ", RMSE)
8989
message("#####################################")
9090
return(results)
9191
}
@@ -163,9 +163,11 @@ o2cv<-function(X, Y, nc, nx, ny, group=NULL, nr_folds = 5, ncores=1,
163163
# Restore to original values
164164
Xev <- X[cls.grp == k & is.na(cls.grp)==FALSE,]
165165
Yev <- Y[cls.grp == k & is.na(cls.grp)==FALSE,]
166-
167-
tmp <- list(k=k, nc=n, nx=nx, ny=ny, Qx=abs(Q(Xev,X_hat)),
168-
Qy=abs(Q(Yev,Y_hat)),Px=s2(Xev-X_hat),Py=s2(Yev-Y_hat),
166+
#####
167+
#### just use the RMSE to determine the best paramaters
168+
### some thing shown wrong results with Q values
169+
tmp <- list(k=k, nc=n, nx=nx, ny=ny,
170+
Px=s2(Xev-X_hat),Py=s2(Yev-Y_hat),
169171
Rx=rcpp_rmse(Xev,X_hat),Ry=rcpp_rmse(Yev,Y_hat))
170172
results <- append(results, list(tmp))
171173
}

R/plot.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ plot.O2pls <- function(x, type = "score", var = "Xjoint",group = NULL,
149149
#' @importFrom stats reorder
150150
#' @param x an o2plsda object
151151
#' @param type score, vip or loading
152-
#' @param var specify Xjoint
153152
#' @param group color used for score plot
154153
#' @param ind which components to be used for score plot or loading plot
155154
#' @param color color used for score or loading plot
@@ -172,14 +171,19 @@ plot.O2pls <- function(x, type = "score", var = "Xjoint",group = NULL,
172171
#' plot(fit0, type="score", group = factor(yy))
173172
#' @export
174173
#' @author Kai Guo
175-
plot.o2plsda <- function(x,type = "score", var = "Xjoint",group = NULL,
174+
plot.o2plsda <- function(x,type = "score",group = NULL,
176175
ind = c(1,2), color = NULL,
177176
top = 20, ellipse = TRUE,order=FALSE,
178177
pt.size = 3, label = TRUE, label.size = 4,
179178
repel=FALSE, rotation =FALSE,...){
180179
if(type == "score"){
181180
dd <- scores(x)
182-
va <- x$xvar[2,ind]
181+
if(x$ncomp==1){
182+
va <- x$xvar[2,1]
183+
}else{
184+
va <- x$xvar[2,ind]
185+
}
186+
183187
dd <- as.data.frame(dd)
184188
if(ncol(dd)==1){
185189
dd <- dd[, 1, drop = FALSE]
@@ -216,8 +220,12 @@ plot.o2plsda <- function(x,type = "score", var = "Xjoint",group = NULL,
216220
if(isTRUE(ellipse)&!is.null(group)){
217221
p <- p + stat_ellipse()
218222
}
223+
if(ncol(dd)==1){
224+
p <- p + xlab(paste0("LV",ind[1],"(",round(va[1]*100,2),"%)"))
225+
}else{
219226
p <- p + xlab(paste0("LV",ind[1],"(",round(va[1]*100,2),"%)"))+
220227
ylab(xlab(paste0("LV",ind[2],"(",round(va[2]*100,2),"%)")))
228+
}
221229
p <- p + theme_classic(base_size =14)
222230
}
223231
if(type == "vip"){
@@ -368,8 +376,12 @@ plot.plsda <- function(x,type = "score",group = NULL,
368376
if(isTRUE(ellipse)&!is.null(group)){
369377
p <- p + stat_ellipse()
370378
}
379+
if(ncol(dd)==1){
380+
p <- p + xlab(paste0("LV",ind[1],"(",round(va[1]*100,2),"%)"))
381+
}else{
371382
p <- p + xlab(paste0("LV",ind[1],"(",round(va[1]*100,2),"%)"))+
372383
ylab(xlab(paste0("LV",ind[2],"(",round(va[2]*100,2),"%)")))
384+
}
373385
p <- p + theme_classic(base_size =14)
374386
}
375387
if(type == "vip"){

0 commit comments

Comments
 (0)