Skip to content

Commit

Permalink
fixed gen3 library
Browse files Browse the repository at this point in the history
  • Loading branch information
selbouhaddani committed Oct 15, 2024
1 parent 249f22b commit 650e46b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LazyData: TRUE
LinkingTo: Rcpp, RcppArmadillo
Imports:
stats, utils, MASS, OmicsPLS, Rcpp, RcppArmadillo, dplyr, tibble, magrittr, parallel
RoxygenNote: 7.1.2
RoxygenNote: 7.3.2
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
3 changes: 1 addition & 2 deletions R/PO2PLS_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#'
#' Maintainer: Said el Bouhaddani (\email{s.el_bouhaddani@@outlook.com}).
#'
#' @docType package
#' @name PO2PLS-package
#' @keywords Probabilistic-O2PLS
#' @import OmicsPLS Rcpp RcppArmadillo magrittr dplyr tibble parallel
Expand All @@ -19,7 +18,7 @@
#' @importFrom stats pchisq rnorm runif sd
#' @importFrom MASS ginv
#' @useDynLib PO2PLS, .registration=TRUE
NULL
"_PACKAGE"

#' Construct a block-diagonal matrix
#'
Expand Down
36 changes: 18 additions & 18 deletions R/PO2PLS_gen3.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
library(OmicsPLS)
library(PO2PLS)
# library(OmicsPLS)
# library(PO2PLS)

# p <- 10
# q <- 11
Expand All @@ -9,15 +9,15 @@ library(PO2PLS)
# ry <- 1
# prm <- generate_params(p, q, r, rx, ry)
# prm3 <- generate_params(p, p3, r, rx, ry)
#
#
# prm
# prm3


gen_par3 <- function(p1, p2, p3, r, rx1, rx2, rx3, alpha = 0.1){
prm <- generate_params(p1, p2, r, rx1, rx2, alpha)
prm3 <- generate_params(p3, p2, r, rx3, rx2, alpha)
list(W1 = prm$W,
list(W1 = prm$W,
W2 = prm$C,
W3 = prm3$W,
Wo1 = prm$Wo,
Expand All @@ -41,61 +41,61 @@ gen_dat3 <- function(N, params, alpha_out = 0.1, sparse = FALSE){
Wo1 <- params$Wo1
Wo2 <- params$Wo2
Wo3 <- params$Wo3

r <- ncol(W1)
rx1 <- ncol(Wo1)
rx2 <- ncol(Wo2)
rx3 <- ncol(Wo3)
p1 <- nrow(W1)
p2 <- nrow(W2)
p3 <- nrow(W3)

if(sparse){
W1[-(1:(p1/4)),] <- 0
W2[-(1:(p2/4)),] <- 0
W3[-(1:(p3/4)),] <- 0
}
# print(W1)

SigT = params$SigT
SigTo1 = params$SigTo1 + 1e-06 * SigT[1] * (params$SigTo1[1] == 0)
SigTo2 = params$SigTo2 + 1e-06 * SigT[1] * (params$SigTo2[1] == 0)
SigTo3 = params$SigTo3 + 1e-06 * SigT[1] * (params$SigTo3[1] == 0)

N <- 3/2 * N

Tt <- matrix(rnorm(N * r), N, r) %*% chol(SigT)
To1 <- matrix(rnorm(N * rx1), N, rx1) %*% chol(SigTo1)
To2 <- matrix(rnorm(N * rx2), N, rx2) %*% chol(SigTo2)
To3 <- matrix(rnorm(N * rx3), N, rx3) %*% chol(SigTo3)

E1 <- matrix(rnorm(N * p1), N, p1) * sqrt(params$sig2E1)
E2 <- matrix(rnorm(N * p2), N, p2) * sqrt(params$sig2E2)
E3 <- matrix(rnorm(N * p3), N, p3) * sqrt(params$sig2E3)

X1 <- Tt %*% t(W1) + To1 %*% t(Wo1) + E1
X2 <- Tt %*% t(W2) + To2 %*% t(Wo2) + E2
X3 <- Tt %*% t(W3) + To3 %*% t(Wo3) + E3

outc <- Tt %*% params$beta_T
outc <- outc + rnorm(N, 0, sd = sqrt( alpha_out/(1-alpha_out)*var(outc) ))

indx1 <- order(outc)[1:(N/3)]
indx2 <- order(-outc)[1:(N/3)]
indxN <- c(indx1, indx2)

outc_bin <- 1*(outc > 0)
outc_bin <- outc_bin[indxN]

#print((indxN))
#print(str(X1))

X1 <- X1[indxN,]
X2 <- X2[indxN,]
X3 <- X3[indxN,]

return(list(X1 = X1, X2 = X2, X3 = X3, outc = outc_bin))

}


Expand Down
2 changes: 0 additions & 2 deletions R/PO2PLS_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ print.loglik.po2m <- function(x, digits=3, ...){
#' @export
LRT <- function(fit, fit0, digits=3, ...) UseMethod("LRT")

#' @inherit LRT
#'
#' @rdname LRT
#' @export
LRT.po2m <- function(fit, fit0, digits=3, ...){
Expand Down

0 comments on commit 650e46b

Please sign in to comment.