Spline Modeling

A few spline models (also known as piecewise models). As in previous posts, ‘affect’ is the name given to values of \(y\) throughout.

1) Growth and Even More Growth

A model that captures a process that increases initially and then increases at an even greater rate once it reaches time point 5. The data generating process:

\[\begin{equation} y_{it} = \begin{cases} 4 + 0.3t + error_{t}, & \text{if time < 5}\\ 8 + 0.9t + error_{t}, & \text{otherwise} \end{cases} \end{equation}\]

The data generating code and plot

library(tidyverse)
library(lavaan)
library(ggplot2)
library(MASS)

N <- 400
time <- 10

intercept_1 <- 4
intercept_2 <- 8

growth1 <- 0.3
growth2 <- 0.9


df_matrix <- matrix(, ncol = 3, nrow = N*time)


count <- 0

for(i in 1:N){
  
  unob_het_y <- rnorm(1,0,1)
  
  
  for(j in 1:time){
    
    count <- count + 1
    
    if(j < 5){
    df_matrix[count, 1] <- i
    df_matrix[count, 2] <- j
    df_matrix[count, 3] <- intercept_1 + growth1*j + unob_het_y + rnorm(1,0,1)
    
    }else{
      
      df_matrix[count, 1] <- i
      df_matrix[count, 2] <- j
      df_matrix[count, 3] <- intercept_2 + growth2*j + unob_het_y + rnorm(1,0,1)
      
      
    }
  }
  
}

df <- data.frame(df_matrix)

names(df) <- c('id', 'time', 'affect')

df1 <- df %>%
  filter(time < 5)

df2 <- df %>%
  filter(time >= 5)

df_sum1 <- df1 %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

df_sum2 <- df2 %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

