楼主: Lisrelchen
3539 7

[程序分享] Choice-Based Conjoint Analysis using R [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2014-5-23 02:13:03 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
#> library ( AlgDesign )
#> ffd = gen.factorial ( c ( 2, 2, 4 ), varNames = c ( 'HAC', 'ECO', 'PRI' ), factors = 'all' )
#> set.seed(54321)
#> des = optFederov ( ~., ffd, 8 )
#> alt1 = des$design
#> alt2 = alt1
#> alt1 = transform ( alt1, r1 = runif ( 8 ) )
#> alt2 = transform ( alt2, r2 = runif ( 8 ) )
#> alt1.sort = alt1 [ order ( alt1$r1 ), ]
#> alt2.sort = alt2 [ order ( alt2$r2 ), ]
#> library ( survival )
#> source ('MktRoll.R')
#> results = MktRoll ( 10, 8, 3, data, labs[,1:3] )
#> clogout1 = clogit ( RES~ASC+HAC+ECO+PRI+strata(STR), data=results )
#> clogout2 = clogit ( RES~ASC+HAC+ECO+PRI+PRI:FEM+strata(STR), data=results )

labels = matrix ( c (
  "No" , "No" , "145 yen" , "Yes" ,"No"  ,"160 yen",
  "Yes", "No" , "155 yen" , "Yes" ,"Yes" ,"145 yen",
  "Yes", "Yes", "150 yen" , "No"  ,"Yes" ,"160 yen",
  "No" , "No" , "150 yen" , "No"  ,"No"  ,"145 yen",
  "No" , "Yes", "155 yen" , "Yes" ,"Yes" ,"150 yen",
  "Yes", "Yes", "145 yen" , "Yes" ,"No"  ,"155 yen",
  "No" , "Yes", "160 yen" , "No"  ,"Yes" ,"155 yen",
  "Yes", "No" , "160 yen" , "No"  ,"No"  ,"150 yen"),
  ncol = 6, byrow=T )

labs = matrix ( c (
  0, 0, 145, 1, 0, 160,
  1, 0, 155, 1, 1, 145,
  1, 1, 150, 0, 1, 160,
  0, 0, 150, 0, 0, 145,
  0, 1, 155, 1, 1, 150,
  1, 1, 145, 1, 0, 155,
  0, 1, 160, 0, 1, 155,
  1, 0, 160, 0, 0, 150),
  ncol = 6, byrow = T )
colnames ( labs ) = c ( rep ( c( 'HAC', 'ECO', 'PRI'), 2 ) )

data = matrix ( c (
  3,   2,    2,    1,    3,    3,    1,    3,  1,
  3,   2,    1,    3,    2,    1,    3,    1,  0,
  1,   2,    3,    1,    1,    1,    2,    1,  1,
  3,   3,    3,    1,    2,    1,    3,    3,  0,
  3,   2,    1,    1,    3,    1,    3,    3,  1,
  1,   3,    3,    3,    3,    1,    3,    3,  0,
  3,   3,    3,    1,    2,    1,    3,    3,  1,
  2,   2,    3,    2,    2,    3,    3,    1,  0,
  3,   2,    2,    2,    2,    1,    3,    2,  1,
  3,   1,    3,    3,    2,    2,    3,    3,  0),
  ncol = 9, byrow = T )

n   = nrow ( data )
q   = nrow ( labs )
a   = 3
key = labs

MktRoll = function ( n, q, a, data, key )
  {
    # n    = number of respondents
    # q    = number of questions (choice sets)
    # a    = size of choice set
    # data = responses: n x q
    # key  = ???

    debug = FALSE
    z = n * q * a
    c = 1 + 2 + dim ( key )[2] + 1
    r = matrix ( rep ( 0, z * c ), ncol = c, byrow = T )
    if ( debug )
      {
        print ( paste ( 'Result is a ', nrow(r), 'by', ncol(r), 'matrix' ) )
      }
    cnames = c ( 'STR', 'RES', 'ASC', colnames ( key ), 'FEM' )
    colnames ( r ) = cnames

    l = 1
    for ( i in 1 : n ) # for each respondent
      {
        for ( j in 1 : q ) # for each question
          {
            for ( k in 1 : a ) # for each alternative
              {
                r [ l, 1 ] = 100 * i + j  # Stratification variable
                if ( data [ i, j ] == k ) { r [ l, 2] = 1 } # RES (result, i.e. chosen alternative)
                if ( k == 1 )
                  {
                    r [ l, 3] = 1 # ASC (alternative-specific constant)
                    r [ l, 4:6 ] = labs [ j, 1:3 ] # values of factors for this alternative
                  }
                if ( k == 2 )
                  {
                    r [ l, 3] = 1 # ASC (alternative-specific constant)
                    r [ l, 4:6 ] = labs [ j, 4:6 ]
                  }
                dem = data [ i, q + 1 ]
                if ( debug )
                  {
                    print ( paste ("inserting", dem, "for respondent", i, "in row", l ) )
                  }
                r [ l, 7 ] =  dem # Demographic variable
                l = l + 1
              }
          }
      }
    return ( data.frame ( r ) )
  }


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Conjoint Analysis Analysi Choice alysis survival library factors design source

已有 1 人评分经验 收起 理由
ltx5151 + 20 根据规定进行奖励

总评分: 经验 + 20   查看全部评分

本帖被以下文库推荐

沙发
commercial 发表于 2014-7-14 21:39:52
very interesting

藤椅
Nicolle 学生认证  发表于 2014-7-14 22:00:40
提示: 作者被禁止或删除 内容自动屏蔽

板凳
lemontang 发表于 2014-9-10 01:58:17

报纸
edhe3 发表于 2014-10-13 09:50:36
赞。。。

地板
ilh73 发表于 2014-10-13 09:52:36
很好的帖子

7
xiexie1111 发表于 2015-3-25 00:01:18
thanks for your sharing, do you have the software of sawtooth for choice-based conjoint analysis?

8
jgchen1966 发表于 2015-3-25 17:28:05
what to do !!!!!!!!!!!!!!?????????????????????????????????

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-8 05:46