跳轉到內容

聯合分析與離散選擇任務

向標註者並排展示由屬性水平構成的方案,記錄每位標註者選中的方案,並保留設計資訊,供 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 即可啟動該研究。


延伸閱讀

有關實現細節,請參閱源文件。