Skip to content

Commit

Permalink
after fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dpc10ster committed Apr 18, 2024
1 parent 3f1d276 commit 4819381
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 103 deletions.
95 changes: 95 additions & 0 deletions R/PseudovaluesSP_A.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# simplified for debugging
PseudovaluesSP_A <- function(dataset, FOM) {

NL <- dataset$ratings$NL
LL <- dataset$ratings$LL
maxNL <- dim(NL)[4]
maxLL <- dim(LL)[4]
I <- dim(NL)[1]
J <- dim(NL)[2]
K <- dim(NL)[3]
K2 <- dim(LL)[3]
K1 <- K - K2

t <- dataset$descriptions$truthTableStr

jkFomValues <- array(dim = c(I, J/I, K))
jkPseudoValues <- array(dim = c(I, J/I, K))

fomArray <- FOM_SP(dataset, FOM)

lastCase <- 0
caseTransitions <- array(dim = J)
for (i in 1:I) {
for (j in (J/I*(i-1)+1):(J/I*i)) {
j1 <- j-J/I*(i-1)
perCase_ij <- dataset$lesions$perCase
lID_ij <- dataset$lesions$IDs
lW_ij <- dataset$lesions$weights
nl_ij <- NL[i, j, 1:K, 1:maxNL]; dim(nl_ij) <- c(K, maxNL)
ll_ij <- LL[i, j, 1:K2, 1:maxLL]; dim(ll_ij) <- c(K2, maxLL)

for (k in 1:K) {
if (k <= K1) {
nl_ij_jk <- nl_ij[-k, ];dim(nl_ij_jk) <- c(K - 1, maxNL)
ll_ij_jk <- ll_ij;dim(ll_ij_jk) <- c(K2, maxLL)
lID_ij_jk <- lID_ij;dim(lID_ij_jk) <- c(K2, maxLL)
lW_ij_jk <- lW_ij;dim(lW_ij_jk) <- c(K2, maxLL)
jkFomValues[i, j1, k] <-
MyFom_ij_SP(nl_ij_jk, ll_ij_jk, perCase_ij,
lID_ij_jk, lW_ij_jk, maxNL, maxLL,
K1 - 1, K2, FOM)

jkPseudoValues[i, j1, k] <-
fomArray[i, j1] * K - jkFomValues[i, j1, k] * (K - 1)
} else { # (k > K1)
nl_ij_jk <- nl_ij[-k, ];dim(nl_ij_jk) <- c(K - 1, maxNL)
ll_ij_jk <- ll_ij[-(k - K1), ];dim(ll_ij_jk) <- c(K2 - 1, maxLL)
lV_ij_jk <- perCase_ij[-(k - K1)]
lW_ij_jk <- lW_ij[-(k - K1), ];dim(lW_ij_jk) <- c(K2 - 1, maxLL)
lID_ij_jk <- lID_ij[-(k - K1), ];dim(lID_ij_jk) <- c(K2 - 1, maxLL)
jkFomValues[i, j1, k] <-
MyFom_ij_SP(nl_ij_jk, ll_ij_jk, lV_ij_jk,
lID_ij_jk, lW_ij_jk, maxNL, maxLL,
K1, K2 - 1, FOM)
jkPseudoValues[i, j1, k] <-
fomArray[i, j1] * K - jkFomValues[i, j1, k] * (K - 1)
}
}
# center the pseudovalues
if (FOM %in% c("MaxNLF", "ExpTrnsfmSp", "HrSp")) {
# FOMs defined over NORMAL cases
jkPseudoValues[i, j1, ] <- jkPseudoValues[i, j1, ] +
(fomArray[i, j1] - mean(jkPseudoValues[i, j1, ]))
} else if (FOM %in% c("MaxLLF", "HrSe")) {
# FOMs defined over ABNORMAL cases
jkPseudoValues[i, j1, ] <-
jkPseudoValues[i, j1, ] +
(fomArray[i, j1] - mean(jkPseudoValues[i, j1, ]))
} else {
# FOMs defined over ALL cases
jkPseudoValues[i, j1, ] <-
jkPseudoValues[i, j1, ] + (fomArray[i, j1] - mean(jkPseudoValues[i, j1, ]))
}
caseTransitions[j] <- lastCase
lastCase <- (lastCase + K) %% K
}
}

# there should not be any NAs in each of the following arrays
# any(is.na(jkPseudoValues))
# [1] FALSE
# any(is.na(jkFomValues))
# [1] FALSE
# any(is.na(fomArray))
# [1] FALSE

caseTransitions <- c(caseTransitions, K)
return(list(
jkPseudoValues = jkPseudoValues,
jkFomValues = jkFomValues,
caseTransitions = caseTransitions
))
}


10 changes: 5 additions & 5 deletions R/StSP.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ convert2dataset <- function(NL, LL, LL_IL,



FOM_SP <- function(dataset, FOM = "wAFROC") { # dpc
FOM_SP <- function(dataset, FOM) {

# dataType <- dataset$descriptions$type
# if (dataType == "ROC" && FOM != "Wilcoxon") {
Expand Down Expand Up @@ -665,9 +665,9 @@ FOM_SP <- function(dataset, FOM = "wAFROC") { # dpc

modalityID <- dataset$descriptions$modalityID
# readers in other treatments can have same names as there is not need to
# distinguish between them - by definition readers with same names in
# distinguish between them as, readers with same names in
# different treatments are different readers
readerID <- dataset$descriptions$readerID[1:(J/2)]
readerID <- dataset$descriptions$readerID[1:(J/I)]
rownames(fomArray) <- paste("trt", sep = "", modalityID)
colnames(fomArray) <- paste("rdr", sep = "", readerID)
return(as.data.frame(fomArray))
Expand All @@ -677,7 +677,7 @@ FOM_SP <- function(dataset, FOM = "wAFROC") { # dpc



PseudovaluesSP_A <- function(dataset, FOM) {
PseudovaluesSP_A1 <- function(dataset, FOM) {

dataType <- dataset$descriptions$type
NL <- dataset$ratings$NL
Expand Down Expand Up @@ -808,7 +808,7 @@ PseudovaluesSP_A <- function(dataset, FOM) {
jkPseudoValues[i, j1, kIndxAll] <-
fomArray[i, j1] * K_ij - jkFomValues[i, j1, kIndxAll] * (K_ij - 1)
} else stop("overwriting Pseudovalues")
} else {
} else { # (k > K1_ij)
nlij_jk <- nl_ij[-k, ];dim(nlij_jk) <- c(K_ij - 1, maxNL)
llij_jk <- ll_ij[-(k - K1_ij), ];dim(llij_jk) <- c(K2_ij - 1, maxLL)
lV_j_jk <- perCase_ij[-(k - K1_ij)]
Expand Down
Loading

0 comments on commit 4819381

Please sign in to comment.