I am trying to follow this example for Latent class analysis here:
https://www.rpubs.com/hlennon/LCTMtoolsvignette
But stucked when performing residual plot and got error message:
Error in dplyr::left_join()
:
! ...
must be empty.
Problematic argument:
ā¢ .by = nameofid
The code is pasted below, can anyone help fix the problem? Thank you.
# installing LCTMtools
install.packages("remotes")
remotes::install_github("hlennon/LCTMtools")
library( LCTMtools )
library(ggplot2)
data(bmi_long, package = "LCTMtools" )
# spaghetti plot
p <- ggplot(data = bmi_long, aes(x = age, y = bmi, group = id))
p + geom_line()
ggplot(bmi_long, aes(x = age, y= bmi)) + geom_line(aes(color = true_class, group = id)) +
xlab("Age") + ylab("BMI") + labs(color = "Class Assignment")
m1<- hlme(fixed=bmi ~ 1+age+I(age^2), random=~ 1, subject='id', data=data.frame(bmi_long))
# Step 1: Select the form of the random effect structure
library( lcmm )
# To fit a latent class modelel with no random effects, the lcmm R package this can be used with the
# specification of random=~-1 .
m1<- hlme(fixed=bmi ~ 1+age+I(age^2), random=~ -1, subject='id', idiag = FALSE, data=data.frame(bmi_long))
model1 <- lcmm::hlme(fixed=bmi~1+age+I(age^2),
mixture = ~1+age+I(age^2),
random=~ -1,
subject="id", idiag = FALSE,
ng=5,
nwg=FALSE,
data=data.frame(bmi_long),
B=m1
)
residualplot_step1( model1,
nameofoutcome="bmi", nameofage = "age",
data = data.frame(bmi_long),
ylimit=c(-15,15))