title: Latent Class Analysis in R using a mix model
body: <p>I am trying to perform a latent class analysis in R but I have some variables that are both continuous and categorical. In addition I have 52 states or rows and I am trying to have 52 latent class or subgroups. I started to write the code in R but I am getting an error. Here is the error : <code>Error in contrasts&lt;-(*tmp*, value = contr.funs[1 + isOF[nn]]) : 
    contrasts can be applied only to factors with 2 or more levels</code></p>
  
  <p>Here is my R code</p>
  
  <pre><code>#Getting data into R
  library(haven)
  Component_3_database_11022018 &lt;- read_sav("C:/Users/gaurelien/WRMA/APS-TARC - Documents/Evaluation/Component 3 Research Study/Data Analysis/SPSS/Source/Component 3 database 11022018.sav")
  #Create a subset of the full data set reduced to 52 states
  LCA&lt;-subset(Component_3_database_11022018, State52==1)
  #Loading packages
  library(mclust)
  library(poLCA) # only categorical indicators
  library(scatterplot3d)
  library(MASS)
  library(orthopolynom)
  library(polynom)
  library(nlsem)
  library(nnet)
  library(Rsolnp)
  library(depmixS4)
  
  #Latent class Modeling with component 3 data
  # Construcution of the dependent Mixture Models
  #To avoid time-consuming mistakes in model specification, the analysis involves two steps: 
  #construction of a model with mix function and fitting it with fit function. family argument 
  #of mix function allows specifying a type of observed variables – whether they are continuous, nominal, 
  #or count by adding to a list corresponding distribution name, i.g. guassian or multinomial.
  model_definition &lt;- mix(list(AgencyLocation ~1, GeographicStructure ~1 , EligibilityCode ~1, 
    Maltreatment_Definitions_group ~ 1 ,ratio_report_per_investigator ~ 1,
    census_TotalPop ~ 1, percent_belowpovertylevel_12months ~1),
    family=list(multinomial(), #For every corresponding 
    multinomial(),  #  indicator a family of distribution 
    multinomial(),
    multinomial(),
    multinomial(),
    multinomial(),
    multinomial()), # should be indicated in the list.
    data= LCA,
    nstates=52,
    initdata =LCA)
    fit.mod &lt;- fit(model_definition)
  </code></pre>