Data analysis mlogit code


#1

Hi Everyone,

I have been using r studio to analyse my data and I encounter this problem. what do you think of it?
Below shows the whole codes I used to run it went very well till the last code. the error says

Error in solve.default(H, g[!fixed]) : 
Lapack routine dgesv: system is exactly singular: U[6,6] = 0. 

and I don't know what does it mean? So could you please help me on this?

dce_data<-read.spss("Data.sav", 
                    use.value.labels = TRUE, to.data.frame = TRUE,
                    max.value.labels = Inf, trim.factor.names = FALSE,
                    trim_values = TRUE, reencode = NA)

head(dce_data)

dce_choice <- read.spss("choices.sav",
                        use.value.labels = TRUE, to.data.frame = TRUE,
                        max.value.labels = Inf, trim.factor.names = FALSE,
                        trim_values = TRUE, reencode = NA)


DCE_long <- reshape(dce_data,
                        varying = list(rep(names(dce_data)[6:23],
                                           times=1)),
                        v.names = c("choice"),
                        timevar = "idCard",
                        times = 1:(nrow(dce_choice)),
                        new.row.names = 1:(nrow(dce_data)*nrow(dce_choice)),
                        direction = "long")

head(DCE_long)


DCE_long <- DCE_long[order(DCE_long$id),]

head(DCE_long)


DCE_final<-merge(DCE_long,dce_choice,by.x="idCard",by.y="choiceset")
head(DCE_final)

DCE_final<-DCE_final[order(DCE_final$id),]

head(DCE_final)

DCE_final<-DCE_final[,-c(3:6)]
head(DCE_final)

#prepare use mlogit 

#-----------------------------------Data Handling

DCE<- mlogit.data(DCE_final, choice = "choice", shape = "wide",
                      varying = 4:13, alt.levels = c("scen1", "scen2"), sep = "")
head(DCE)

#estimate 

fit_dce <- mlogit(choice ~ A + B + C + D + E | -1, data= DCE)
fit_dce
summary(fit_dce)

## check if a variable is a factor variable (=categorical)

is.factor(DCE$A)
is.factor(DCE$B)
is.factor(DCE$C)
is.factor(DCE$D)
is.factor(DCE$E)


##be sure that the first three are continuous and the last two are categoricals
DCE$A<-as.numeric(DCE$A)
DCE$B<-as.numeric(DCE$B)
DCE$C<-as.numeric(DCE$C)
DCE$D<-as.factor(DCE$D)
DCE$D<-as.factor(DCE$E)


options(contrasts = c("contr.sum", "contr.poly"))
getOption("contrasts")


#Dummy coding
my_contrasts <- matrix(c(1,0,0,0,1,0),ncol=2)
my_contrasts
#?matrix

contrasts(DCE$D) = my_contrasts
contrasts(DCE$E) = my_contrasts

# fit your model where A, B, C,D and E are dummy coded. 

fit_dce_dum<-mlogit(choice ~ A + B + C + D + E | -1, data= DCE) 
summary(fit_dce_dum)

now it said

error stating Error in solve.default(H, g[!fixed]) :
Lapack routine dgesv: system is exactly singular: U[6,6] = 0