Panelgvar - How to create design matrix out of dataframe
Closed this issue · 4 comments
Dear,
I have panel data of 3 waves, 20 variables and 1911 cases. And I have restructured my data from long to wide such that it is like this:
Var1.2021 Var1.2022 Var1.2023 Var2.2021 Var2.2022 Var2.2023 Var3.2021 Var3.2022 Var3.2023 Var4.2021 Var4.2022 ...
1.
2.
3.
....
However, I am unable to create the matrix in the format below (which I believe I should do to enter it in the function panelgvar):
2021 2022 2023
V1
V2
....
I keep getting:
[,1]
[1,] Var1.2021
[2,] Var1.2022
[3,] Var1.2023
....
I went through the codes provided on this website, however I am still unable to fix it after many struggles :( Can you help, please? :(
Thank you in advance!
Does this work?
outer(1:20,2021:2023,function(i,j){
paste0("Var",i,".",j)
})
See also https://osf.io/dax8g/ for updated materials and code examples.
Thank you very much! This one worked! Now I have the matrix :) Thank you also for the updated materials and code examples :)
I followed these steps: https://osf.io/837jp
However, when I ran the model, I received such a message:
Warning messages:
1: In addSEs_cpp(x, verbose = verbose, approximate_SEs = approximate_SEs) :
Standard errors could not be obtained because the Fischer information matrix could not be inverted. This may be a symptom of a non-identified model or due to convergence issues. You can try to approximate standard errors by setting approximate_SEs = TRUE at own risk.
2: In runmodel(.) :
Model might not have converged properly: mean(abs(gradient)) > 1.
When I plotted the networks, they turned out like that: please see attached.
I tried to enter the argument "approximate_SEs = TRUE" into the code: mod <- panelgvar(df_network, vars = design.matrix, estimator = "FIML") as suggested in the warning message, however, then it says "unused argument":
mod <- panelgvar(df_network, vars = design.matrix, estimator = "FIML", approximate_SEs = TRUE)
Error in dlvm1(data, vars, lambda = I, within_latent = within_latent, :
unused argument (approximate_SEs = TRUE)
See https://osf.io/qbez8 for tips on debugging! One thing that often works for panelgvar models is to set the between person effects to a cholesky decomposition. I can also recommend to just run the saturated model and to not use pruning / model selection.
Thank you very much! I will try these. Thanks again for your kind help.