Create Multitrait-Multimethod Matrix

I am trying to create a Multitrait-Multimethod Matrix using R for reality purposes (I will also use CFA to not answer this question). How can I use R to create MTMM similar to this:

enter image description here

I looked at the MTMM function in the psy package. If this is what I want, it seems in a very unfamiliar form (not at all like the image above). I have provided some fake data to help:

 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 

Column Name Encoding:

  • A, B, C - 3 methods
  • 1-3 is sign 1
  • 4-6 is sign 2
  • 7-9 is sign 3

I guess this is easier than I do, but I just couldn't find a way. Thank you in advance for your help.

+4
source share
1 answer

This is an attempt to make MTMM in R using friends advice at talkstats.com. I do not know if this is correct, because I do not have a test (control) data set to use it with the known correct MTMM. Please criticize. Is it MTMM or just a random matrix with reliability in diagonals?

Just remember that dim is a method, and r is a construct in column and row names.

 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 alpha intot he diagonal diag(mtmm) <- sapply(LIST2, function(x) round(reliability(x)$alpha, digits=3)) noquote(mtmm) 

It produces:

  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 

which could be cleaned up and done pretty well with ggplot or an external program like excel etc.

0
source

Source: https://habr.com/ru/post/1400511/


All Articles