##input correlation matrix
matrix = matrix(
c(
1, .57, .25, .33, .29, .19, .47, .44, .30,
.57, 1, .64, .23, .37, .20, .37, .58, .40,
.25, .64, 1, .15, .25, .27, .28, .43, .52,
.33, .23, .15, 1, .38, .26, .22, .21, .12,
.29, .37, .25, .38, 1, .38, .23, .37, .20,
.19, .20, .27, .26, .38, 1, .13, .20, .31,
.47, .37, .28, .22, .23, .13, 1, .59, .40,
.44, .58, .43, .21, .37, .20, .59, 1, .60,
.30, .40, .52, .12, .20, .31, 40, .60, 1
),
nrow=9,
ncol=9,
byrow=TRUE)
##assign names
dimnames(matrix)= list(
c("var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8", "var9"), c("var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8", "var9"))
##input SD
SD <- c(.74, .80, .76, .63, .68, .67, .91, 1.11, 1.17)
#convert to covariance matrix
matrix_cov <- cor2cov(matrix,SD)
I need to use a correlation matrix since I do not have sd's.
I want to read in my LOWER correlation matrix I always get an error message.
(M <- as.matrix(read.csv("Desktop/ex5.csv", header = FALSE)))
dimnames(M) <- list(c("a", "b", "c", "d"), c("a", "b", "c", "d"))
(tM <- t(M)) # save the transpose
upper.tri(M) # this is how you flag upper/lower triangles
M[upper.tri(M)] <- tM[upper.tri(tM)]
M
isSymmetric(M) # TRUE> library("lavaan", lib.loc="~/R/win-library/3.6")
> Bagcorstr<-' 1.000
0.418 1.000
0.394 0.627 1.000
0.129 0.202 0.266 1.000
0.189 0.284 0.208 0.365 1.000
0.544 0.281 0.324 0.201 0.161 1.000
0.507 0.225 0.314 0.172 0.174 0.546 1.000
-0.357 -0.156 -0.038 -0.199 -0.277 -0.294 -0.174 1.000'
> Bagnames<-c("Perform1", "JobSat1",
"JobSat2", "AchMot1", "AchMot2",
"SelfEst1", "SelfEst2", "VerbInt1")
> # Use default spec, first indicator loading fixed to 1
> Bagcor<-getCov(Bagcorstr,names=Bagnames)
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/cb4a4b6b-b804-4990-863c-aecfae2865fb%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lav...@googlegroups.com.