跳转到内容

联合分析与离散选择任务

向标注者并排展示由属性水平构成的方案,记录每位标注者选中的方案,并保留设计信息,供 R 或 Python 中的选择模型使用。

conjoint 方案向标注者并排展示两个或更多方案(profile),并记录标注者会选择的那一个。联合分析(conjoint analysis)是一种调查技术,它用一组属性(例如薪资或通勤时间)来描述每个选项,再从大量选择中估计每个属性水平对选择的影响有多大。基于选择的联合分析,也叫离散选择实验,要求从每组方案中选出一个,而不是给每个方案打分。Potato 负责抽取并展示方案,并把选择结果与当时展示的方案一起记录下来。选择模型则在事后用 R 或 Python 拟合。

何时使用联合分析

联合分析回答的是权衡取舍的问题,例如求职者为了远程办公愿意放弃多少薪资。这个方案适合政策与市场研究、针对 AI 助手等产品配置的偏好研究,以及任何选项在多个属性上同时存在差异的研究。如果两个选项是数据中的完整条目(例如两条模型回复),成对比较更合适。最优-最差量表则对一批条目排序,不用属性来描述条目。

配置

由属性构成的方案,列出每个属性及其水平:

yaml
annotation_schemes:
  - annotation_type: conjoint
    name: job_choice
    description: "Which job offer would you accept?"
    profiles_per_set: 2
    attributes:
      - name: Salary
        levels: ["$55,000", "$65,000", "$75,000"]
      - name: Remote work
        levels: ["None", "Two days a week", "Fully remote"]
      - name: Commute
        levels: ["15 minutes", "45 minutes"]
      - name: Contract
        levels: ["Permanent", "One-year renewable"]
    show_none_option: true

这个例子每组使用两个方案,因为两张卡片比较起来更快。默认值是三个。

选项类型默认值说明
profiles_per_setinteger3每个选择集中展示的方案数。小于 2 的值会被校验拒绝。
attributeslist无属性列表,每个属性包含 name 和 levels 列表。除非设置了 profiles_field,否则必填。
show_none_optionbooleantrue在卡片下方加入"以上都不选"("None of these")选项。
profiles_fieldstring无存放现成方案的条目字段。设置后,Potato 展示条目自带的方案,而不再自行抽取。

除了 name、description 和上面四个选项,方案还接受所有方案共有的键,其中 conjoint 生成器会读取 label_requirement 和 layout。既没有 attributes 也没有 profiles_field 的 conjoint 方案,会在服务器启动时校验失败。每张卡片的标题是"Option 1"、"Option 2",依此类推,卡片的属性水平表格下方有一个标为"Choose this"的单选按钮。条目自己的文本照常显示在方案上方,因此数据文件可以带上每次选择所处的情境。

按标注者和条目随机抽取方案

对于由 attributes 构成的方案,服务器逐个属性随机抽取一个水平来构造每个方案,各水平概率相等,各属性相互独立。抽取的随机种子由标注者、条目和方案名称共同决定。因此每位标注者在每个条目上看到的设计各不相同,而刷新页面后看到的卡片保持不变。只要属性的组合数足够多,Potato 会让同一组中的方案互不相同。

服务器会保存标注者在某个条目上第一次看到的设计,此后每次访问都显示已保存的设计。在研究进行中修改水平,不会改变某位标注者已经看过的条目的卡片。Potato 没有排除不合理水平组合的设置,也不能在整个研究范围内平衡各水平。在别处构建的设计(例如高效设计或分区组设计),通过 profiles_field 放进数据里。

卡片不需要 randomize_order,因为方案本身就是随机抽取的。Potato 会忽略 conjoint 方案上的 randomize_order,并记录一条警告。在 Potato 2.13.1 之前,浏览器根据条目 ID 的长度和属性名称来选取每个水平,ID 长度相同的条目会显示相同的方案,因此用旧版本收集的 conjoint 研究,没有留下每位标注者所见方案的记录。

来自你的数据的方案

使用 profiles_field 时,每个条目自带一个方案列表,Potato 按数据中的顺序、原样把这个列表展示给每位标注者。当设计来自其他工具,或者方案是真实存在的选项而不是水平的组合时,使用 profiles_field。方案中指定字段的名称:

yaml
annotation_schemes:
  - annotation_type: conjoint
    name: platform
    description: "Which platform would you rather use?"
    profiles_field: profiles
    profiles_per_set: 3

每个条目随后在该字段下带有一个方案列表:

json
{"id": "task_01", "text": "Your lab needs somewhere to run an annotation study.", "profiles": [
  {"Hosting": "Self-hosted", "Cost": "Free"},
  {"Hosting": "Cloud", "Cost": "$20/mo"},
  {"Hosting": "Hybrid", "Cost": "$8/mo"}
]}

没有 attributes 块时,Potato 根据各方案用到的键来构造每张卡片的行。每张卡片都有该集合中每个键对应的行,缺少某个键的方案会在该行显示破折号(—),因此各卡片的行保持对齐。在 profiles_field 旁边声明 attributes,则卡片只显示你指定的属性,并按你给出的顺序排列。

