psych::alpha(dimE,keys=(1:9)[(keyE==-1)]) library(psych) qtype <- c("E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "O","A","C","O") valence <- c(1,-1,1,1,1, -1,1,-1,-1,1, 1,-1,1,1,1, 1,1,-1,1,1, -1,1,-1,-1,1, 1,1,-1,-1,-1, 1,-1,1,-1,-1, 1,1,-1,-1,-1, 1,-1,1,-1) ##let's use select with the column numbers: dat.raw <- read.csv("bigfive-full.csv")[,4:47] #dat.raw[is.na(dat.raw)] <- 3 dat.raw[1:5,] dat2 <- dat.raw library(dplyr) dimE <- dplyr::select(dat2,(1:44)[qtype=="E"]) dimA <- dplyr::select(dat2,(1:44)[qtype=="A"]) dimC <- dplyr::select(dat2,(1:44)[qtype=="C"]) dimN <- dplyr::select(dat2,(1:44)[qtype=="N"]) dimO <- dplyr::select(dat2,(1:44)[qtype=="O"]) keyE <- valence[qtype=="E"] keyA <- valence[qtype=="A"] keyC <- valence[qtype=="C"] keyN <- valence[qtype=="N"] keyO <- valence[qtype=="O"] psych::alpha(dimE,keys=(1:9)[(keyE==-1)]) dimE psych::alpha(dimE,keys=(1:8)[(keyE==-1)]) keyE ?alpha psych::alpha(dimE)# keys=(1:8)[(keyE==-1) ] keys keyE dimE psych::alpha(dimE,keys=keyE) psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) glb(dimE,key=keyE) psych::alpha(dimE,keys=keyE) glb(dimE,key=keyE) # This no longer works: #psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) psych::alpha(dimA,keys=keyA) glb(dimA,key=keyA) psych::alpha(dimN,keys=keyN) glb(dimN,key=keyN) psych::alpha(dimO,keys=keyO) glb(dimO,key=keyO) psych::alpha(dimE,keys=keyE,title="Extraversion") glb(dimE,key=keyE) # This no longer works: #psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) psych::alpha(dimA,keys=keyA) glb(dimA,key=keyA) psych::alpha(dimN,keys=keyN) glb(dimN,key=keyN) psych::alpha(dimO,keys=keyO) glb(dimO,key=keyO) psych::alpha(dimE,keys=keyE,title="Extraversion") glb(dimE,key=keyE) # This no longer works: #psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) psych::alpha(dimA,keys=keyA,title="Agreeableness") glb(dimA,key=keyA) psych::alpha(dimN,keys=keyN,title="Neuroticism") glb(dimN,key=keyN) psych::alpha(dimO,keys=keyO,title="Openness to experience") glb(dimO,key=keyO) psych::alpha(dimC) ##with keys specified a priori psych::alpha(dimC,keys=keyC) psych::alpha(dimC,keys=c("Q8","Q18","Q23","Q43")) library(ggplot2) ##without keys psych::alpha(dimC) ##with keys specified a priori psych::alpha(dimC,keys=keyC) psych::alpha(dimC,keys=c("Q8","Q18","Q23","Q43")) ## with keys discovered using first PCA dimension. psych::alpha(dimC, check.keys=T) glb(dimC,key=keyC) cc <- cor(dimC,use="pairwise.complete") e <- eigen(cc) tmp <- data.frame(i=1:9,eigenvalue=e$values) ggplot(tmp,aes(x=i,y=eigenvalue))+geom_line()+geom_point(aes(x=i,y=eigenvalue)) + geom_hline( yintercept=1) + ylim(0,4) + scale_x_continuous(breaks=1:9) tmp <- data.frame(i=1:9,vector=e$vectors[,1]) ggplot(tmp,aes(x=i,y=vector))+geom_bar(stat="identity") keyC <- c(1,-1,1,-1,-1,1,1,1,-1) psych::alpha(dimC,keys=(1:9)[keyC==-1]) keyC <- c(1,-1,1,-1,-1,1,1,1,-1) psych::alpha(dimC,keys=keyC) glb(dimC,key=keyC) colMeans(dimC,na.rm=T) colSums(is.na(dimC)) cc round(abs(cc)>.35,2) heatmap(cc) heatmap(cc) round(abs(cc)>.35,2) small <- dplyr::select(dimC,Q8,Q18,Q23,Q33,Q43) psych::alpha(small) psych::alpha(small,check.keys=T) psych::alpha(small,keys=keyC[c(2,4,5,7,9)]) round(cc,3) heatmap(cc) round(abs(cc)>.35,2) round(cc,3) heatmap(cc^2) round(abs(cc)>.35,2) heatmap(abs(cc)) cor(dplyr::select(dimC,Q43,Q8,Q23,Q18), dplyr::select(dimC,Q28,Q38,Q33,Q3,Q13)) cor(dplyr::select(dimC,Q43,Q8,Q23,Q18), dplyr::select(dimC,Q28,Q38,Q33,Q3,Q13),use="pairwise.complete") small <- dplyr::select(dimC,Q8,Q18,Q23,Q33,Q43) psych::alpha(small) psych::alpha(small,check.keys=T) psych::alpha(small,keys=keyC[c(2,4,5,7,9)]) print(tmp0) print(tmp) dimC tmp$names <- colnames(dimC) print(tmp) tr <- read.csv("TaskRatings.csv") data <- tr #r1 to r2 cat("1 versus 2:\n") round(diag(cor(data[,3:10],data[,11:18])),3) mean(round(diag(cor(data[,3:10],data[,11:18])),3)) #r1 to r3 cat("1 versus 3:\n") round(diag(cor(data[,3:10],data[,19:26])),3) mean(round(diag(cor(data[,3:10],data[,19:26])),3)) #r2 to r3 cat("2 versus 3:\n") round(diag(cor(data[,11:18],data[,19:26])),3) mean(round(diag(cor(data[,11:18],data[,19:26])),3)) tr library(GGally) data <- tr i <- 2;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 3;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 4;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 5;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 6;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 7;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 8;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 9;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) library(ICC) data <- tr for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n------------------------\n") print( round(cor(data[,c(i+1,i+9,i+17)]),3)) ggpairs(data[,c(i+1,i+9,i+17)]) merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(task,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } frame.1 task irr:icc(merged) library(irr) icc(merged) icc(t(merged)) merged frame.1[1:5,] library(ICC) data <- tr for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n------------------------\n") print( round(cor(data[,c(i+1,i+9,i+17)]),3)) ggpairs(data[,c(i+1,i+9,i+17)]) merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(task,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } frame.1[1:5,] for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } ?ICCest for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } subject library(ICC) data <- tr for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n------------------------\n") print( round(cor(data[,c(i+1,i+9,i+17)]),3)) ggpairs(data[,c(i+1,i+9,i+17)]) merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(subject,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } frame.1 for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(task,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(task,merged,data=frame.1)) } library(psych) cohen.kappa(data[,c(3,11)]) for(i in 3:10) { cat("===========================================\n") cat("Kappa for",names(data)[i],"\n") print(cohen.kappa(data[,c(i,i+8)])) } cc1 <- cor(t(tr[,3:26])) e <- eigen(cc1) cc1 <- cor(t(tr[,3:26])) e <- eigen(cc1) plot(e$values) tr$Task[order(-e1$vectors[,1])][1:10] tr$Task[order(e1$vectors[,1])][1:10] tr$Task[order(-e1$vectors[,1])][1:10] tr$Task[order(e1$vectors[,1])][1:10] tr$Task[order(-e1$vectors[,2])][1:10] tr$Task[order(e1$vectors[,2])][1:10] tr$Task[order(-e1$vectors[,3])][1:10] tr$Task[order(e1$vectors[,3])][1:10] plot(e$vectors[,1],e$vectors[,2]) text(e$vectors[,1],e$vectors[,2],tr$Task) plot(e$vectors[,1],e$vectors[,2]) text(e$vectors[,1],e$vectors[,2],tr$Task) cc2 <- cor(tr[,3:26]) e2 <- eigen(cc2) cc2 <- cor(tr[,3:26]) e2 <- eigen(cc2) plot(e2$values) tr[1:5,] rownames(tr) colnames(tr) colnames(tr)[3:26] plot(e2$vectors[,1],e2$vectors[,2]) text(e2$vectors[,1],e2$vectors[,2], colnames(tr)[3:26]) data(ChickWeight) ICCest(Chick, weight, data = ChickWeight, CI.type = "S") library(psych) qtype <- c("E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "E","A","C","N","O", "O","A","C","O") valence <- c(1,-1,1,1,1, -1,1,-1,-1,1, 1,-1,1,1,1, 1,1,-1,1,1, -1,1,-1,-1,1, 1,1,-1,-1,-1, 1,-1,1,-1,-1, 1,1,-1,-1,-1, 1,-1,1,-1) ##let's use select with the column numbers: dat.raw <- read.csv("bigfive-full.csv")[,4:47] #dat.raw[is.na(dat.raw)] <- 3 dat.raw[1:5,] dat2 <- dat.raw library(dplyr) dimE <- dplyr::select(dat2,(1:44)[qtype=="E"]) dimA <- dplyr::select(dat2,(1:44)[qtype=="A"]) dimC <- dplyr::select(dat2,(1:44)[qtype=="C"]) dimN <- dplyr::select(dat2,(1:44)[qtype=="N"]) dimO <- dplyr::select(dat2,(1:44)[qtype=="O"]) keyE <- valence[qtype=="E"] keyA <- valence[qtype=="A"] keyC <- valence[qtype=="C"] keyN <- valence[qtype=="N"] keyO <- valence[qtype=="O"] psych::alpha(dimE,keys=keyE,title="Extraversion") glb(dimE,key=keyE) # This does not work: #psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) psych::alpha(dimA,keys=keyA,title="Agreeableness") glb(dimA,key=keyA) psych::alpha(dimN,keys=keyN,title="Neuroticism") glb(dimN,key=keyN) psych::alpha(dimO,keys=keyO,title="Openness to experience") glb(dimO,key=keyO) psych::alpha(dimE,keys=keyE,title="Extraversion") glb(dimE,key=keyE) # This does not work: #psych::alpha(dimA,keys=(1:9)[(keyA==-1)]) psych::alpha(dimA,keys=keyA,title="Agreeableness") glb(dimA,key=keyA) psych::alpha(dimN,keys=keyN,title="Neuroticism") glb(dimN,key=keyN) psych::alpha(dimO,keys=keyO,title="Openness to experience") glb(dimO,key=keyO) psych::alpha(dimA,keys=keyA,title="Agreeableness") glb(dimA,key=keyA) library(ggplot2) ##without keys psych::alpha(dimC) ##with keys specified a priori psych::alpha(dimC,keys=keyC) psych::alpha(dimC,keys=c("Q8","Q18","Q23","Q43")) ## with keys discovered using first PCA dimension. psych::alpha(dimC, check.keys=T) glb(dimC,key=keyC) cc <- cor(dimC,use="pairwise.complete") e <- eigen(cc) tmp <- data.frame(i=1:9,eigenvalue=e$values) ggplot(tmp,aes(x=i,y=eigenvalue))+geom_line()+geom_point(aes(x=i,y=eigenvalue)) + geom_hline( yintercept=1) + ylim(0,4) + scale_x_continuous(breaks=1:9) tmp <- data.frame(i=1:9,vector=e$vectors[,1]) tmp$names <- colnames(dimC) print(tmp) ggplot(tmp,aes(x=i,y=vector))+geom_bar(stat="identity") psych::alpha(dimC) psych::alpha(dimC, check.keys=T) psych::alpha(dimC,keys=c("Q8","Q18","Q23","Q43")) glb(dimC,key=keyC) cc <- cor(dimC,use="pairwise.complete") e <- eigen(cc) tmp <- data.frame(i=1:9,eigenvalue=e$values) ggplot(tmp,aes(x=i,y=eigenvalue))+geom_line()+geom_point(aes(x=i,y=eigenvalue)) + geom_hline( yintercept=1) + ylim(0,4) + scale_x_continuous(breaks=1:9) tmp <- data.frame(i=1:9,vector=e$vectors[,1]) tmp$names <- colnames(dimC) print(tmp) ggplot(tmp,aes(x=i,y=vector))+geom_bar(stat="identity") keyC <- c(1,-1,1,-1,-1,1,1,1,-1) psych::alpha(dimC,keys=keyC) glb(dimC,key=keyC) colMeans(dimC,na.rm=T) colSums(is.na(dimC)) psych::alpha(dimC,keys=c("Q8","Q18","Q23","Q43")) round(cc,3) heatmap(abs(cc)) round(abs(cc)>.35,2) small <- dplyr::select(dimC,Q8,Q18,Q23,Q33,Q43) psych::alpha(small) psych::alpha(small,check.keys=T) psych::alpha(small,keys=keyC[c(2,4,5,7,9)]) small cor(small) v.small <- eigen(cor(small,use="pairwise.complete"))$vectors[,1] v.small v.small <- eigen(cor(t(small),use="pairwise.complete"))$vectors tr <- read.csv("TaskRatings.csv") data <- tr #r1 to r2 cat("1 versus 2:\n") round(diag(cor(data[,3:10],data[,11:18])),3) mean(round(diag(cor(data[,3:10],data[,11:18])),3)) #r1 to r3 cat("1 versus 3:\n") round(diag(cor(data[,3:10],data[,19:26])),3) mean(round(diag(cor(data[,3:10],data[,19:26])),3)) #r2 to r3 cat("2 versus 3:\n") round(diag(cor(data[,11:18],data[,19:26])),3) mean(round(diag(cor(data[,11:18],data[,19:26])),3)) tr[,3:11] library(GGally) data <- tr i <- 2;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 3;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 4;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 5;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 6;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 7;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 8;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) i <- 9;tmp <- as.data.frame(data[,c(i+1,i+9,i+17)]) + (runif(3*nrow(data))-.5)*.2 ggpairs(tmp) library(ICC) data <- tr for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n------------------------\n") print( round(cor(data[,c(i+1,i+9,i+17)]),3)) ggpairs(data[,c(i+1,i+9,i+17)]) merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(subject,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+9],data[,i+17]) subject <- as.factor(rep(2:3,each=nrow(data))) frame.1 <- data.frame(merged,subject) print(ICCest(subject,merged,data=frame.1)) } for(i in 2:8) { cat("-------------------------\n",colnames(data)[i+1],"\n") merged <- c(data[,i+1],data[,i+9],data[,i+17]) subject <- as.factor(rep(1:3,each=nrow(data))) task <- as.factor(rep(1:nrow(data),3)) frame.1 <- data.frame(merged,subject,task) print(ICCest(task,merged,data=frame.1)) } library(psych) cohen.kappa(data[,c(3,11)]) for(i in 3:10) { cat("===========================================\n") cat("Kappa for",names(data)[i],"\n") print(cohen.kappa(data[,c(i,i+8)])) } cc1 <- cor(t(tr[,3:26])) e <- eigen(cc1) plot(e$values) tr$Task[order(-e1$vectors[,1])][1:10] tr$Task[order(e1$vectors[,1])][1:10] tr$Task[order(-e1$vectors[,2])][1:10] tr$Task[order(e1$vectors[,2])][1:10] tr$Task[order(-e1$vectors[,3])][1:10] tr$Task[order(e1$vectors[,3])][1:10] e1$vectors[,1] plot(e1$vectors[,1]) tr$Task[28] tr$Task[order(-e1$vectors[,1])][1:10] tr$Task[order(e1$vectors[,1])][1:10] plot(e1$vectors[,2]) tr$Task[order(-e1$vectors[,2])][1:10] tr$Task[order(e1$vectors[,2])][1:10] tr$Task[order(-e1$vectors[,3])][1:10] tr$Task[order(e1$vectors[,3])][1:10] plot(e$vectors[,1],e$vectors[,2]) text(e$vectors[,1],e$vectors[,2],tr$Task) plot(e2$vectors[,1],e2$vectors[,2]) text(e2$vectors[,1],e2$vectors[,2], colnames(tr)[3:26]) cc2 <- cor(tr[,3:26]) e2 <- eigen(cc2) plot(e2$values) plot(e2$vectors[,1],e2$vectors[,2]) text(e2$vectors[,1],e2$vectors[,2], colnames(tr)[3:26]) plot(e2$vectors[,1],e2$vectors[,2],cex=.1) text(e2$vectors[,1],e2$vectors[,2], colnames(tr)[3:26]) plot(e2$vectors[,1],e2$vectors[,2],cex=.1) text(e2$vectors[,1],e2$vectors[,2], colnames(tr)[3:26])