ggplot() + 
  geom_point(data = df1, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df1, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_point(data = df2, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df2, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df_sum1, aes(x = time, y = affect)) + 
  geom_line(data = df_sum2, aes(x = time, y = affect))

Estimating the parameters using SEM:

library(lavaan)

df_wide <- reshape(df, idvar = 'id', timevar = 'time', direction = 'wide')


spline_string <- [1687 chars quoted with ''']

spline_model <- growth(spline_string, data = df_wide)
summary(spline_model, fit.measures = T)
lavaan 0.6-9 ended normally after 83 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        24
  Number of equality constraints                     9
                                                      
  Number of observations                           400
                                                      
Model Test User Model:
                                                      
  Test statistic                                40.920
  Degrees of freedom                                50
  P-value (Chi-square)                           0.816

Model Test Baseline Model:

  Test statistic                              1854.037
  Degrees of freedom                                45
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    1.000
  Tucker-Lewis Index (TLI)                       1.005

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -6174.770
  Loglikelihood unrestricted model (H1)      -6154.310
                                                      
  Akaike (AIC)                               12379.539
  Bayesian (BIC)                             12439.411
  Sample-size adjusted Bayesian (BIC)        12391.815

Root Mean Square Error of Approximation:

  RMSEA                                          0.000
  90 Percent confidence interval - lower         0.000
  90 Percent confidence interval - upper         0.021
  P-value RMSEA <= 0.05                          1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.032

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect =~                                    
    affect.1          1.000                           
    affect.2          1.000                           
    affect.3          1.000                           
    affect.4          1.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
  level2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          1.000                           
    affect.6          1.000                           
    affect.7          1.000                           
    affect.8          1.000                           
    affect.9          1.000                           
    affect.10         1.000                           
  slope1_affect =~                                    
    affect.1          1.000                           
    affect.2          2.000                           
    affect.3          3.000                           
    affect.4          4.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
  slope2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          5.000                           
    affect.6          6.000                           
    affect.7          7.000                           
    affect.8          8.000                           
    affect.9          9.000                           
    affect.10        10.000                           

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect ~~                                    
    level2_affect     0.941    0.183    5.147    0.000
    slope1_affect    -0.093    0.052   -1.783    0.075
    slope2_affect     0.006    0.021    0.292    0.770
  level2_affect ~~                                    
    slope1_affect     0.041    0.052    0.802    0.423
    slope2_affect    -0.028    0.037   -0.748    0.454
  slope1_affect ~~                                    
    slope2_affect    -0.004    0.006   -0.581    0.561

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .affect.1          0.000                           
   .affect.2          0.000                           
   .affect.3          0.000                           
   .affect.4          0.000                           
   .affect.5          0.000                           
   .affect.6          0.000                           
   .affect.7          0.000                           
   .affect.8          0.000                           
   .affect.9          0.000                           
   .affect.10         0.000                           
    level1_affect     3.929    0.083   47.407    0.000
    level2_affect     7.849    0.107   73.630    0.000
    slope1_affect     0.294    0.024   12.166    0.000
    slope2_affect     0.909    0.013   72.612    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    lvl1_ff           1.234    0.199    6.198    0.000
    lvl2_ff           1.135    0.336    3.375    0.001
    slp1_ff           0.032    0.018    1.839    0.066
    slp2_ff           0.005    0.005    1.068    0.285
   .affct.1 (rs_v)    1.009    0.029   34.641    0.000
   .affct.2 (rs_v)    1.009    0.029   34.641    0.000
   .affct.3 (rs_v)    1.009    0.029   34.641    0.000
   .affct.4 (rs_v)    1.009    0.029   34.641    0.000
   .affct.5 (rs_v)    1.009    0.029   34.641    0.000
   .affct.6 (rs_v)    1.009    0.029   34.641    0.000
   .affct.7 (rs_v)    1.009    0.029   34.641    0.000
   .affct.8 (rs_v)    1.009    0.029   34.641    0.000
   .affct.9 (rs_v)    1.009    0.029   34.641    0.000
   .affc.10 (rs_v)    1.009    0.029   34.641    0.000

The structure of the basis coefficients is the important piece that allows us to capture the change in slope:

'
# latent slope for first half basis coefficients

slope1_affect =~ 1*affect.1 + 2*affect.2 + 3*affect.3 + 4*affect.4 + 0*affect.5 + 0*affect.6 + 0*affect.7 + 0*affect.8 + 0*affect.9 + 0*affect.10

# latent slope for second half basis coefficients

slope2_affect =~ 0*affect.1 + 0*affect.2 + 0*affect.3 + 0*affect.4 + 5*affect.5 + 6*affect.6 + 7*affect.7 + 8*affect.8 + 9*affect.9 + 10*affect.10

'

2) Growth and Negative Growth

A model that captures a process that goes up and then goes down. The data generating process:

\[\begin{equation} y_{it} = \begin{cases} 4 + 0.5t + error_{t}, & \text{if time < 5}\\ 4 - 0.5t + error_{t}, & \text{otherwise} \end{cases} \end{equation}\]

The data generating code and plot

library(tidyverse)
library(lavaan)
library(ggplot2)
library(MASS)

N <- 400
time <- 10

intercept_1 <- 4
intercept_2 <- 4

growth1 <- 0.8
growth2 <- -0.8

df_matrix_b <- matrix(, ncol = 3, nrow = N*time)


count <- 0

for(i in 1:N){
  
  unob_het_y <- rnorm(1,0,1)
  
  
  for(j in 1:time){
    
    count <- count + 1
    
    if(j < 5){
      df_matrix_b[count, 1] <- i
      df_matrix_b[count, 2] <- j
      df_matrix_b[count, 3] <- intercept_1 + growth1*j + unob_het_y + rnorm(1,0,1)
      
    }else{
      
      df_matrix_b[count, 1] <- i
      df_matrix_b[count, 2] <- j
      df_matrix_b[count, 3] <- intercept_2 + growth2*j + unob_het_y + rnorm(1,0,1)
      
      
    }
  }
  
}

df_b <- data.frame(df_matrix_b)

names(df_b) <- c('id', 'time', 'affect')

df1_b <- df_b %>%
  filter(time < 5)

df2_b <- df_b %>%
  filter(time >= 5)

df_sum1_b <- df1_b %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

df_sum2_b <- df2_b %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

ggplot() + 
  geom_point(data = df1_b, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df1_b, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_point(data = df2_b, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df2_b, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df_sum1_b, aes(x = time, y = affect)) + 
  geom_line(data = df_sum2_b, aes(x = time, y = affect))

Estimating the parameters using SEM:

library(lavaan)


df_wide_b <- reshape(df_b, idvar = 'id', timevar = 'time', direction = 'wide')


spline_string_b <- [1687 chars quoted with ''']

spline_model_b <- growth(spline_string_b, data = df_wide_b)
summary(spline_model_b, fit.measures = T)
lavaan 0.6-9 ended normally after 79 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        24
  Number of equality constraints                     9
                                                      
  Number of observations                           400
                                                      
Model Test User Model:
                                                      
  Test statistic                                60.348
  Degrees of freedom                                50
  P-value (Chi-square)                           0.150

Model Test Baseline Model:

  Test statistic                              1931.249
  Degrees of freedom                                45
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.995
  Tucker-Lewis Index (TLI)                       0.995

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -6219.675
  Loglikelihood unrestricted model (H1)      -6189.501
                                                      
  Akaike (AIC)                               12469.349
  Bayesian (BIC)                             12529.221
  Sample-size adjusted Bayesian (BIC)        12481.625

Root Mean Square Error of Approximation:

  RMSEA                                          0.023
  90 Percent confidence interval - lower         0.000
  90 Percent confidence interval - upper         0.041
  P-value RMSEA <= 0.05                          0.995

Standardized Root Mean Square Residual:

  SRMR                                           0.059

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect =~                                    
    affect.1          1.000                           
    affect.2          1.000                           
    affect.3          1.000                           
    affect.4          1.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
  level2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          1.000                           
    affect.6          1.000                           
    affect.7          1.000                           
    affect.8          1.000                           
    affect.9          1.000                           
    affect.10         1.000                           
  slope1_affect =~                                    
    affect.1          1.000                           
    affect.2          2.000                           
    affect.3          3.000                           
    affect.4          4.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
  slope2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          5.000                           
    affect.6          6.000                           
    affect.7          7.000                           
    affect.8          8.000                           
    affect.9          9.000                           
    affect.10        10.000                           

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect ~~                                    
    level2_affect     1.110    0.180    6.151    0.000
    slope1_affect    -0.029    0.049   -0.594    0.553
    slope2_affect     0.016    0.020    0.788    0.431
  level2_affect ~~                                    
    slope1_affect    -0.041    0.046   -0.893    0.372
    slope2_affect     0.036    0.034    1.037    0.300
  slope1_affect ~~                                    
    slope2_affect    -0.003    0.005   -0.576    0.565

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .affect.1          0.000                           
   .affect.2          0.000                           
   .affect.3          0.000                           
   .affect.4          0.000                           
   .affect.5          0.000                           
   .affect.6          0.000                           
   .affect.7          0.000                           
   .affect.8          0.000                           
   .affect.9          0.000                           
   .affect.10         0.000                           
    level1_affect     3.886    0.084   46.497    0.000
    level2_affect     3.740    0.103   36.398    0.000
    slope1_affect     0.813    0.023   36.105    0.000
    slope2_affect    -0.778    0.012  -65.684    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    lvl1_ff           1.241    0.203    6.124    0.000
    lvl2_ff           0.721    0.315    2.289    0.022
    slp1_ff          -0.004    0.016   -0.290    0.772
    slp2_ff          -0.003    0.004   -0.709    0.478
   .affct.1 (rs_v)    1.035    0.030   34.641    0.000
   .affct.2 (rs_v)    1.035    0.030   34.641    0.000
   .affct.3 (rs_v)    1.035    0.030   34.641    0.000
   .affct.4 (rs_v)    1.035    0.030   34.641    0.000
   .affct.5 (rs_v)    1.035    0.030   34.641    0.000
   .affct.6 (rs_v)    1.035    0.030   34.641    0.000
   .affct.7 (rs_v)    1.035    0.030   34.641    0.000
   .affct.8 (rs_v)    1.035    0.030   34.641    0.000
   .affct.9 (rs_v)    1.035    0.030   34.641    0.000
   .affc.10 (rs_v)    1.035    0.030   34.641    0.000

Notice that the string syntax is the exact same because the process changes at the same point in time, it does not matter if the process changes to ‘more positive’ or ‘more negative.’

3) Negative Growth, Growth, and Negative Growth