每个条目有多少个方案由数据决定。方案数少于 profiles_per_set 的条目,每个方案显示一张卡片。方案数更多的条目,显示前 profiles_per_set 个方案,并告知标注者,例如"Showing 3 of 5 options for this item."。请把 profiles_per_set 设为数据中最大的集合大小。对于 profiles_field 方案,Potato 不记录设计,因为数据文件本身已经包含设计。

"以上都不选"选项

"以上都不选"("None of these")位于卡片下方,默认开启。选择它时,存储的是 "none",而不是卡片编号。若要做强制选择设计,让每位标注者必须从方案中选一个,请设置 show_none_option: false。

存储的答案与展示的方案

答案是所选卡片的编号(字符串,从 "1" 起),或者 "none"。在导出记录中,答案位于方案名称之下,出现两次,一次对应方案,一次对应方案的单个值:

json
"labels": {"job_choice": {"job_choice": "2"}}

对于由 attributes 构成的方案,标注者看到的方案保存在 <output_annotation_dir>/<annotator>/user_state.json 中的 instance_id_to_presentation_order 下,先按条目、再按方案名称索引,并按卡片顺序排列:

json
"instance_id_to_presentation_order": {
  "job_01": {
    "job_choice": [
      {"Salary": "$65,000", "Remote work": "None", "Commute": "15 minutes", "Contract": "Permanent"},
      {"Salary": "$55,000", "Remote work": "Fully remote", "Commute": "45 minutes", "Contract": "One-year renewable"}
    ]
  }
}

卡片 "2" 是列表中的第二个方案。export_annotation_format 写出的记录只含选择,不含方案,设计请从 user_state.json 读取。

Potato 的一致性报告把 conjoint 的答案视为一个名义型选择。当方案由 attributes 抽取时,两位标注者在同一条目上选的"卡片 2"通常是两个不同的方案。因此卡片编号一致并不意味着偏好一致,比较标注者更适合通过拟合后的模型进行。

估计属性重要性

估计在 Potato 之外用 R 或 Python 完成。Potato 2.14.0 不计算部分效用值(part-worth)、平均边际成分效应(AMCE)或属性重要性。部分效用值是选择模型赋予某个属性某个水平的效用。AMCE 是当某个属性从参照水平变为另一个水平时,选中某个方案的概率的平均变化量。

部分效用值和 AMCE 的估计方法都从一张长表开始,表中每展示一个方案占一行。下面的脚本从所有标注者的 user_state.json 构建这张表,选中的卡片 chosen 为 1,其余为 0:

python
import csv
import glob
import json
 
SCHEME = "job_choice"
rows = []
for path in glob.glob("annotation_output/*/user_state.json"):
    with open(path) as f:
        state = json.load(f)
    shown = state.get("instance_id_to_presentation_order", {})
    for item_id, labels in state.get("instance_id_to_label_to_value", {}).items():
        choice = next((value for label, value in labels if label.get("schema") == SCHEME), None)
        profiles = shown.get(item_id, {}).get(SCHEME)
        if choice is None or not profiles:
            continue
        for card, profile in enumerate(profiles, start=1):
            rows.append({"annotator": state["user_id"], "item": item_id, "card": card,
                         "chosen": int(choice == str(card)), **profile})
 
with open("conjoint_long.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=list(rows[0]))
    writer.writeheader()
    writer.writerows(rows)

回答"以上都不选"时,该集合中每张卡片的 chosen 都是 0。可以丢弃这些集合,或者在估计方法支持时,把放弃选择建模为一个单独的备选项。在 R 中,cjoint 包可以用这种形状的表估计 AMCE,以 chosen 为结果变量,以 annotator 为受访者 ID。在 Python 中,statsmodels 的 ConditionalLogit 可以在哑变量编码的水平上拟合条件 logit 模型,每个标注者与条目的组合作为一组。

完整示例

下面的配置运行每次选择两个方案的求职研究:

yaml
annotation_task_name: "Job Offer Conjoint"
task_dir: "."
 
data_files:
  - "data/job_tasks.jsonl"
 
item_properties:
  id_key: id
  text_key: text
 
annotation_schemes:
  - annotation_type: conjoint
    name: job_choice
    description: "Which job offer would you accept?"
    profiles_per_set: 2
    attributes:
      - name: Salary
        levels: ["$55,000", "$65,000", "$75,000"]
      - name: Remote work
        levels: ["None", "Two days a week", "Fully remote"]
      - name: Commute
        levels: ["15 minutes", "45 minutes"]
      - name: Contract
        levels: ["Permanent", "One-year renewable"]
    show_none_option: true
 
output_annotation_dir: "annotation_output/"
export_annotation_format: jsonl
 
user_config:
  allow_all_users: true

数据文件的每一行是一个选择任务,文本为选择提供情境:

json
{"id": "job_01", "text": "You are offered two jobs in your field. Which would you accept?"}
{"id": "job_02", "text": "Both offers below are for the same role at different companies. Which would you accept?"}
{"id": "job_03", "text": "You are moving cities and have two offers. Which would you accept?"}

启动服务器:

bash
potato start config.yaml -p 8000

Potato 的代码仓库还带有第二个示例,位于 examples/classification/conjoint/,是一项每组三个方案的 AI 助手偏好研究。在仓库的检出目录中,运行 potato start examples/classification/conjoint/config.yaml -p 8000 即可启动该研究。


延伸阅读

有关实现细节,请参阅源文档。