我正在尝试使用R创建一个Multitrait-Multimethod Matrix用于有效目的(我也将使用CFA,因此这不是这个问题的答案)。如何使用R创建类似于此的MTMM:
我查看了psy包中的MTMM
函数。如果这是我想要的,它似乎是一种非常陌生的形式(完全不像上面的图像)。我提供了一些虚假数据来帮助:
set.seed(100)
x <- data.frame(matrix(sample(1:5, 270, replace=T), 10, 27))
names(x) <- paste(rep(c("A", "B", "C"), each=9), rep(c(1:9), 3), sep="")
x
对列名称进行编码:
我猜这比我做的更容易,但我找不到办法。提前感谢您的帮助。
答案 0 :(得分:0)
这是尝试使用talkstats.com的朋友建议在R中制作MTMM。我不知道它是否正确,因为我没有测试(基准)数据集来使用已知的正确MTMM。请批评。这是一个MTMM还是只是一个在对角线上具有可靠性的随机矩阵?
请记住,dim是方法,r是列名和行名的构造。
require(CTT); require(foreign)
dat22 <-read.csv(url("http://dl.dropbox.com/u/61803503/dat.csv"), header=TRUE,
strip.white = TRUE, sep=",", as.is=FALSE, na.strings= c("999", "NA", " "))
#group items by method(dim) and construct(r)
dim1r1 <- dat2[, c(3, 5, 9, 10)]
dim2r1 <- dat2[, c(4, 13:15)]
dim3r1 <- dat2[, c(1, 6, 7, 11, 12)]
dim4r1 <- dat2[, c(2, 8, 16, 17)]
dim1r2 <- dat2[, c(3, 5, 9, 10)+17]
dim2r2 <- dat2[, c(4, 13:15)+17]
dim3r2 <- dat2[, c(1, 6, 7, 11, 12)+17]
dim4r2 <- dat2[, c(2, 8, 16, 17)+17]
dim1r3 <- dat2[, c(3, 5, 9, 10)+17*2]
dim2r3 <- dat2[, c(4, 13:15)+17*2]
dim3r3 <- dat2[, c(1, 6, 7, 11, 12)+17*2]
dim4r3 <- dat2[, c(2, 8, 16, 17)+17*2]
dim1r4 <- dat2[, c(3, 5, 9, 10)+17*3]
dim2r4 <- dat2[, c(4, 13:15)+17*3]
dim3r4 <- dat2[, c(1, 6, 7, 11, 12)+17*3]
dim4r4 <- dat2[, c(2, 8, 16, 17)+17*3]
#make a list from the above items
#dim1r1 means methid 1 (dim1) and construct 1(r1)
LIST2 <- list(dim1r1, dim1r2, dim1r3, dim1r4, dim2r1, dim2r2, dim2r3, dim2r4,
dim3r1, dim3r2, dim3r3, dim3r4, dim4r1, dim4r2, dim4r3, dim4r4)
#get the sums of the items by method and construct
#and generate correlation amtrix (all in 1 step)
mtmm <- round(cor(sapply(LIST2, function(x) rowSums(x))), digits=3)
#generate and order row and column names
VN <- expand.grid(paste('dim', 1:4, sep=""), paste('r', 1:4, sep=""))
VN <- VN[order(VN$Var1, VN$Var2), ]
varNames <- paste(VN[, 1], VN[, 2], sep="")
rownames(mtmm) <- colnames(mtmm) <-varNames
#blank out the upper triangle
mtmm[upper.tri(mtmm)] <- " "
#add cronbach's alpha intot he diagonal
diag(mtmm) <- sapply(LIST2, function(x) round(reliability(x)$alpha, digits=3))
noquote(mtmm)
产生:
dim1r1 dim1r2 dim1r3 dim1r4 dim2r1 dim2r2 dim2r3 dim2r4 dim3r1 dim3r2 dim3r3 dim3r4 dim4r1 dim4r2 dim4r3 dim4r4
dim1r1 0.737
dim1r2 0.82 0.78
dim1r3 0.825 0.755 0.735
dim1r4 0.828 0.783 0.812 0.791
dim2r1 0.415 0.496 0.484 0.495 0.801
dim2r2 0.432 0.615 0.493 0.479 0.818 0.886
dim2r3 0.425 0.473 0.505 0.459 0.89 0.831 0.843
dim2r4 0.355 0.468 0.413 0.482 0.806 0.826 0.837 0.802
dim3r1 0.544 0.518 0.413 0.494 0.281 0.226 0.184 0.233 0.778
dim3r2 0.517 0.585 0.399 0.461 0.306 0.324 0.26 0.293 0.88 0.782
dim3r3 0.491 0.489 0.392 0.421 0.258 0.229 0.232 0.221 0.875 0.912 0.804
dim3r4 0.487 0.492 0.366 0.475 0.269 0.268 0.209 0.274 0.887 0.89 0.859 0.77
dim4r1 0.341 0.399 0.38 0.357 0.387 0.398 0.355 0.375 0.397 0.417 0.387 0.43 0.489
dim4r2 0.274 0.433 0.326 0.323 0.462 0.535 0.416 0.46 0.343 0.422 0.349 0.432 0.863 0.517
dim4r3 0.268 0.368 0.364 0.306 0.329 0.417 0.333 0.341 0.293 0.376 0.34 0.353 0.863 0.856 0.545
dim4r4 0.301 0.403 0.347 0.395 0.377 0.443 0.371 0.483 0.372 0.441 0.345 0.441 0.86 0.84 0.83 0.52
可以使用ggplot或Excel等外部程序进行清理和制作。