I am trying to run a Confirmatory Factor Analysis (part of the SEM package) in R but part of the syntax consists of using (<->) double-sided arrows. However, when I write "<->" in R, the program does not run and I get this: "Error: unexpected '>' in "amsex1<->" Thanks for your help!
library(SEM)
data<-read.csv("C:/Users/cgonzal6/Desktop/CYRUS/pilot-2-measurement13.csv")
factor<-data.frame(cbind(amsex1,amsex2))
cov.matrix<-cov(na.omit(factor))
cfa.model<-specifyModel()
EXTERNAL->amsex1,external0
Introjected -> amsex2, introjected0
amsex1<-> amsex1, error1
amsex2<-> amsex2, error2
The specifyModel()
function reads the user input from the command line. It must be running in interactive mode to work. The <->
is not R syntax and should not be run as R code; that's just how specifyModel()
wants' the model to be described in a text format. You can interpret everything after the specifyModel()
to the next blank line as a big long character variable.
I assume you're trying to source()
this script or run it from the command line? In a non-interactive mode, you can save the model specification in a file and read it with specifyModel(file="filename.txt")
. That should also work in interactive mode as well.