Skip to content

Commit

Permalink
get Hmisc::rcorr results properly
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Nov 30, 2023
1 parent 7360be2 commit 5ddf460
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ server <- function(input, output, session) {
data2 <- readData(file2)
}

numData1Cols <- length(data1)
numData2Cols <- length(data2)

corrData <- Hmisc::rcorr(as.matrix(data1), as.matrix(data2))
pValuesMatrix$p_values <- corrData$P[1:numData1Cols, 1:numData2Cols]
correlationMatrix$corr_matrix <- corrData$r[1:numData1Cols, 1:numData2Cols]
lastData1ColIndex <- length(data1)
firstData2ColIndex <- length(data1) + 1
corrResult <- Hmisc::rcorr(as.matrix(data1), as.matrix(data2))
print(corrResult)
# this bc Hmisc::rcorr cbinds the two data.tables and runs the correlation
# so we need to extract only the relevant values
pValuesMatrix$p_values <- corrResult$P[1:lastData1ColIndex, firstData2ColIndex:length(colnames(corrResult$P))]
print(pValuesMatrix$p_values)
correlationMatrix$corr_matrix <- corrResult$r[1:lastData1ColIndex, firstData2ColIndex:length(colnames(corrResult$r))]
print(correlationMatrix$corr_matrix)
}, error = function(e) {
shiny::showNotification(paste('Error:', e$message), type = 'error')
})
Expand Down

0 comments on commit 5ddf460

Please sign in to comment.