Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

r - Error in mlogit: Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.4767e-18

I have a conjoint survey data in long format. the first few rows look like this:

 ID alt choice size tar length brand flavor gender age yr_smoke num_smoke job
 1  1   1     no    1   1      1     1      1      2  35       10        20   1
 2  1   2     no    1   1      1     1      1      2  35       10        20   1
 3  1   3     no    1   1      1     1      1      2  35       10        20   1
 4  1   4     no    1   1      1     1      1      2  35       10        20   1
 5  1   5     no    1   1      1     1      1      2  35       10        20   1
 6  1   6     no    1   1      1     1      1      2  35       10        20   1

I used mlogit.data as:

data_mlogit_ct1_test2 <- mlogit.data(data_mlogit_ct1_test1,choice="choice",
shape="long",alt.var="alt")

The first few rows of the transformed data looks like:

   ID alt choice size tar length brand flavor gender age yr_smoke num_smoke job
   1.1  1   1  FALSE    1   1      1     1      1      2  35       10        20   1
   1.2  1   2  FALSE    1   1      1     1      1      2  35       10        20   1
   1.3  1   3  FALSE    1   1      1     1      1      2  35       10        20   1
   1.4  1   4  FALSE    1   1      1     1      1      2  35       10        20   1
   1.5  1   5  FALSE    1   1      1     1      1      2  35       10        20   1
   1.6  1   6  FALSE    1   1      1     1      1      2  35       10        20   1

Now I am trying to fit mlogit as:

 fit_mlogit_ct11 <- mlogit(choice~size+tar+length+brand+flavor, 
                           data_mlogit_ct1_test1,shape="long",chid.var="ID",
                           alt.var="alt",method="bfgs",heterosc=TRUE,tol=10)

I got this error:

Error in solve.default(crossprod(attr(x, "gradi")[, !fixed])) : Lapack routine dgesv: system is exactly singular

Then I did:

  fit_mlogit_ct11 <- mlogit(choice~size+tar+length+brand+flavor, data_mlogit_ct1_test2)

Now I got:

Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.4767e-18

Can somebody please help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think the problem is because you did not define right your individual specific variables. According to the package manual, when you build your models with mlogit function you can use : | to separate the alternative specific with individual specific variables. For example:

fit_mlogit_ct11 <- mlogit(choice~1|size+tar+length+brand+flavor, 
                           data_mlogit_ct1_test1,shape="long",chid.var="ID",
                           alt.var="alt",method="bfgs",heterosc=TRUE,tol=10)

Which simply says that all your variables are individual specific and your take only the intercept for the alternative specific. But indeed as it has already mentioned above your data look odd since they look the same, since you have only individual specific variables. This leads eventually to singularity (your variables correlate with each other with 1).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...