2012-03-09 44 views
4

我試圖創建Multitrait-Multimethod Matrix使用R爲有效性目的(我也將使用CFA,所以這不是對這個問題的答案)。我怎樣才能用R創建一個類似於此的MTMM:創建一個Multitrait-Multimethod矩陣

enter image description here

我看着在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 

編碼列名稱:

  • A,B,C是3種方法
  • 1-3是性狀1
  • 特性2是4-6特性
  • 7-9是特性3

我猜這是比我更容易做到的,但我找不到方法。預先感謝您的幫助。

+0

一個外部程序的一般邏輯可能是使用的方法作爲板進行清洗,並加以,特徵作爲分類軸,然後根據相關係數對相關矩陣中的單元格進行着色(例如,請參閱統計站點上的[本答案](http://stats.stackexchange.com/q/9918/1036)) )。如果您真的重現了您的相關矩陣,那將會更容易。對於上帝的愛,請不要在包含的圖片中使用該顏色方案! – 2012-03-09 12:52:40

+0

安迪提請我注意上面的圖片是誤導性的。我真的不想輸出成漂亮的圖形,只是從數字上說輸出是正確的。它可能是醜陋的(現在實際上是首選)。 – 2012-03-11 18:00:25

回答

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等

+0

我不認爲這是MTMM的內容,請參閱David Kenny關於此主題的網頁http://davidakenny.net/cm/mtmm.htm。 – 2012-03-11 18:15:04