I am running a Mulitlevel Confirmatory Factorial Analysis in R based on the paper of Francis Huang. Iam working with the syntax from the article and the example data set used in the article.
Here is the Article: Huang, F. L. (2017). Conducting multilevel confirmatory factor analysis using R. Unpublished Manuscript). http://faculty. missouri. edu/huangf/data/mcfa/MCFA% 20in% 20R% 20HUANG. pdf .
Watch out! The webadress for downloading the data and the R function is obsolete in the paper. In the syntax below the webadresses are correct.
# load lavaan package Library(lavaan) # That’s an r function source('http://web.missouri.edu/huangf/data/mcfa/mcfa.R') #dataset containing only the grouping variable and the variables of interest. raw <- read.csv("http://web.missouri.edu/huangf/data/mcfa/raw.csv") #the function is applied to the dataset specifying that sid (school id) is the clustering #variable x <- mcfa.input("sid", raw) ############## STEP 1 # one factor model and two factor model with results onefactor <- 'f1 =~ x1 + x2 + x3 + x4 + x5 + x6' twofactor <- 'f1 =~ x1 + x2 + x4; f2= ~x3 + x5 + x6' results1 <- cfa(onefactor, sample.cov = x$pw.cov, sample.nobs = x$n - x$G) summary(results1, fit.measures = T, standardized = T) results2 <- cfa(twofactor, sample.cov = x$pw.cov, sample.nobs = x$n - x$G) summary(results2, fit.measures = T, standardized = T) ############# STEP 2 # A null model is specified where both the SPW and SB matrices are used in a # multigroup setup using the factor structure defined at step 1 on both matrices with # all equality constraints set to be equal. We do not really have two groups but # the multigroup setup will be used to analyze both the `within group' and the #`between group' matrices simultaneously. In lavaan, multiple input covariance #matrices and the sample sizes for each are stored in a list object: combined.cov <- list(within = x$pw.cov, between = x$b.cov) combined.n <- list(within = x$n - x$G, between = x$G) #The first object in the list refers to group one and the second object refers to group #two and we create two new objects (i.e., combined.cov and combined.n) that #contain the two covariance matrices (i.e., SPW and SB) and the sample size for each #(n - G and G, respectively). # A model imposing the equality constraints must be specified. In this step, the #model specification expands quite a bit. In lavaan, the equality constrains are imposed #for the particular variable by indicating c(a,a)*variable where c() is the concatenate #function, a is a label assigned by the user to indicate that loading a for group one is set to #be equal for loading a in group two. The same label names instruct lavaan to use the #same estimates between groups or in other words, specify equality constraints. To #specify equal factor loadings for both factors for the within and between models, #we indicate: f1 =~ x1 + c(a,a)*x2 + c(b,b)*x4; f2 =~ x3 + c(c,c)*x5 + c(d,d)*x6. The loadings #for x1 and x3 are auto matically set to 1 so do not need to be specified. nullmodel <- ' + f1 =~ x1 + c(a,a)*x2 + c(b,b)*x4 + f2 =~ x3 + c(c,c)*x5 + c(d,d)*x6 + x1 ~~ c(e,e)*x1 + x2 ~~ c(f,f)*x2 + x3 ~~ c(g,g)*x3 + x4 ~~ c(h,h)*x4 + x5 ~~ c(i,i)*x5 + x6 ~~ c(j,j)*x6 + f1 ~~ c(k,k)*f1 + f2 ~~ c(l,l)*f2 + f1 ~~ c(m,m)*f2 + ' results3 <- cfa(nullmodel, sample.cov = combined.cov, + sample.nobs = combined.n) #Thats the error message Error: Unexpected '=' in: "results3 <- cfa(nullmodel, sample.cov = combined.cov, + sample.nobs ="
With my data I am received the same error message.
Any ideas? Help is appreciated.
Best regards Konstantin