Skip to content

Commit

Permalink
Modify reciprocal.coa to deal with matrices as arguments (not only da…
Browse files Browse the repository at this point in the history
…ta.frame)

Use colnames/rownames to deal with matrices and clean the code
  • Loading branch information
sdray committed Oct 7, 2024
1 parent 8e09264 commit af1eeb3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions R/score.coa.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,23 @@
oritab <- eval.parent(as.list(y$call)[[2]])
}
else oritab <- eval.parent(as.list(x$call)[[2]])
l.names <- row.names(oritab)
c.names <- names(oritab)
l.names <- rownames(oritab)
c.names <- colnames(oritab)
oritab <- as.matrix(oritab)
f1 <- function(x,oritab,xax){
f1 <- function(x, oritab, xax){
a <- x$co[col(oritab), xax]
a <- a + x$li[row(oritab), xax]
a <- a/sqrt(2 * x$eig[xax] * (1 + sqrt(x$eig[xax])))
a <- a[oritab > 0]
}
res <- sapply(1:x$nf,f1,x=x,oritab=oritab)
res <- sapply(1:x$nf, f1, x = x, oritab = oritab)
aco <- col(oritab)[oritab > 0]
aco <- factor(aco)
levels(aco) <- c.names
aco <- factor(aco, labels = c.names)
ali <- row(oritab)[oritab > 0]
ali <- factor(ali)
levels(ali) <- l.names
ali <- factor(ali, labels = l.names)
aw <- oritab[oritab > 0]/sum(oritab)
res <- cbind.data.frame(res,Row=ali,Col=aco,Weight=aw)
names(res)[1:x$nf] <- paste("Scor",1:x$nf,sep="")
rownames(res) <- paste(ali,aco,sep="")
res <- cbind.data.frame(res, Row = ali, Col = aco, Weight = aw)
names(res)[1:x$nf] <- paste("Scor", 1:x$nf, sep = "")
# rownames(res) <- paste(ali, aco, sep = "")
return(res)
}

0 comments on commit af1eeb3

Please sign in to comment.