library(tidyverse)
library(foreign)
library(lavaan)
library(semPlot)
library(semTools)
library(haven)
#A <- read.spss("U:\\My Documents\\A.sav")
#A <- data.frame(A)
B <- read.spss("U:\\My Documents\\A.sav")
B <- data.frame(B)

model<-'i=~ 1*R1 + 1*R2 + 1*R3 
s =~ 0*R1 + 1*R2 + 2*R3
i ~~ s
i~A
s~A
'
#fit <- growth(model, data=A )
fit <- growth(model, data=B )
summary(fit,fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
semPaths(fit,what = "std.all", edge.label.cex = 0.9, edge.color = 1, esize = 1, sizeMan = 6.5, asize = 4.5, intercepts = FALSE, rotation = 4, thresholdColor = "red", mar = c(1, 5, 1.5, 5), fade = FALSE, nCharNodes = 4)

#https://stats.oarc.ucla.edu/r/seminars/lgm/#s1h
#https://lavaan.ugent.be/tutorial/growth.html

>>>>>>>>>>>>>>> THE ABOVE REGRESSION ESTIMATES FOR 'A' WITH THE INTERCEPT AND SLOPE ARE VERY CLOSE TO THE AVERAGE OF THE A1,A2 AND A3 INDIVIDUAL REGRESSION ESTIMATES OBTAINED AS BELOW WITH THE INTERCEPT AND SLOPE 

#A <- read.spss("U:\\My Documents\\A.sav")
#A <- data.frame(A)
B <- read.spss("U:\\My Documents\\A.sav")
B <- data.frame(A1,A2,A3,R1,R2,R3)

model<-'i=~ 1*R1 + 1*R2 + 1*R3 
s =~ 0*R1 + 1*R2 + 2*R3
i ~~ s
i~A1+A2+A3
s~A1+A2+A3
'
#fit <- growth(model, data=A )
fit <- growth(model, data=B )
summary(fit,fit.measures=TRUE, rsquare=TRUE, standardized=TRUE)
semPaths(fit,what = "std.all", edge.label.cex = 0.9, edge.color = 1, esize = 1, sizeMan = 6.5, asize = 4.5, intercepts = FALSE, rotation = 4, thresholdColor = "red", mar = c(1, 5, 1.5, 5), fade = FALSE, nCharNodes = 4)