Я пытаюсь выполнить скрытый анализ классов в R, но у меня есть некоторые переменные, которые являются как непрерывными, так и категориальными.Кроме того, у меня есть 52 состояния или строки, и я пытаюсь иметь 52 скрытых класса или подгруппы.Я начал писать код на R, но получаю ошибку.Вот ошибка: Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Вот мой код R
#Getting data into R
library(haven)
Component_3_database_11022018 <- 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<-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 <- 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 <- fit(model_definition)