Now a process that goes down, goes up, and then goes back down. The data generating process:

\[\begin{equation} y_{it} = \begin{cases} 4 - 0.5t + error_{t}, & \text{if time < 5}\\ 4 + 0.5t + error_{t}, & \text{if 5 < time < 10}\\ 4 - 0.5t + error_{t}, & \text{otherwise} \end{cases} \end{equation}\]

The data generating code and plot

library(tidyverse)
library(lavaan)
library(ggplot2)
library(MASS)

N <- 400
time <- 15

intercept_1 <- 4
intercept_2 <- 4
intercept_3 <- 4

growth1 <- -0.5
growth2 <- 0.5
growth3 <- -0.5


df_matrix_c <- matrix(, ncol = 3, nrow = N*time)


count <- 0

for(i in 1:N){
  
  unob_het_y <- rnorm(1,0,1)
  
  
  for(j in 1:time){
    
    count <- count + 1
    
    if(j < 5){
      df_matrix_c[count, 1] <- i
      df_matrix_c[count, 2] <- j
      df_matrix_c[count, 3] <- intercept_1 + growth1*j + unob_het_y + rnorm(1,0,1)
      
    }else if(j >= 5 && j < 10){
      
      df_matrix_c[count, 1] <- i
      df_matrix_c[count, 2] <- j
      df_matrix_c[count, 3] <- intercept_2 + growth2*j + unob_het_y + rnorm(1,0,1)
      
      
    }else{
      
      df_matrix_c[count, 1] <- i
      df_matrix_c[count, 2] <- j
      df_matrix_c[count, 3] <- intercept_3 + growth3*j + unob_het_y + rnorm(1,0,1)
      
    }
  }
  
}

