Required Packages:
library(tidyverse)
library(corrplot)
library(BayesFM)
library(hablar)
library(blavaan)
Read the data from our behavioral stability dataset, remove columns with session information, and transform integer variables into numeric variables (which is required by the BayesFM package). This also randomly removes 3 participants whose first session was prompt S to correct counterbalancing.
df <- read_csv("by_token_estimates.csv")
# Remove 3 participants for which session_no 1 was prompt S at random
set.seed(365)
rnd_subs <- filter(df, session_no == "1", prompt == "S") %>%
pull(participant) %>% factor() %>% levels() %>%
sample(3)
df <- df %>% filter(!(participant %in% rnd_subs)) %>%
mutate(across(participant, factor))
# Check counterbalancing
count(df, session_no, prompt)
## # A tibble: 9 × 3
## session_no prompt n
## <dbl> <chr> <int>
## 1 1 A 10
## 2 1 G 10
## 3 1 S 10
## 4 2 A 10
## 5 2 G 10
## 6 2 S 10
## 7 3 A 10
## 8 3 G 10
## 9 3 S 10
df <- df %>%
select(-c(token, prompt, session_no, participant)) %>%
mutate(across(c(starts_with("n_"), starts_with("len_")), ~log(.+1)),
across(starts_with("prop_"), brms::logit_scaled),
across(where(is.numeric), ~scale(.)[,1]))
Create a correlation matrix for the variables in the dataset: (very ugly and unreadable right now. Need to figure out how to adjust that)
cor_stability <- cor(df)
corrplot::corrplot.mixed(corr = cor_stability,
upper = "ellipse",
order = "hclust")
We want 45 sessions for exploratory factor analysis. Then we will check the factor loadings, ensure that they make sense, and then confirm that the other half of the data has the same factor structure through confirmatory factor analysis.
n <- 2
list_dfs <- split(df, factor(sort(rank(row.names(df))%%n)))
df.efa <- list_dfs[[1]]
df.cfa <- list_dfs[[2]]
Select Nid (Minimum number of manifest variables dedicated to each latent factor for identification.) and Kmax (Maximum number of latent factors):
Nid <- 2
# Kmax <- trunc(x = ncol(df)/Nid); Kmax # This is the default formula for Kmax, but I am going to manually set it to 5 because that's what we believe should be the actual maximum number of factors for this data.
Kmax <- 5
set.seed(823) # this is a random number generator seed. Setting it to a given number makes results reproducible.
simul.R.prior_df.efa <- simul.R.prior(
Kmax = Kmax,
nu0 = Kmax + c(1, 2, 5, 7, 10)
)
## simulating prior for nu0 = 6 and S0 = 1
## simulating prior for nu0 = 7 and S0 = 1
## simulating prior for nu0 = 10 and S0 = 1
## simulating prior for nu0 = 12 and S0 = 1
## simulating prior for nu0 = 15 and S0 = 1
simul.R.prior_df.efa
## sample from prior distribution of factor correlation matrix
##
## call:
## simul.R.prior(Kmax = Kmax, nu0 = Kmax + c(1, 2, 5, 7, 10))
##
## Kmax = 5
##
## parameter values:
## nu0 = 6, S0 = 1
## nu0 = 7, S0 = 1
## nu0 = 10, S0 = 1
## nu0 = 12, S0 = 1
## nu0 = 15, S0 = 1
##
## nrep = 1e+05
##
## use summary() and plot() functions to summarize and plot prior density
## of maximum correlation and/or of minimum eigenvalue
We review this output to look at possible maximum correlations for each randomly generated covariance matrix for each distribution for different nu0 values:
summary(object = simul.R.prior_df.efa)
## prior distribution of correlation matrix of latent factors
##
## maximum correlation (in absolute value):
##
## mean median sd min max
## nu0 = 6, S0 = 1 0.822 0.849 0.133 0.223 1.000
## nu0 = 7, S0 = 1 0.758 0.774 0.140 0.193 1.000
## nu0 = 10, S0 = 1 0.625 0.625 0.139 0.120 0.985
## nu0 = 12, S0 = 1 0.566 0.563 0.133 0.109 0.991
## nu0 = 15, S0 = 1 0.503 0.498 0.122 0.110 0.951
##
## 5% 10% 25% 75% 90% 95%
## nu0 = 6, S0 = 1 0.568 0.631 0.739 0.930 0.973 0.986
## nu0 = 7, S0 = 1 0.504 0.561 0.662 0.870 0.933 0.959
## nu0 = 10, S0 = 1 0.395 0.442 0.526 0.726 0.809 0.851
## nu0 = 12, S0 = 1 0.352 0.395 0.471 0.660 0.744 0.790
## nu0 = 15, S0 = 1 0.311 0.348 0.415 0.587 0.667 0.713
##
## minimum eigenvalue of correlation matrix:
##
## mean median sd min max
## nu0 = 6, S0 = 1 0.103 0.082 0.086 0.000 0.702
## nu0 = 7, S0 = 1 0.151 0.134 0.097 0.000 0.727
## nu0 = 10, S0 = 1 0.263 0.253 0.110 0.008 0.791
## nu0 = 12, S0 = 1 0.317 0.310 0.111 0.008 0.820
## nu0 = 15, S0 = 1 0.380 0.376 0.108 0.047 0.806
##
## 5% 10% 25% 75% 90% 95%
## nu0 = 6, S0 = 1 0.007 0.015 0.037 0.147 0.221 0.272
## nu0 = 7, S0 = 1 0.025 0.040 0.076 0.207 0.286 0.336
## nu0 = 10, S0 = 1 0.100 0.128 0.183 0.333 0.412 0.460
## nu0 = 12, S0 = 1 0.148 0.179 0.237 0.390 0.465 0.511
## nu0 = 15, S0 = 1 0.211 0.243 0.303 0.452 0.524 0.567
Plotting this lets us look at the distributions for maximum correlation and eigenvalues. If we don’t know what to expect, we want larger variance and a central tendency closer to the middle. (For the eigenvalue plots, shorter peaks mean greater variance.)
plot(x = simul.R.prior_df.efa)
simul.nfac.prior_df.efa <- BayesFM::simul.nfac.prior(
nvar = ncol(df.efa),
Kmax = Kmax,
Nid = Nid,
kappa = c(.1, .2, .5, 1)
)
simul.nfac.prior_df.efa
## sample from prior distribution of number of latent factors
##
## call:
## BayesFM::simul.nfac.prior(nvar = ncol(df.efa), Kmax = Kmax, Nid = Nid,
## kappa = c(0.1, 0.2, 0.5, 1))
##
## nvar = 20
## Kmax = 5
## Nid = 2
## kappa = 0.1 0.2 0.5 1
## nrep = 1e+06
##
## use summary() and plot() functions to summarize and plot
## prior distribution of number of latent factors
This gives the likelihoods of the model choosing each number of factors (1 through 11 factors) given a kappa value:
summary(object = simul.nfac.prior_df.efa)
## prior probabilities of numbers of factors:
## 1 2 3 4 5 acc
## kappa = 0.1 0.387 0.452 0.145 0.015 0.000 0.728
## kappa = 0.2 0.164 0.439 0.319 0.073 0.005 0.604
## kappa = 0.5 0.018 0.179 0.432 0.313 0.058 0.470
## kappa = 1 0.001 0.036 0.258 0.488 0.216 0.437
Plotting these likelihoods
plot(x = simul.nfac.prior_df.efa)
Nid <- 2
Kmax <- 5 # selected from what we believe to be a reasonable amount of reduction for this data with 20 variables
nu0 <- 15 #chosen from the plotted values that looked "best" from line 31
kappa <- .5
simul.R.prior_df.efa <- BayesFM::simul.R.prior(
Kmax = Kmax,
nu0 = nu0
)
## simulating prior for nu0 = 15 and S0 = 1
simul.R.prior_df.efa
## sample from prior distribution of factor correlation matrix
##
## call:
## BayesFM::simul.R.prior(Kmax = Kmax, nu0 = nu0)
##
## Kmax = 5
##
## parameter values:
## nu0 = 15, S0 = 1
##
## nrep = 1e+05
##
## use summary() and plot() functions to summarize and plot prior density
## of maximum correlation and/or of minimum eigenvalue
Plotting with just the selected parameters. This is what we assume to be the distribution prior to looking at the data:
plot(x = simul.R.prior_df.efa)
Prior probabilities for the number of factors:
simul.nfac.prior_df.efa <- BayesFM::simul.nfac.prior(
nvar = ncol(df),
Kmax = Kmax,
Nid = Nid,
kappa = kappa
)
#simul.nfac.prior_df
summary(object = simul.nfac.prior_df.efa)
## prior probabilities of numbers of factors:
## 1 2 3 4 5 acc
## kappa = 0.5 0.018 0.179 0.433 0.313 0.057 0.47
befa_stability <- BayesFM::befa(
model = df.efa,
burnin = 5000,
iter = 50000,
Nid = Nid,
Kmax = Kmax,
nu0 = nu0,
kappa = kappa,
kappa0 = 0.5,
xi0 = 0.5
)
## starting MCMC sampling...
## 5%
## done with burn-in period
## 10%
## 15%
## 20%
## 25%
## 30%
## 35%
## 40%
## 45%
## 50%
## 55%
## 60%
## 65%
## 70%
## 75%
## 80%
## 85%
## 90%
## 95%
## 100%
## done with sampling!
befa_stability <- BayesFM::post.column.switch(
mcmc = befa_stability
)
befa_stability <- BayesFM::post.sign.switch(
mcmc = befa_stability
)
Summary and plot
summary(object = befa_stability)
## BEFA - Bayesian Exploratory Factor Analysis
## Summary of posterior results
##
## Maximum number of factors (Kmax) = 5
## Identification restriction (Nid) = 2
##
## MCMC iterations = 50000
## burn-in period = 5000
##
## Metropolis-Hastings acceptance rate = 0.897
##
## Posterior frequency of number of latent factors:
## K = 4 70.68%
## K = 5 29.12%
##
## -----------------------------------------------------------------
## Model parameters
##
## Factor loadings:
##
## dedic prob mean sd
## alpha:n_major_block 1 0.897 0.562 0.253
## alpha:n_jumps 1 0.707 0.862 0.183
## alpha:n_edges 1 0.707 0.874 0.174
## alpha:n_sustained_reading 1 0.958 0.621 0.115
## alpha:prop_edits_before_sentence 2 0.698 -0.724 0.156
## alpha:prop_edits_before_word 2 0.699 -0.881 0.113
## alpha:prop_edits_within_word 2 0.699 -0.829 0.106
## alpha:prop_lookbacks_before_sentence 3 0.701 0.769 0.131
## alpha:prop_lookbacks_before_word 3 0.701 0.793 0.110
## alpha:prop_lookbacks_within_word 3 0.701 0.730 0.116
## alpha:len_nonlookbacks 3 0.701 -0.839 0.104
## alpha:len_prodseq 2 0.699 0.737 0.133
## alpha:lookback_duration 0 0.910
## alpha:prob_long_lookback_duration 4 0.357 0.519 0.188
## alpha:short_event_duration_before_sentence 4 0.419 0.523 0.185
## alpha:short_event_duration_before_word 4 0.698 0.891 0.170
## alpha:short_event_duration_within_word 4 0.699 0.900 0.170
## alpha:prob_long_event_duration_before_sentence 0 0.913
## alpha:prob_long_event_duration_before_word 0 0.808
## alpha:prob_long_event_duration_within_word 0 0.862
## [ 95% hpd ]
## alpha:n_major_block 0.231 0.992
## alpha:n_jumps 0.632 1.135
## alpha:n_edges 0.673 1.125
## alpha:n_sustained_reading 0.398 0.846
## alpha:prop_edits_before_sentence -1.028 -0.416
## alpha:prop_edits_before_word -1.109 -0.673
## alpha:prop_edits_within_word -1.042 -0.631
## alpha:prop_lookbacks_before_sentence 0.520 1.035
## alpha:prop_lookbacks_before_word 0.583 1.011
## alpha:prop_lookbacks_within_word 0.506 0.959
## alpha:len_nonlookbacks -1.054 -0.650
## alpha:len_prodseq 0.477 0.999
## alpha:lookback_duration
## alpha:prob_long_lookback_duration 0.193 0.848
## alpha:short_event_duration_before_sentence 0.189 0.882
## alpha:short_event_duration_before_word 0.567 1.230
## alpha:short_event_duration_within_word 0.575 1.243
## alpha:prob_long_event_duration_before_sentence
## alpha:prob_long_event_duration_before_word
## alpha:prob_long_event_duration_within_word
##
## Idiosyncratic variances:
##
## mean sd [ 95% hpd ]
## sigma:n_major_block 0.830 0.231 0.425 1.331
## sigma:n_jumps 0.251 0.080 0.115 0.411
## sigma:n_edges 0.164 0.049 0.081 0.261
## sigma:n_sustained_reading 0.293 0.099 0.101 0.469
## sigma:prop_edits_before_sentence 0.728 0.165 0.444 1.061
## sigma:prop_edits_before_word 0.154 0.043 0.080 0.240
## sigma:prop_edits_within_word 0.138 0.037 0.074 0.211
## sigma:prop_lookbacks_before_sentence 0.401 0.093 0.239 0.590
## sigma:prop_lookbacks_before_word 0.178 0.047 0.096 0.270
## sigma:prop_lookbacks_within_word 0.267 0.065 0.150 0.394
## sigma:len_nonlookbacks 0.106 0.028 0.059 0.161
## sigma:len_prodseq 0.456 0.106 0.273 0.670
## sigma:lookback_duration 0.636 0.133 0.409 0.907
## sigma:prob_long_lookback_duration 0.706 0.186 0.386 1.090
## sigma:short_event_duration_before_sentence 0.907 0.241 0.492 1.387
## sigma:short_event_duration_before_word 0.495 0.192 0.154 0.847
## sigma:short_event_duration_within_word 0.488 0.195 0.145 0.849
## sigma:prob_long_event_duration_before_sentence 0.913 0.194 0.576 1.301
## sigma:prob_long_event_duration_before_word 0.999 0.219 0.617 1.452
## sigma:prob_long_event_duration_within_word 1.143 0.244 0.724 1.642
##
## Factor correlation matrix:
##
## mean sd [ 95% hpd ]
## R:1:2 -0.363 0.211 -0.782 -0.031
## R:1:3 0.030 0.187 -0.361 0.360
## R:1:4 0.058 0.272 -0.570 0.499
## R:1:5 0.006 0.258 -0.495 0.506
## R:2:3 0.167 0.178 -0.165 0.516
## R:2:4 0.140 0.177 -0.202 0.472
## R:2:5 -0.007 0.262 -0.513 0.496
## R:3:4 -0.032 0.160 -0.340 0.280
## R:3:5 0.012 0.252 -0.462 0.493
## R:4:5 0.010 0.240 -0.480 0.477
plot(x = befa_stability)
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
b1 <- befa(df.efa)
## starting MCMC sampling...
## 5%
## done with burn-in period
## 10%
## 15%
## 20%
## 25%
## 30%
## 35%
## 40%
## 45%
## 50%
## 55%
## 60%
## 65%
## 70%
## 75%
## 80%
## 85%
## 90%
## 95%
## 100%
## done with sampling!
b1 <- BayesFM::post.column.switch(
mcmc = b1
)
b1 <- BayesFM::post.sign.switch(
mcmc = b1
)
summary(object = b1)
## BEFA - Bayesian Exploratory Factor Analysis
## Summary of posterior results
##
## Maximum number of factors (Kmax) = 6
## Identification restriction (Nid) = 3
##
## MCMC iterations = 10000
## burn-in period = 1000
##
## Metropolis-Hastings acceptance rate = 0.523
##
## Posterior frequency of number of latent factors:
## K = 4 97.84%
##
## -----------------------------------------------------------------
## Model parameters
##
## Factor loadings:
##
## dedic prob mean sd
## alpha:n_major_block 1 0.723 0.559 0.196
## alpha:n_jumps 1 0.971 0.886 0.131
## alpha:n_edges 1 0.971 0.894 0.118
## alpha:n_sustained_reading 1 0.982 0.605 0.117
## alpha:prop_edits_before_sentence 2 0.966 0.736 0.159
## alpha:prop_edits_before_word 2 0.970 0.895 0.115
## alpha:prop_edits_within_word 2 0.970 0.842 0.110
## alpha:prop_lookbacks_before_sentence 3 0.972 0.780 0.137
## alpha:prop_lookbacks_before_word 3 0.972 0.801 0.114
## alpha:prop_lookbacks_within_word 3 0.972 0.736 0.117
## alpha:len_nonlookbacks 3 0.972 -0.850 0.109
## alpha:len_prodseq 2 0.970 -0.757 0.139
## alpha:lookback_duration 0 0.952
## alpha:prob_long_lookback_duration 4 0.705 0.539 0.157
## alpha:short_event_duration_before_sentence 4 0.580 0.526 0.169
## alpha:short_event_duration_before_word 4 0.963 0.888 0.175
## alpha:short_event_duration_within_word 4 0.963 0.905 0.170
## alpha:prob_long_event_duration_before_sentence 0 0.957
## alpha:prob_long_event_duration_before_word 0 0.900
## alpha:prob_long_event_duration_within_word 0 0.921
## [ 95% hpd ]
## alpha:n_major_block 0.227 0.917
## alpha:n_jumps 0.628 1.144
## alpha:n_edges 0.668 1.124
## alpha:n_sustained_reading 0.383 0.840
## alpha:prop_edits_before_sentence 0.456 1.078
## alpha:prop_edits_before_word 0.694 1.139
## alpha:prop_edits_within_word 0.633 1.056
## alpha:prop_lookbacks_before_sentence 0.537 1.071
## alpha:prop_lookbacks_before_word 0.593 1.031
## alpha:prop_lookbacks_within_word 0.518 0.973
## alpha:len_nonlookbacks -1.059 -0.640
## alpha:len_prodseq -1.046 -0.505
## alpha:lookback_duration
## alpha:prob_long_lookback_duration 0.243 0.855
## alpha:short_event_duration_before_sentence 0.182 0.834
## alpha:short_event_duration_before_word 0.546 1.233
## alpha:short_event_duration_within_word 0.564 1.222
## alpha:prob_long_event_duration_before_sentence
## alpha:prob_long_event_duration_before_word
## alpha:prob_long_event_duration_within_word
##
## Idiosyncratic variances:
##
## mean sd [ 95% hpd ]
## sigma:n_major_block 0.927 0.248 0.495 1.411
## sigma:n_jumps 0.261 0.078 0.128 0.422
## sigma:n_edges 0.164 0.048 0.081 0.259
## sigma:n_sustained_reading 0.332 0.083 0.193 0.519
## sigma:prop_edits_before_sentence 0.726 0.167 0.451 1.058
## sigma:prop_edits_before_word 0.155 0.043 0.086 0.246
## sigma:prop_edits_within_word 0.141 0.038 0.075 0.215
## sigma:prop_lookbacks_before_sentence 0.401 0.094 0.239 0.590
## sigma:prop_lookbacks_before_word 0.179 0.047 0.093 0.268
## sigma:prop_lookbacks_within_word 0.269 0.066 0.152 0.401
## sigma:len_nonlookbacks 0.107 0.028 0.058 0.162
## sigma:len_prodseq 0.455 0.105 0.267 0.658
## sigma:lookback_duration 0.639 0.136 0.399 0.899
## sigma:prob_long_lookback_duration 0.689 0.187 0.367 1.082
## sigma:short_event_duration_before_sentence 0.912 0.238 0.517 1.410
## sigma:short_event_duration_before_word 0.526 0.216 0.148 0.956
## sigma:short_event_duration_within_word 0.511 0.219 0.147 0.916
## sigma:prob_long_event_duration_before_sentence 0.916 0.192 0.574 1.298
## sigma:prob_long_event_duration_before_word 1.012 0.217 0.640 1.443
## sigma:prob_long_event_duration_within_word 1.156 0.246 0.734 1.662
##
## Factor correlation matrix:
##
## mean sd [ 95% hpd ]
## R:1:2 0.355 0.156 0.059 0.660
## R:1:3 0.118 0.158 -0.198 0.408
## R:1:4 0.162 0.177 -0.193 0.499
## R:1:5 -0.004 0.399 -0.754 0.714
## R:1:6 0.000 0.399 -0.737 0.730
## R:2:3 -0.111 0.167 -0.421 0.216
## R:2:4 -0.237 0.167 -0.558 0.073
## R:2:5 0.005 0.410 -0.759 0.750
## R:2:6 0.008 0.407 -0.777 0.727
## R:3:4 -0.052 0.170 -0.380 0.299
## R:3:5 0.024 0.368 -0.729 0.702
## R:3:6 0.003 0.369 -0.697 0.716
## R:4:5 -0.011 0.389 -0.725 0.706
## R:4:6 -0.007 0.379 -0.740 0.690
## R:5:6 -0.008 0.460 -0.802 0.820
Plot using defaults
plot(x = b1)
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
## Press <Enter> to show next graph...
Get the most popular factor allocation and loadings using defaults
summary(b1, hpd.prob = .95)$alpha %>%
round(2) %>%
rownames_to_column("measure") %>%
mutate(loading = paste0(mean," [",hpd.lo,", ",hpd.up,"]")
, measure = str_remove(measure,"alpha:")) %>%
select(measure, "factor" = dedic, loading) %>%
arrange(factor) %>%
knitr::kable()
| measure | factor | loading |
|---|---|---|
| lookback_duration | 0 | NA [NA, NA] |
| prob_long_event_duration_before_sentence | 0 | NA [NA, NA] |
| prob_long_event_duration_before_word | 0 | NA [NA, NA] |
| prob_long_event_duration_within_word | 0 | NA [NA, NA] |
| n_major_block | 1 | 0.56 [0.23, 0.92] |
| n_jumps | 1 | 0.89 [0.63, 1.14] |
| n_edges | 1 | 0.89 [0.67, 1.12] |
| n_sustained_reading | 1 | 0.6 [0.38, 0.84] |
| prop_edits_before_sentence | 2 | 0.74 [0.46, 1.08] |
| prop_edits_before_word | 2 | 0.9 [0.69, 1.14] |
| prop_edits_within_word | 2 | 0.84 [0.63, 1.06] |
| len_prodseq | 2 | -0.76 [-1.05, -0.5] |
| prop_lookbacks_before_sentence | 3 | 0.78 [0.54, 1.07] |
| prop_lookbacks_before_word | 3 | 0.8 [0.59, 1.03] |
| prop_lookbacks_within_word | 3 | 0.74 [0.52, 0.97] |
| len_nonlookbacks | 3 | -0.85 [-1.06, -0.64] |
| prob_long_lookback_duration | 4 | 0.54 [0.24, 0.85] |
| short_event_duration_before_sentence | 4 | 0.53 [0.18, 0.83] |
| short_event_duration_before_word | 4 | 0.89 [0.55, 1.23] |
| short_event_duration_within_word | 4 | 0.9 [0.56, 1.22] |
Correlations among all factors using defaults
summary(b1)$R %>%
round(2) %>%
rownames_to_column("factors") %>%
mutate(correlation = paste0(mean," [",hpd.lo,", ",hpd.up,"]")
, factors = str_remove(factors,"R:")) %>%
select(factors, correlation) %>%
knitr::kable()
| factors | correlation |
|---|---|
| 1:2 | 0.35 [0.06, 0.66] |
| 1:3 | 0.12 [-0.2, 0.41] |
| 1:4 | 0.16 [-0.19, 0.5] |
| 1:5 | 0 [-0.75, 0.71] |
| 1:6 | 0 [-0.74, 0.73] |
| 2:3 | -0.11 [-0.42, 0.22] |
| 2:4 | -0.24 [-0.56, 0.07] |
| 2:5 | 0 [-0.76, 0.75] |
| 2:6 | 0.01 [-0.78, 0.73] |
| 3:4 | -0.05 [-0.38, 0.3] |
| 3:5 | 0.02 [-0.73, 0.7] |
| 3:6 | 0 [-0.7, 0.72] |
| 4:5 | -0.01 [-0.72, 0.71] |
| 4:6 | -0.01 [-0.74, 0.69] |
| 5:6 | -0.01 [-0.8, 0.82] |
Above, we performed exploratory factor analysis on half of the data. That allowed us to identify factors as they emerged from the data. Now, we will check to confirm that these factors would fit the second half of the data.
path <- '
f1 =~ n_major_block + n_jumps + n_edges + n_sustained_reading
f2 =~ prop_edits_before_sentence + prop_edits_before_word + prop_edits_within_word + len_prodseq
f3 =~ prop_lookbacks_before_sentence + prop_lookbacks_before_word + prop_lookbacks_within_word + len_nonlookbacks
f4 =~ prob_long_lookback_duration + short_event_duration_before_sentence + short_event_duration_before_word + short_event_duration_within_word
'
# fit the model and output the results
cfamodel <- blavaan(path, data=df.cfa, auto.var=TRUE, auto.fix.first=TRUE, auto.cov.lv.x=TRUE)
##
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 0.001332 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 13.32 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 1500 [ 0%] (Warmup)
## Chain 1: Iteration: 150 / 1500 [ 10%] (Warmup)
## Chain 1: Iteration: 300 / 1500 [ 20%] (Warmup)
## Chain 1: Iteration: 450 / 1500 [ 30%] (Warmup)
## Chain 1: Iteration: 501 / 1500 [ 33%] (Sampling)
## Chain 1: Iteration: 650 / 1500 [ 43%] (Sampling)
## Chain 1: Iteration: 800 / 1500 [ 53%] (Sampling)
## Chain 1: Iteration: 950 / 1500 [ 63%] (Sampling)
## Chain 1: Iteration: 1100 / 1500 [ 73%] (Sampling)
## Chain 1: Iteration: 1250 / 1500 [ 83%] (Sampling)
## Chain 1: Iteration: 1400 / 1500 [ 93%] (Sampling)
## Chain 1: Iteration: 1500 / 1500 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 53.724 seconds (Warm-up)
## Chain 1: 96.7796 seconds (Sampling)
## Chain 1: 150.504 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 0.000593 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 5.93 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 1500 [ 0%] (Warmup)
## Chain 2: Iteration: 150 / 1500 [ 10%] (Warmup)
## Chain 2: Iteration: 300 / 1500 [ 20%] (Warmup)
## Chain 2: Iteration: 450 / 1500 [ 30%] (Warmup)
## Chain 2: Iteration: 501 / 1500 [ 33%] (Sampling)
## Chain 2: Iteration: 650 / 1500 [ 43%] (Sampling)
## Chain 2: Iteration: 800 / 1500 [ 53%] (Sampling)
## Chain 2: Iteration: 950 / 1500 [ 63%] (Sampling)
## Chain 2: Iteration: 1100 / 1500 [ 73%] (Sampling)
## Chain 2: Iteration: 1250 / 1500 [ 83%] (Sampling)
## Chain 2: Iteration: 1400 / 1500 [ 93%] (Sampling)
## Chain 2: Iteration: 1500 / 1500 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 41.1072 seconds (Warm-up)
## Chain 2: 78.9646 seconds (Sampling)
## Chain 2: 120.072 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 0.001119 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 11.19 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 1500 [ 0%] (Warmup)
## Chain 3: Iteration: 150 / 1500 [ 10%] (Warmup)
## Chain 3: Iteration: 300 / 1500 [ 20%] (Warmup)
## Chain 3: Iteration: 450 / 1500 [ 30%] (Warmup)
## Chain 3: Iteration: 501 / 1500 [ 33%] (Sampling)
## Chain 3: Iteration: 650 / 1500 [ 43%] (Sampling)
## Chain 3: Iteration: 800 / 1500 [ 53%] (Sampling)
## Chain 3: Iteration: 950 / 1500 [ 63%] (Sampling)
## Chain 3: Iteration: 1100 / 1500 [ 73%] (Sampling)
## Chain 3: Iteration: 1250 / 1500 [ 83%] (Sampling)
## Chain 3: Iteration: 1400 / 1500 [ 93%] (Sampling)
## Chain 3: Iteration: 1500 / 1500 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 39.6377 seconds (Warm-up)
## Chain 3: 45.913 seconds (Sampling)
## Chain 3: 85.5508 seconds (Total)
## Chain 3:
## Computing posterior predictives...
summary(cfamodel, fit.measures=TRUE)
## ** WARNING ** blavaan (0.4-3) did NOT converge after 500 adapt+burnin iterations
## ** WARNING ** Proceed with caution
##
## Number of observations 45
##
## Number of missing patterns 1
##
## Statistic MargLogLik PPP
## Value -936.178 0.000
##
## Latent Variables:
## Estimate Post.SD pi.lower pi.upper Rhat Prior
## f1 =~
## n_major_block 1.000
## n_jumps 2.601 1.333 1.428 6.166 1.014 normal(0,10)
## n_edges 2.646 1.343 1.449 6.419 1.013 normal(0,10)
## n_sustand_rdng 1.759 0.992 0.732 4.453 1.012 normal(0,10)
## f2 =~
## prp_dts_bfr_sn 1.000
## prp_dts_bfr_wr 4.972 2.725 1.993 12.359 1.005 normal(0,10)
## prp_dts_wthn_w 5.441 2.990 2.181 13.557 1.005 normal(0,10)
## len_prodseq -4.009 2.248 -10.185 -1.525 1.005 normal(0,10)
## f3 =~
## prp_lkbcks_bf_ 1.000
## prp_lkbcks_bf_ -3.228 6.710 -17.988 1.643 3.426 normal(0,10)
## prp_lkbcks_wt_ -3.256 6.759 -18.079 1.637 3.475 normal(0,10)
## len_nonlokbcks 3.596 7.436 -1.760 19.883 3.497 normal(0,10)
## f4 =~
## prb_lng_lkbck_ 1.000
## shrt_vnt_drt__ 0.951 2.571 -3.896 6.588 1.000 normal(0,10)
## shrt_vnt_drt__ 8.051 3.967 2.250 17.169 1.001 normal(0,10)
## shrt_vnt_drt__ 10.051 4.794 2.902 21.091 1.002 normal(0,10)
##
## Covariances:
## Estimate Post.SD pi.lower pi.upper Rhat Prior
## f1 ~~
## f2 0.052 0.037 0.007 0.147 1.001 lkj_corr(1)
## f3 0.053 0.072 -0.029 0.224 1.320 lkj_corr(1)
## f4 -0.001 0.009 -0.019 0.017 1.000 lkj_corr(1)
## f2 ~~
## f3 0.041 0.052 -0.018 0.174 1.394 lkj_corr(1)
## f4 -0.011 0.010 -0.037 -0.002 1.000 lkj_corr(1)
## f3 ~~
## f4 0.003 0.014 -0.023 0.035 1.014 lkj_corr(1)
##
## Intercepts:
## Estimate Post.SD pi.lower pi.upper Rhat Prior
## .n_major_block 0.000
## .n_jumps 0.000
## .n_edges 0.000
## .n_sustand_rdng 0.000
## .prp_dts_bfr_sn 0.000
## .prp_dts_bfr_wr 0.000
## .prp_dts_wthn_w 0.000
## .len_prodseq 0.000
## .prp_lkbcks_bf_ 0.000
## .prp_lkbcks_bf_ 0.000
## .prp_lkbcks_wt_ 0.000
## .len_nonlokbcks 0.000
## .prb_lng_lkbck_ 0.000
## .shrt_vnt_drt__ 0.000
## .shrt_vnt_drt__ 0.000
## .shrt_vnt_drt__ 0.000
## f1 0.000
## f2 0.000
## f3 0.000
## f4 0.000
##
## Variances:
## Estimate Post.SD pi.lower pi.upper Rhat Prior
## .n_major_block 0.595 0.137 0.377 0.918 1.003 gamma(1,.5)[sd]
## .n_jumps 0.024 0.026 0.000 0.092 1.004 gamma(1,.5)[sd]
## .n_edges 0.083 0.033 0.013 0.148 1.001 gamma(1,.5)[sd]
## .n_sustand_rdng 0.953 0.215 0.620 1.439 1.000 gamma(1,.5)[sd]
## .prp_dts_bfr_sn 0.673 0.154 0.438 1.026 1.000 gamma(1,.5)[sd]
## .prp_dts_bfr_wr 0.116 0.034 0.054 0.192 1.000 gamma(1,.5)[sd]
## .prp_dts_wthn_w 0.022 0.026 0.000 0.094 1.000 gamma(1,.5)[sd]
## .len_prodseq 0.400 0.092 0.257 0.620 0.999 gamma(1,.5)[sd]
## .prp_lkbcks_bf_ 0.679 0.471 0.251 1.726 2.759 gamma(1,.5)[sd]
## .prp_lkbcks_bf_ 0.243 0.054 0.157 0.367 1.000 gamma(1,.5)[sd]
## .prp_lkbcks_wt_ 0.216 0.050 0.138 0.337 1.000 gamma(1,.5)[sd]
## .len_nonlokbcks 0.006 0.008 0.000 0.031 1.002 gamma(1,.5)[sd]
## .prb_lng_lkbck_ 1.132 0.244 0.740 1.703 0.999 gamma(1,.5)[sd]
## .shrt_vnt_drt__ 0.980 0.219 0.645 1.510 0.999 gamma(1,.5)[sd]
## .shrt_vnt_drt__ 0.425 0.158 0.100 0.750 1.002 gamma(1,.5)[sd]
## .shrt_vnt_drt__ 0.223 0.168 0.002 0.592 1.003 gamma(1,.5)[sd]
## f1 0.237 0.144 0.026 0.583 1.002 gamma(1,.5)[sd]
## f2 0.084 0.076 0.007 0.285 1.000 gamma(1,.5)[sd]
## f3 0.497 0.397 0.003 1.245 2.168 gamma(1,.5)[sd]
## f4 0.012 0.017 0.001 0.061 1.000 gamma(1,.5)[sd]
coef(cfamodel)
## f1=~n_jumps
## 2.601
## f1=~n_edges
## 2.646
## f1=~n_sustained_reading
## 1.759
## f2=~prop_edits_before_word
## 4.972
## f2=~prop_edits_within_word
## 5.441
## f2=~len_prodseq
## -4.009
## f3=~prop_lookbacks_before_word
## -3.228
## f3=~prop_lookbacks_within_word
## -3.256
## f3=~len_nonlookbacks
## 3.596
## f4=~short_event_duration_before_sentence
## 0.951
## f4=~short_event_duration_before_word
## 8.051
## f4=~short_event_duration_within_word
## 10.051
## n_major_block~~n_major_block
## 0.595
## n_jumps~~n_jumps
## 0.024
## n_edges~~n_edges
## 0.083
## n_sustained_reading~~n_sustained_reading
## 0.953
## prop_edits_before_sentence~~prop_edits_before_sentence
## 0.673
## prop_edits_before_word~~prop_edits_before_word
## 0.116
## prop_edits_within_word~~prop_edits_within_word
## 0.022
## len_prodseq~~len_prodseq
## 0.400
## prop_lookbacks_before_sentence~~prop_lookbacks_before_sentence
## 0.679
## prop_lookbacks_before_word~~prop_lookbacks_before_word
## 0.243
## prop_lookbacks_within_word~~prop_lookbacks_within_word
## 0.216
## len_nonlookbacks~~len_nonlookbacks
## 0.006
## prob_long_lookback_duration~~prob_long_lookback_duration
## 1.132
## short_event_duration_before_sentence~~short_event_duration_before_sentence
## 0.980
## short_event_duration_before_word~~short_event_duration_before_word
## 0.425
## short_event_duration_within_word~~short_event_duration_within_word
## 0.223
## f1~~f1
## 0.237
## f2~~f2
## 0.084
## f3~~f3
## 0.497
## f4~~f4
## 0.012
## f1~~f2
## 0.052
## f1~~f3
## 0.053
## f1~~f4
## -0.001
## f2~~f3
## 0.041
## f2~~f4
## -0.011
## f3~~f4
## 0.003