cf4 <- read.csv("cf4.txt", sep="")
#cf4 = do.call(rbind.data.frame, cf4)
df <- data.frame(matrix(unlist(cf4), nrow=2789, byrow=TRUE))
colnames(df) = names(cf4)
head(df)
## rt.uaw rt.uax rt.uay rt.uaz rt.faw rt.fax rt.fay rt.faz rt.thw
## 1 -0.7614 -0.7614 -0.7614 -0.7614 -0.7604 -0.7604 -0.7604 -0.7604 -0.7604
## 2 -0.7565 -0.7565 -0.7565 -0.7565 -0.7565 -0.7506 -0.7506 -0.7506 -0.7506
## 3 -0.7516 -0.7458 -0.7458 -0.7458 -0.7458 -0.7458 -0.7458 -0.7401 -0.7401
## 4 -0.7647 -0.7647 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646
## 5 -0.7742 -0.7742 -0.7742 -0.7658 -0.7658 -0.7658 -0.7658 -0.7658 -0.7658
## 6 -0.7565 -0.7565 -0.7565 -0.7565 -0.7565 -0.7642 -0.7642 -0.7642 -0.7642
## rt.thx rt.thy rt.thz rt.llw rt.llx rt.lly rt.llz rt.ftw rt.ftx
## 1 -0.7604 -0.7604 -0.7604 -0.7598 -0.7598 -0.7598 -0.7598 -0.7598 -0.7598
## 2 -0.7506 -0.7506 -0.7506 -0.7506 -0.7555 -0.7555 -0.7555 -0.7555 -0.7555
## 3 -0.7401 -0.7401 -0.7401 -0.7401 -0.7401 -0.7440 -0.7440 -0.7440 -0.7440
## 4 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7601
## 5 -0.7658 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7576
## 6 -0.7642 -0.7642 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648
## rt.fty rt.ftz lt.uaw lt.uax lt.uay lt.uaz lt.faw lt.fax lt.fay
## 1 -0.7598 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7558
## 2 -0.7555 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7587
## 3 -0.7440 -0.7440 -0.7440 -0.7561 -0.7561 -0.7561 -0.7561 -0.7561 -0.7561
## 4 -0.7601 -0.7601 -0.7601 -0.7601 -0.7601 -0.7601 -0.7644 -0.7644 -0.7644
## 5 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7587 -0.7587 -0.7587
## 6 -0.7648 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7646
## lt.faz lt.thw lt.thx lt.thy lt.thz lt.llw lt.llx lt.lly lt.llz
## 1 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558
## 2 -0.7587 -0.7587 -0.7587 -0.7587 -0.7587 -0.7587 -0.7516 -0.7516 -0.7516
## 3 -0.7561 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7647
## 4 -0.7644 -0.7644 -0.7644 -0.7735 -0.7735 -0.7735 -0.7735 -0.7735 -0.7735
## 5 -0.7587 -0.7587 -0.7587 -0.7578 -0.7578 -0.7578 -0.7578 -0.7578 -0.7578
## 6 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7570 -0.7570 -0.7570 -0.7570
## lt.ftw lt.ftx lt.fty lt.ftz
## 1 -0.7558 -0.7558 -0.7558 -0.7565
## 2 -0.7516 -0.7516 -0.7516 -0.7516
## 3 -0.7647 -0.7647 -0.7647 -0.7647
## 4 -0.7735 -0.7742 -0.7742 -0.7742
## 5 -0.7578 -0.7565 -0.7565 -0.7565
## 6 -0.7570 -0.7570 -0.7570 -0.7570
# scale data
library("dplyr")
## Warning: package 'dplyr' was built under R version 4.0.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
df_scaled <- df %>% # Applying functions of dplyr
mutate_at(names(df), ~(scale(.) %>% as.vector))
#df_scaled = scale(df)
#par(mfrow=c(2, 2))
#for (j in seq(1,36,4)){
# for(i in 1:4) {
# plot(cf4[,i+j],type="l")
#lines(lowess(cf4[,i+j],f=.01), lwd=1, col=2)
# }
#}
max(df[,1])
## [1] 0.9848
head(df)
## rt.uaw rt.uax rt.uay rt.uaz rt.faw rt.fax rt.fay rt.faz rt.thw
## 1 -0.7614 -0.7614 -0.7614 -0.7614 -0.7604 -0.7604 -0.7604 -0.7604 -0.7604
## 2 -0.7565 -0.7565 -0.7565 -0.7565 -0.7565 -0.7506 -0.7506 -0.7506 -0.7506
## 3 -0.7516 -0.7458 -0.7458 -0.7458 -0.7458 -0.7458 -0.7458 -0.7401 -0.7401
## 4 -0.7647 -0.7647 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646
## 5 -0.7742 -0.7742 -0.7742 -0.7658 -0.7658 -0.7658 -0.7658 -0.7658 -0.7658
## 6 -0.7565 -0.7565 -0.7565 -0.7565 -0.7565 -0.7642 -0.7642 -0.7642 -0.7642
## rt.thx rt.thy rt.thz rt.llw rt.llx rt.lly rt.llz rt.ftw rt.ftx
## 1 -0.7604 -0.7604 -0.7604 -0.7598 -0.7598 -0.7598 -0.7598 -0.7598 -0.7598
## 2 -0.7506 -0.7506 -0.7506 -0.7506 -0.7555 -0.7555 -0.7555 -0.7555 -0.7555
## 3 -0.7401 -0.7401 -0.7401 -0.7401 -0.7401 -0.7440 -0.7440 -0.7440 -0.7440
## 4 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7590 -0.7601
## 5 -0.7658 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7609 -0.7576
## 6 -0.7642 -0.7642 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648 -0.7648
## rt.fty rt.ftz lt.uaw lt.uax lt.uay lt.uaz lt.faw lt.fax lt.fay
## 1 -0.7598 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7558
## 2 -0.7555 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7580 -0.7587
## 3 -0.7440 -0.7440 -0.7440 -0.7561 -0.7561 -0.7561 -0.7561 -0.7561 -0.7561
## 4 -0.7601 -0.7601 -0.7601 -0.7601 -0.7601 -0.7601 -0.7644 -0.7644 -0.7644
## 5 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7576 -0.7587 -0.7587 -0.7587
## 6 -0.7648 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7715 -0.7646
## lt.faz lt.thw lt.thx lt.thy lt.thz lt.llw lt.llx lt.lly lt.llz
## 1 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558 -0.7558
## 2 -0.7587 -0.7587 -0.7587 -0.7587 -0.7587 -0.7587 -0.7516 -0.7516 -0.7516
## 3 -0.7561 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7627 -0.7647
## 4 -0.7644 -0.7644 -0.7644 -0.7735 -0.7735 -0.7735 -0.7735 -0.7735 -0.7735
## 5 -0.7587 -0.7587 -0.7587 -0.7578 -0.7578 -0.7578 -0.7578 -0.7578 -0.7578
## 6 -0.7646 -0.7646 -0.7646 -0.7646 -0.7646 -0.7570 -0.7570 -0.7570 -0.7570
## lt.ftw lt.ftx lt.fty lt.ftz
## 1 -0.7558 -0.7558 -0.7558 -0.7565
## 2 -0.7516 -0.7516 -0.7516 -0.7516
## 3 -0.7647 -0.7647 -0.7647 -0.7647
## 4 -0.7735 -0.7742 -0.7742 -0.7742
## 5 -0.7578 -0.7565 -0.7565 -0.7565
## 6 -0.7570 -0.7570 -0.7570 -0.7570
## Warning: package 'psych' was built under R version 4.0.5
## Warning: package 'astsa' was built under R version 4.0.5
##
## Attaching package: 'astsa'
## The following object is masked from 'package:psych':
##
## scatter.hist
## Warning: package 'factoextra' was built under R version 4.0.5
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.0.3
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
## Warning: ggrepel: 2786 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## Warning: ggrepel: 2786 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## Warning: ggrepel: 2781 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## Warning: ggrepel: 2779 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## Warning: ggrepel: 29 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
A plain version
another version
more customized version
A better version
largest correlation
# function for plot top correlations
top_cor <- function(df, n){
n = 2*n
# compute the correlation matrix and minus diagonal
m = cor(df,method = "spearman") - diag(dim(df)[2])
# find the top correlations
ij_pos <- which(m >= sort(m, decreasing=T)[n], arr.ind=TRUE)
#sort(m[ij_pos])
ij_neg <- which(-m >= sort(-m, decreasing=T)[n], arr.ind=TRUE)
#sort(m[ij_neg])
# create a zero matrix
test = matrix(0,nrow = dim(df)[2], ncol = dim(df)[2])
# pass index to zero matrix
for (i in 1:n) {
test[ij_pos[i,1],ij_pos[i,2]]=m[ij_pos[i,1],ij_pos[i,2]]
test[ij_neg[i,1],ij_neg[i,2]]=m[ij_neg[i,1],ij_neg[i,2]]
}
# return results
#return(test1)
# plot
rownames(test) = names(df)
colnames(test) = names(df)
corrplot::corrplot(test)
#return(test)
}
## [1] 0.6339022 0.6339022 0.6842742 0.6842742 0.6870818 0.6870818 0.6955016
## [8] 0.6955016 0.7512215 0.7512215
## [1] -0.5927696 -0.5927696 -0.5123219 -0.5123219 -0.4969329 -0.4969329
## [7] -0.4735347 -0.4735347 -0.4240953 -0.4240953
## [1] 0.4131197 0.4131197 0.4432934 0.4432934 0.4680090 0.4680090 0.5917081
## [8] 0.5917081 0.6848475 0.6848475
## [1] -0.5116982 -0.5116982 -0.4599920 -0.4599920 -0.4142687 -0.4142687
## [7] -0.3872607 -0.3872607 -0.3631521 -0.3631521
## [1] 0.5303046 0.5303046 0.6271936 0.6271936 0.6531508 0.6531508 0.6855158
## [8] 0.6855158 0.7278851 0.7278851
## [1] -0.7197638 -0.7197638 -0.6555251 -0.6555251 -0.5870003 -0.5870003
## [7] -0.5031092 -0.5031092 -0.4891882 -0.4891882
## [1] 0.6984086 0.6984086 0.7002466 0.7002466 0.7258311 0.7258311 0.7692318
## [8] 0.7692318 0.7769656 0.7769656
## [1] -0.7332564 -0.7332564 -0.7184782 -0.7184782 -0.6900608 -0.6900608
## [7] -0.6380025 -0.6380025 -0.6034289 -0.6034289