df_c <- data.frame(df_matrix_c)

names(df_c) <- c('id', 'time', 'affect')

df1_c <- df_c %>%
  filter(time < 5)

df2_c <- df_c %>%
  filter(time >= 5 & time < 10)

df3_c <- df_c %>%
  filter(time >= 10)

df_sum1_c <- df1_c %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

df_sum2_c <- df2_c %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

df_sum3_c <- df3_c %>%
  group_by(time) %>%
  summarise(
    affect = mean(affect)
  )

ggplot() + 
  geom_point(data = df1_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df1_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_point(data = df2_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df2_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df_sum1_c, aes(x = time, y = affect)) + 
  geom_line(data = df_sum2_c, aes(x = time, y = affect)) + 
  geom_point(data = df3_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df3_c, aes(x = time, y = affect, group = id), color = 'gray85') + 
  geom_line(data = df_sum3_c, aes(x = time, y = affect))

Now estimate the parameters using SEM:

library(lavaan)

df_wide_c <- reshape(df_c, idvar = 'id', timevar = 'time', direction = 'wide')


spline_string_c <- [2843 chars quoted with ''']

spline_model_c <- growth(spline_string_c, data = df_wide_c)
summary(spline_model_c, fit.measures = T)
lavaan 0.6-9 ended normally after 167 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        42
  Number of equality constraints                     9
                                                      
  Number of observations                           400
                                                      
Model Test User Model:
                                                      
  Test statistic                               120.754
  Degrees of freedom                               102
  P-value (Chi-square)                           0.099

Model Test Baseline Model:

  Test statistic                              3055.629
  Degrees of freedom                               105
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.994
  Tucker-Lewis Index (TLI)                       0.993

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -9115.240
  Loglikelihood unrestricted model (H1)      -9054.863
                                                      
  Akaike (AIC)                               18296.479
  Bayesian (BIC)                             18428.198
  Sample-size adjusted Bayesian (BIC)        18323.486

Root Mean Square Error of Approximation:

  RMSEA                                          0.021
  90 Percent confidence interval - lower         0.000
  90 Percent confidence interval - upper         0.035
  P-value RMSEA <= 0.05                          1.000

Standardized Root Mean Square Residual:

  SRMR                                           0.040

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect =~                                    
    affect.1          1.000                           
    affect.2          1.000                           
    affect.3          1.000                           
    affect.4          1.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
    affect.11         0.000                           
    affect.12         0.000                           
    affect.13         0.000                           
    affect.14         0.000                           
    affect.15         0.000                           
  level2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          1.000                           
    affect.6          1.000                           
    affect.7          1.000                           
    affect.8          1.000                           
    affect.9          1.000                           
    affect.10         0.000                           
    affect.11         0.000                           
    affect.12         0.000                           
    affect.13         0.000                           
    affect.14         0.000                           
    affect.15         0.000                           
  level3_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         1.000                           
    affect.11         1.000                           
    affect.12         1.000                           
    affect.13         1.000                           
    affect.14         1.000                           
    affect.15         1.000                           
  slope1_affect =~                                    
    affect.1          1.000                           
    affect.2          2.000                           
    affect.3          3.000                           
    affect.4          4.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10         0.000                           
    affect.11         0.000                           
    affect.12         0.000                           
    affect.13         0.000                           
    affect.14         0.000                           
    affect.15         0.000                           
  slope2_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          5.000                           
    affect.6          6.000                           
    affect.7          7.000                           
    affect.8          8.000                           
    affect.9          9.000                           
    affect.10         0.000                           
    affect.11         0.000                           
    affect.12         0.000                           
    affect.13         0.000                           
    affect.14         0.000                           
    affect.15         0.000                           
  slope3_affect =~                                    
    affect.1          0.000                           
    affect.2          0.000                           
    affect.3          0.000                           
    affect.4          0.000                           
    affect.5          0.000                           
    affect.6          0.000                           
    affect.7          0.000                           
    affect.8          0.000                           
    affect.9          0.000                           
    affect.10        10.000                           
    affect.11        11.000                           
    affect.12        12.000                           
    affect.13        13.000                           
    affect.14        14.000                           
    affect.15        15.000                           

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  level1_affect ~~                                    
    level2_affect     1.113    0.209    5.311    0.000
    level3_affect     1.354    0.280    4.844    0.000
    slope1_affect    -0.046    0.051   -0.902    0.367
    slope2_affect    -0.004    0.025   -0.169    0.866
    slope3_affect    -0.023    0.020   -1.142    0.254
  level2_affect ~~                                    
    level3_affect     0.729    0.399    1.828    0.067
    slope1_affect    -0.062    0.058   -1.074    0.283
    slope2_affect     0.076    0.055    1.391    0.164
    slope3_affect     0.021    0.030    0.725    0.468
  level3_affect ~~                                    
    slope1_affect    -0.074    0.077   -0.963    0.336
    slope2_affect     0.048    0.050    0.960    0.337
    slope3_affect    -0.028    0.060   -0.462    0.644
  slope1_affect ~~                                    
    slope2_affect     0.005    0.007    0.626    0.531
    slope3_affect     0.003    0.006    0.511    0.609
  slope2_affect ~~                                    
    slope3_affect    -0.004    0.004   -1.151    0.250

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .affect.1          0.000                           
   .affect.2          0.000                           
   .affect.3          0.000                           
   .affect.4          0.000                           
   .affect.5          0.000                           
   .affect.6          0.000                           
   .affect.7          0.000                           
   .affect.8          0.000                           
   .affect.9          0.000                           
   .affect.10         0.000                           
   .affect.11         0.000                           
   .affect.12         0.000                           
   .affect.13         0.000                           
   .affect.14         0.000                           
   .affect.15         0.000                           
    level1_affect     3.876    0.083   46.673    0.000
    level2_affect     3.993    0.122   32.835    0.000
    level3_affect     3.964    0.163   24.272    0.000
    slope1_affect    -0.491    0.024  -20.791    0.000
    slope2_affect     0.496    0.015   32.376    0.000
    slope3_affect    -0.501    0.012  -41.367    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
    lvl1_ff           1.167    0.201    5.816    0.000
    lvl2_ff           0.505    0.448    1.127    0.260
    lvl3_ff           1.470    0.815    1.804    0.071
    slp1_ff           0.011    0.017    0.666    0.505
    slp2_ff          -0.012    0.007   -1.658    0.097
    slp3_ff           0.001    0.005    0.253    0.801
   .affct.1 (rs_v)    1.061    0.032   33.639    0.000
   .affct.2 (rs_v)    1.061    0.032   33.639    0.000
   .affct.3 (rs_v)    1.061    0.032   33.639    0.000
   .affct.4 (rs_v)    1.061    0.032   33.639    0.000
   .affct.5 (rs_v)    1.061    0.032   33.639    0.000
   .affct.6 (rs_v)    1.061    0.032   33.639    0.000
   .affct.7 (rs_v)    1.061    0.032   33.639    0.000
   .affct.8 (rs_v)    1.061    0.032   33.639    0.000
   .affct.9 (rs_v)    1.061    0.032   33.639    0.000
   .affc.10 (rs_v)    1.061    0.032   33.639    0.000
   .affc.11           0.958    0.076   12.593    0.000
   .affc.12           0.939    0.072   12.961    0.000
   .affc.13           0.896    0.069   12.940    0.000
   .affc.14           0.964    0.076   12.657    0.000
   .affc.15           1.001    0.087   11.487    0.000

Again, the basis coefficients are the important piece here:

'


# latent slope for first third basis coefficients

slope1_affect =~ 1*affect.1 + 2*affect.2 + 3*affect.3 + 4*affect.4 + 
                 0*affect.5 + 0*affect.6 + 0*affect.7 + 0*affect.8 + 
                 0*affect.9 + 0*affect.10 + 0*affect.11 + 0*affect.12 + 
                 0*affect.13 + 0*affect.14 + 0*affect.15

# latent slope for second third basis coefficients

slope2_affect =~ 0*affect.1 + 0*affect.2 + 0*affect.3 + 0*affect.4 + 
                 5*affect.5 + 6*affect.6 + 7*affect.7 + 8*affect.8 + 
                 9*affect.9 + 0*affect.10 + 0*affect.11 + 0*affect.12 + 
                 0*affect.13 + 0*affect.14 + 0*affect.15

# latent slope for final third basis coefficients

slope3_affect =~ 0*affect.1 + 0*affect.2 + 0*affect.3 + 0*affect.4 +
                 0*affect.5 + 0*affect.6 + 0*affect.7 + 0*affect.8 + 
                 0*affect.9 + 10*affect.10 + 11*affect.11 + 12*affect.12 + 
                 13*affect.13 + 14*affect.14 + 15*affect.15



'
[1] "\n\n\n# latent slope for first third basis coefficients\n\nslope1_affect =~ 1*affect.1 + 2*affect.2 + 3*affect.3 + 4*affect.4 + \n                 0*affect.5 + 0*affect.6 + 0*affect.7 + 0*affect.8 + \n                 0*affect.9 + 0*affect.10 + 0*affect.11 + 0*affect.12 + \n                 0*affect.13 + 0*affect.14 + 0*affect.15\n\n# latent slope for second third basis coefficients\n\nslope2_affect =~ 0*affect.1 + 0*affect.2 + 0*affect.3 + 0*affect.4 + \n                 5*affect.5 + 6*affect.6 + 7*affect.7 + 8*affect.8 + \n                 9*affect.9 + 0*affect.10 + 0*affect.11 + 0*affect.12 + \n                 0*affect.13 + 0*affect.14 + 0*affect.15\n\n# latent slope for final third basis coefficients\n\nslope3_affect =~ 0*affect.1 + 0*affect.2 + 0*affect.3 + 0*affect.4 +\n                 0*affect.5 + 0*affect.6 + 0*affect.7 + 0*affect.8 + \n                 0*affect.9 + 10*affect.10 + 11*affect.11 + 12*affect.12 + \n                 13*affect.13 + 14*affect.14 + 15*affect.15\n\n\n\n"

Bo\(^2\)m =)