Skip to content

Commit

Permalink
Replace methods::as with Matrix::Matrix; import Matrix functions indi…
Browse files Browse the repository at this point in the history
…vidually
  • Loading branch information
SiWen314 committed Aug 9, 2024
1 parent 698d8cf commit 369f39b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Rpackage/iMRMC/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Encoding: UTF-8
LazyData: true
Depends: R (>= 3.5.0)
RoxygenNote: 7.3.2
Imports: stats, Matrix, methods
Imports: stats, Matrix
Suggests: testthat
4 changes: 2 additions & 2 deletions Rpackage/iMRMC/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export(successDFtoROCdf)
export(uStat11.conditionalD)
export(uStat11.jointD)
export(undoIMRMCdf)
import(Matrix)
import(parallel)
import(utils)
importFrom(methods,as)
importFrom(Matrix,Matrix)
importFrom(Matrix,tcrossprod)
importFrom(stats,aov)
importFrom(stats,model.matrix)
importFrom(stats,qnorm)
Expand Down
11 changes: 5 additions & 6 deletions Rpackage/iMRMC/R/limitsOfAgreement.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
#'
#'
#' @importFrom stats aov var qnorm model.matrix
#' @importFrom methods as
#' @import Matrix
#' @importFrom Matrix Matrix tcrossprod
#' @export
#'
#' @examples
Expand Down Expand Up @@ -625,7 +624,7 @@ anova3 <- function(df.A, df.B, if.aov = TRUE, type = 1, reader.first = TRUE,
## Compute SS and coefficient for the variance components
R.full <- RSS(X,Y,output.q = T,is.sparseQR = is.sparseQR)
if(is.sparseQR){
sparseX <- as(X[,R.full$ind],"sparseMatrix")
sparseX <- Matrix(X[,R.full$ind],sparse = TRUE)
}else{
sparseX <- NULL
}
Expand Down Expand Up @@ -702,7 +701,7 @@ anova3 <- function(df.A, df.B, if.aov = TRUE, type = 1, reader.first = TRUE,
if(is.sparseQR){
X<-model.matrix(~ readerID + caseID + modalityID + readerID:modalityID + caseID:modalityID,
data = df_2Modality)
sparseX<-as(X[,R.no_RC$ind],"sparseMatrix")
sparseX<-Matrix(X[,R.no_RC$ind],sparse=TRUE)
}
R.RM_C <- RSS(seq(1,nR*nM+nC-1),Y,R.no_RC$q, R.no_RC$ind,is.sparseQR,sparseX, Xrc = X_rc, Xcm = X_cm)

Expand Down Expand Up @@ -768,7 +767,7 @@ RSS <- function(X, Y, q=NULL,ind=NULL, is.sparseQR=F, sparseX=NULL,
ind <- decom$pivot[1:k]

if(is.sparseQR){
decom2<- qr(as(X[,ind],"sparseMatrix"))
decom2<- qr(Matrix(X[,ind],sparse=TRUE))
q <- qr.Q(decom2)
}else{
q <- qr.Q(decom)[,1:k]
Expand Down Expand Up @@ -801,7 +800,7 @@ RSS <- function(X, Y, q=NULL,ind=NULL, is.sparseQR=F, sparseX=NULL,
X_res <- list(Xr, Xc, Xrc, Xrm, Xcm)


coef_var <- unlist(lapply(X_res, function(X) if(!is.null(X)) sum(diag(M %*% tcrossprod(as(X,"sparseMatrix")))) else 0))
coef_var <- unlist(lapply(X_res, function(X) if(!is.null(X)) sum(diag(as.matrix(M %*% tcrossprod(Matrix(X,sparse=TRUE))))) else 0))
if((!output.q) | is.sparseQR){
q=NULL
}
Expand Down

0 comments on commit 369f39b

Please sign in to comment.