Reputation: 1
My data frame filtered_gmmdf_long
(long format) has no NA
. It contains the variables ID
, time
(i.e. 0, 3, 8, 15, 25), and wblv
(continuous, approximately Normal distributed).
library(dplyr)
sample = as.data.frame(matrix(data = c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4, 0,3,8,15,25,0,3,8,15,25,0,3,8,15,25,0,3,8,15,25,
-0.0924870160,0.0274498752,0.2398900582,
0.1422529358,
0.1440320863,-0.0869990920,0.1423375351,
-0.239953000,-0.2378607918,0.1893095329,
0.0470979475,0.0681092844,0.0643890367,
-0.1299717236,0.0284062668,0.0249408593,
0.2341043359,0.0866213575,0.1003340839,
0.2721473565),ncol = 3))|>
mutate(ID = V1, time = V2, wblv = V3)|>
select(-starts_with("V"))
I am attempting to fit a simple growth model using lcmm()
from package {lcmm}
before conducting growth mixture models using the same function. I am able to fit models with hlme() fine but am unable to fit even the basic growth model with lcmm().
# gmm1b<-hlme(wblv~time,subject="ID",var.time="time",random=~1+time,
# ng=1,data=filtered_gmmdf_long)
###This works properly
# gmm2b<-gridsearch(rep=100,maxiter=10,minit=gmm1,
# hlme(wblv~time,subject="ID",random=~1+time,
# ng=2,data=filtered_gmmdf_long,mixture=~time))
###This also works properly
> lcmm1<-lcmm::lcmm(wblv~time,random=~time,subject="ID",
+ data=filtered_gmmdf_long,link='linear',ng=1)
resulting in the error
Numerical problem by computing fn value of function is : NaN
Originally I tried to do this with my entire dataset (n=3255) but I switched to complete responses only (n=873) after receiving this message. I also verified that all variables are identified as either numeric or categorical (with the exception of ID
).
Based on I_O's comment,I have also tried the following:
> lcmm1<-gridsearch(rep=100,maxiter=10,minit=gmm1b,
+ lcmm(wblv~time,random=~time,subject="ID",
+ data=filtered_gmmdf_long,link='linear',ng=1))
Error in lcmm(wblv ~ time, random = ~time, subject = "ID", data = filtered_gmmdf_long, : The model specified in B should be of class lcmm
> lcmm1<-gridsearch(rep=100,maxiter=10,minit=as.vector(coef(gmm1b)),
+ lcmm(wblv~time,random=~time,subject="ID",
+ data=filtered_gmmdf_long,link='linear',ng=1))
Error in minit$conv : $ operator is invalid for atomic vectors
> lcmm1<-lcmm(wblv~time,random=~time,subject="ID",
+ data=filtered_gmmdf_long,B=as.vector(coef(gmm1b)),
+ link='linear',ng=1)
Error in chol.default(varcov) : the leading minor of order 2 is not positive definite
I also tried rescaling wblv such that there were no negative values. Using wblv_rescale, I was able to run the standard growth model, but received an error when attempting to run a 2-class growth mixture model.
lcmm1<-lcmm(wblv_rescale~time,random=~time,subject="ID",
data=filtered_gmmdf_long,
link='linear',ng=1)
summary(lcmm1)
###This works properly with wblv_rescale but not wblv
> lcmm2<-lcmm(wblv_rescale~time,subject="ID",random=~time,mixture=~time,
+ data=filtered_gmmdf_long,
+ link='linear',ng=2)
Error in .Contlcmm(fixed = fixed, mixture = mixture, random = random, : Please specify initial values with argument 'B'
Upvotes: 0
Views: 304