Advertisement
titounnes

sem program

Feb 16th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # Load package lavaan
  2. vs = as.numeric(R.version$major)+as.numeric(R.version$minor)
  3. if(vs < 3.5){
  4. cat(paste("Minimun version is 3.5. Your R version is", vs,"\n"))
  5. quit()
  6. }
  7.  
  8. for(p in c('lavaan')){
  9. if(!require(p,character.only = TRUE)) install.packages(p)
  10. library(p,character.only = TRUE)
  11. }
  12.  
  13. # Load data sample.csv
  14. myData = read.csv('sample.csv')
  15. myData
  16.  
  17. # membangun model
  18. myModel <- '
  19. # measurement model
  20. ind60 =~ x1 + x2 + x3
  21. dem60 =~ y1 + y2 + y3 + y4
  22. dem65 =~ y5 + y6 + y7 + y8
  23. # regressions
  24. dem60 ~ ind60
  25. dem65 ~ ind60 + dem60
  26. # residual correlations
  27. y1 ~~ y5
  28. y2 ~~ y4 + y6
  29. y3 ~~ y7
  30. y4 ~~ y8
  31. y6 ~~ y8
  32. '
  33. # Analsiis
  34. fit <- sem(model = myModel, data = myData)
  35. summary(fit, fit.measures = TRUE)
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement