メインコンテンツへスキップ

論文をAIに読み込ませて分析プログラムを作ってもらったらすごかった。

    以前から気になっていたことをやってみた。
    それは、論文をAIに読み込ませて、分析プログラムを「復元」できるか、である。以下の論文を使ってみた。


    画像
    https://pmc.ncbi.nlm.nih.gov/articles/PMC3798593/

    *論文の内容の解説はここでは行いません、興味があればAIに聞いてくださいw

    今回やってみたこと

    論文本文だけをAIに渡して、

    解析プログラムを復元できるか

    試しました。

    つまり、

    論文に書いてあることだけから逆算する

    という作業です。


    結果

    かなり高い精度で、

    以下が再構成されました。

    SAS版

    • PROC PHREG

    • quartile作成

    • person-years

    • hazard ratio

    • trend test

    /==========================================================
    Ohsaki Cohort: GGT and Cancer Incidence
    Reproduction template for J Epidemiol. 2012;22(2):144-150
    ==========================================================/

    /-------------------------
    0. Input dataset assumed:
    ohsaki_raw
    --------------------------/

    /*
    Assumed variables:
    id
    sex (1=male, 2=female)
    age continuous
    ggt continuous IU/L
    alcohol (0=never,1=former,2=current_light,3=current_heavy)
    liver_history (0/1)
    smoking (0=never,1=former,2=current)
    bmi continuous
    education (0=less than high school,1=high school or more)
    walking (0=<30 min/day,1=>=30 min/day)
    sports (0=<1 h/week,1=>=1 h/week)

    cancer_date
    death_date
    emigration_date
    nhi_loss_date
    cancer_icdo3 character, e.g. "C18.9"
    */

    /*-------------------------

    1. Prepare analysis dataset
      --------------------------*/
      data ohsaki;
      set ohsaki_raw;

    format follow_start end_admin event_date censor_date final_date yymmdd10.;
    follow_start = '01JAN1996'd;
    end_admin    = '31DEC2005'd;
    
    /* Earliest censoring date excluding cancer */
    censor_date = min(death_date, emigration_date, nhi_loss_date, end_admin);
    
    /* Final follow-up end date */
    if cancer_date ne . then final_date = min(cancer_date, censor_date);
    else final_date = censor_date;
    
    /* Person-time in years */
    py = (final_date - follow_start) / 365.25;
    
    /* Exclude invalid follow-up */
    if final_date <= follow_start then delete;
    
    /* GGT quartiles according to paper */
    length ggt_q 8;
    if ggt < 13 then ggt_q = 1;
    else if 13 <= ggt < 18 then ggt_q = 2;
    else if 18 <= ggt < 30 then ggt_q = 3;
    else if ggt >= 30 then ggt_q = 4;
    
    /* Trend variable */
    if ggt > 0 then log_ggt = log(ggt);
    
    /* BMI categories */
    if bmi < 18.5 then bmi_cat = 1;
    else if 18.5 <= bmi < 25 then bmi_cat = 2;
    else if bmi >= 25 then bmi_cat = 3;
    
    /* Event indicators: first cancer at selected site */
    all_cancer = (cancer_date ne . and cancer_date <= censor_date);
    
    /* ICD-O-3 topography code rules */
    liver_cancer = 0;
    non_liver_cancer = 0;
    esophageal = 0;
    stomach = 0;
    colorectal = 0;
    resp_intra = 0;
    pancreatic = 0;
    breast = 0;
    prostate = 0;
    urinary = 0;
    
    if all_cancer=1 then do;
        if substr(cancer_icdo3,1,3) in ("C22") then liver_cancer = 1;
        if substr(cancer_icdo3,1,3) in ("C15") then esophageal = 1;
        if substr(cancer_icdo3,1,3) in ("C16") then stomach = 1;
        if substr(cancer_icdo3,1,3) in ("C18","C19","C20") then colorectal = 1;
        if substr(cancer_icdo3,1,3) in ("C25") then pancreatic = 1;
        if substr(cancer_icdo3,1,3) in ("C50") then breast = 1;
        if substr(cancer_icdo3,1,3) in ("C61") then prostate = 1;
        if substr(cancer_icdo3,1,3) in ("C64","C65","C66","C67","C68") then urinary = 1;
    
        /* C33-C39.8 => use first 3 chars here as approximation */
        if substr(cancer_icdo3,1,3) in ("C33","C34","C37","C38","C39") then resp_intra = 1;
    
        if liver_cancer = 0 then non_liver_cancer = 1;
    end;
    
    /* 3-year exclusion flag for Model 3 */
    early3y_cancer = 0;
    if all_cancer=1 and (cancer_date < intnx('year', follow_start, 3, 'same')) then early3y_cancer = 1;
    
    label
      ggt_q = "GGT quartile"
      bmi_cat = "BMI category"
      all_cancer = "Any cancer"
      liver_cancer = "Liver cancer"
      non_liver_cancer = "Non-liver cancer";

    run;

    /-------------------------
    2. Formats
    --------------------------/
    proc format;
    value ggtqf 1='<13' 2='13.0-17.9' 3='18.0-29.9' 4='>=30.0';
    value sexf 1='Male' 2='Female';
    value alcof 0='Never' 1='Former' 2='Current <45.6g/d' 3='Current >=45.6g/d';
    value smokf 0='Never' 1='Former' 2='Current';
    value bmif 1='<18.5' 2='18.5-24.9' 3='>=25';
    run;

    /-------------------------
    3. Descriptive table (Table 1 style)
    --------------------------/
    proc means data=ohsaki mean std n;
    class ggt_q;
    var ggt age bmi;
    format ggt_q ggtqf.;
    run;

    proc freq data=ohsaki;
    tables ggt_q*(sex liver_history smoking alcohol walking sports education bmi_cat) / nocol norow;
    format ggt_q ggtqf. sex sexf. alcohol alcof. smoking smokf. bmi_cat bmif.;
    run;

    /-------------------------
    Macro for Cox models
    --------------------------/
    %macro cox_outcome(data=, event=, title=);

    proc phreg data=&data;
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*&event(0) = ggt_q age sex / rl;
    hazardratio ggt_q / diff=ref;
    title "&title - Model 1";
    run;

    proc phreg data=&data;
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*&event(0) = ggt_q age sex alcohol liver_history smoking bmi_cat education walking sports / rl;
    hazardratio ggt_q / diff=ref;
    title "&title - Model 2";
    run;

    /* P for trend using log-transformed GGT /
    proc phreg data=&data;
    class sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py&event(0) = log_ggt age sex alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "&title - Model 2 Trend Test";
    run;

    %mend;

    /-------------------------
    4. Main analyses (Table 2)
    --------------------------/
    %cox_outcome(data=ohsaki, event=all_cancer, title=All cancer);
    %cox_outcome(data=ohsaki, event=liver_cancer, title=Liver cancer);
    %cox_outcome(data=ohsaki, event=non_liver_cancer, title=Non-liver cancer);
    %cox_outcome(data=ohsaki, event=esophageal, title=Esophageal cancer);
    %cox_outcome(data=ohsaki, event=stomach, title=Stomach cancer);
    %cox_outcome(data=ohsaki, event=resp_intra, title=Respiratory/intrathoracic cancer);
    %cox_outcome(data=ohsaki, event=pancreatic, title=Pancreatic cancer);
    %cox_outcome(data=ohsaki, event=colorectal, title=Colorectal cancer);
    %cox_outcome(data=ohsaki, event=urinary, title=Kidney and urinary cancer);

    /* Sex-specific cancers /
    proc phreg data=ohsaki(where=(sex=1));
    class ggt_q(ref='1') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model pyprostate(0) = ggt_q age alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "Prostate cancer - Model 2";
    run;

    proc phreg data=ohsaki(where=(sex=2));
    class ggt_q(ref='1') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*breast(0) = ggt_q age alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "Breast cancer - Model 2";
    run;

    /-------------------------
    5. Model 3: exclude cancers in first 3 years
    --------------------------/
    data ohsaki_m3;
    set ohsaki;
    if early3y_cancer=1 then delete;
    run;

    proc phreg data=ohsaki_m3;
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*all_cancer(0) = ggt_q age sex alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "All cancer - Model 3 (exclude first 3 years cancers)";
    run;

    /-------------------------
    6. Stratified analyses (Table 3 style)
    --------------------------/

    /* By drinking habit /
    proc phreg data=ohsaki(where=(alcohol=0));
    class ggt_q(ref='1') sex(ref='2') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model pynon_liver_cancer(0) = ggt_q age sex liver_history smoking bmi_cat education walking sports / rl;
    title "Non-liver cancer among never drinkers";
    run;

    proc phreg data=ohsaki(where=(alcohol=1));
    class ggt_q(ref='1') sex(ref='2') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*non_liver_cancer(0) = ggt_q age sex liver_history smoking bmi_cat education walking sports / rl;
    title "Non-liver cancer among former drinkers";
    run;

    proc phreg data=ohsaki(where=(alcohol in (2,3)));
    class ggt_q(ref='1') sex(ref='2') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*non_liver_cancer(0) = ggt_q age sex liver_history smoking bmi_cat education walking sports / rl;
    title "Non-liver cancer among current drinkers";
    run;

    /* By smoking habit /
    proc phreg data=ohsaki(where=(smoking=0));
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model pynon_liver_cancer(0) = ggt_q age sex alcohol liver_history bmi_cat education walking sports / rl;
    title "Non-liver cancer among never smokers";
    run;

    proc phreg data=ohsaki(where=(smoking=1));
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*non_liver_cancer(0) = ggt_q age sex alcohol liver_history bmi_cat education walking sports / rl;
    title "Non-liver cancer among former smokers";
    run;

    proc phreg data=ohsaki(where=(smoking=2));
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*non_liver_cancer(0) = ggt_q age sex alcohol liver_history bmi_cat education walking sports / rl;
    title "Non-liver cancer among current smokers";
    run;

    /* By sex /
    proc phreg data=ohsaki(where=(sex=1));
    class ggt_q(ref='1') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model pynon_liver_cancer(0) = ggt_q age alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "Non-liver cancer among men";
    run;

    proc phreg data=ohsaki(where=(sex=2));
    class ggt_q(ref='1') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model py*non_liver_cancer(0) = ggt_q age alcohol liver_history smoking bmi_cat education walking sports / rl;
    title "Non-liver cancer among women";
    run;

    /-------------------------
    7. Interaction tests
    --------------------------/
    proc phreg data=ohsaki;
    class ggt_q(ref='1') sex(ref='2') alcohol(ref='0') liver_history(ref='0')
    smoking(ref='0') bmi_cat(ref='2') education(ref='0')
    walking(ref='0') sports(ref='0') / param=ref;
    model pynon_liver_cancer(0) =
    ggt_q age sex alcohol liver_history smoking bmi_cat education walking sports
    ggt_qsex ggt_qsmoking ggt_qalcohol / rl;
    title "Interaction model";
    run;

    Stata版

    • stset

    • stcox

    • strata解析

    • interaction項


    • Ohsaki Cohort: GGT and Cancer Incidence

    • Reproduction template for J Epidemiol. 2012;22(2):144-150


    • Assumed current dataset in memory: ohsaki_raw.dta

    • Variables assumed:

    • id sex age ggt alcohol liver_history smoking bmi education walking sports

    • cancer_date death_date emigration_date nhi_loss_date

    • cancer_icdo3

    clear all
    set more off

    use ohsaki_raw.dta, clear

    *------------------------------------------------------

      1. Date handling
        *------------------------------------------------------

    • Assume dates are already Stata daily dates.
      gen follow_start = td(01jan1996)
      gen end_admin = td(31dec2005)

    egen censor_date = rowmin(death_date emigration_date nhi_loss_date end_admin)
    gen final_date = censor_date
    replace final_date = cancer_date if !missing(cancer_date) & cancer_date < censor_date

    drop if final_date <= follow_start

    gen py_days = final_date - follow_start
    gen py = py_days/365.25

    *------------------------------------------------------

      1. GGT quartile
        *------------------------------------------------------
        gen ggt_q = .
        replace ggt_q = 1 if ggt < 13
        replace ggt_q = 2 if ggt >=13 & ggt <18
        replace ggt_q = 3 if ggt >=18 & ggt <30
        replace ggt_q = 4 if ggt >=30

    label define ggtq 1 "<13" 2 "13.0-17.9" 3 "18.0-29.9" 4 ">=30.0"
    label values ggt_q ggtq

    gen log_ggt = log(ggt) if ggt>0

    *------------------------------------------------------

      1. BMI categories
        *------------------------------------------------------
        gen bmi_cat = .
        replace bmi_cat = 1 if bmi < 18.5
        replace bmi_cat = 2 if bmi >=18.5 & bmi <25
        replace bmi_cat = 3 if bmi >=25
        label define bmil 1 "<18.5" 2 "18.5-24.9" 3 ">=25"
        label values bmi_cat bmil

    *------------------------------------------------------

      1. Cancer outcomes
        *------------------------------------------------------
        gen all_cancer = !missing(cancer_date) & cancer_date <= censor_date

    gen liver_cancer = 0
    gen non_liver_cancer = 0
    gen esophageal = 0
    gen stomach = 0
    gen colorectal = 0
    gen resp_intra = 0
    gen pancreatic = 0
    gen breast = 0
    gen prostate = 0
    gen urinary = 0

    replace liver_cancer = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C22"
    replace esophageal = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C15"
    replace stomach = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C16"
    replace colorectal = 1 if all_cancer==1 & inlist(substr(cancer_icdo3,1,3),"C18","C19","C20")
    replace pancreatic = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C25"
    replace breast = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C50"
    replace prostate = 1 if all_cancer==1 & substr(cancer_icdo3,1,3)=="C61"
    replace urinary = 1 if all_cancer==1 & inlist(substr(cancer_icdo3,1,3),"C64","C65","C66","C67","C68")
    replace resp_intra = 1 if all_cancer==1 & inlist(substr(cancer_icdo3,1,3),"C33","C34","C37","C38","C39")
    replace non_liver_cancer = 1 if all_cancer==1 & liver_cancer==0

    *------------------------------------------------------

      1. Survival setup
        *------------------------------------------------------
        stset final_date, origin(time follow_start) enter(time follow_start) ///
        failure(all_cancer==1) id(id)

    *------------------------------------------------------

      1. Table 1 style descriptives
        *------------------------------------------------------
        tabstat ggt age bmi, by(ggt_q) stat(n mean sd)
        tab ggt_q sex, col
        tab ggt_q alcohol, col
        tab ggt_q smoking, col
        tab ggt_q liver_history, col
        tab ggt_q education, col
        tab ggt_q walking, col
        tab ggt_q sports, col

    *------------------------------------------------------

      1. Cox models
        *------------------------------------------------------

    • Model 1: all cancer
      stcox ib1.ggt_q c.age i.sex, vce(robust)
      est store m1_all

    • Model 2: all cancer
      stcox ib1.ggt_q c.age i.sex i.alcohol i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      est store m2_all

    • Trend test
      stcox c.log_ggt c.age i.sex i.alcohol i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)

    *------------------------------------------------------

    run_cox, outcome(all_cancer)
    run_cox, outcome(liver_cancer)
    run_cox, outcome(non_liver_cancer)
    run_cox, outcome(esophageal)
    run_cox, outcome(stomach)
    run_cox, outcome(resp_intra)
    run_cox, outcome(pancreatic)
    run_cox, outcome(colorectal)
    run_cox, outcome(urinary)

    • Male only: prostate
      preserve
      keep if sex==1
      stset final_date, origin(time follow_start) enter(time follow_start) ///
      failure(prostate==1) id(id)
      stcox ib1.ggt_q c.age i.alcohol i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      restore

    • Female only: breast
      preserve
      keep if sex==2
      stset final_date, origin(time follow_start) enter(time follow_start) ///
      failure(breast==1) id(id)
      stcox ib1.ggt_q c.age i.alcohol i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      restore

    *------------------------------------------------------

      1. Model 3: exclude first 3 years cancers
        *------------------------------------------------------
        gen early3y_cancer = all_cancer==1 & cancer_date < td(01jan1999)

    preserve
    drop if early3y_cancer==1
    stset final_date, origin(time follow_start) enter(time follow_start) ///
    failure(all_cancer==1) id(id)
    stcox ib1.ggt_q c.age i.sex i.alcohol i.liver_history i.smoking ///
    ib2.bmi_cat i.education i.walking i.sports, vce(robust)
    restore

    *------------------------------------------------------

      1. Stratified analyses for non-liver cancer
        *------------------------------------------------------

    • By alcohol
      forvalues a = 0/1 {
      preserve
      keep if alcohol==`a'
      stset final_date, origin(time follow_start) enter(time follow_start) ///
      failure(non_liver_cancer==1) id(id)
      stcox ib1.ggt_q c.age i.sex i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      restore
      }

    preserve
    keep if inlist(alcohol,2,3)
    stset final_date, origin(time follow_start) enter(time follow_start) ///
    failure(non_liver_cancer==1) id(id)
    stcox ib1.ggt_q c.age i.sex i.liver_history i.smoking ///
    ib2.bmi_cat i.education i.walking i.sports, vce(robust)
    restore

    • By smoking
      forvalues s = 0/2 {
      preserve
      keep if smoking==`s'
      stset final_date, origin(time follow_start) enter(time follow_start) ///
      failure(non_liver_cancer==1) id(id)
      stcox ib1.ggt_q c.age i.sex i.alcohol i.liver_history ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      restore
      }

    • By sex
      forvalues sx = 1/2 {
      preserve
      keep if sex==`sx'
      stset final_date, origin(time follow_start) enter(time follow_start) ///
      failure(non_liver_cancer==1) id(id)
      stcox ib1.ggt_q c.age i.alcohol i.liver_history i.smoking ///
      ib2.bmi_cat i.education i.walking i.sports, vce(robust)
      restore
      }

    *------------------------------------------------------

      1. Interaction tests
        *------------------------------------------------------
        stset final_date, origin(time follow_start) enter(time follow_start) ///
        failure(non_liver_cancer==1) id(id)

    stcox ib1.ggt_q##i.alcohol c.age i.sex i.liver_history i.smoking ///
    ib2.bmi_cat i.education i.walking i.sports, vce(robust)

    stcox ib1.ggt_q##i.smoking c.age i.sex i.alcohol i.liver_history ///
    ib2.bmi_cat i.education i.walking i.sports, vce(robust)

    stcox ib1.ggt_q##i.sex c.age i.alcohol i.liver_history i.smoking ///
    ib2.bmi_cat i.education i.walking i.sports, vce(robust)

    R版

    • survival package

    • coxph

    • broom出力

    • tidy形式



    ############################################################

    Ohsaki Cohort: GGT and Cancer Incidence

    Reproduction template for J Epidemiol. 2012;22(2):144-150

    ############################################################

    library(dplyr)
    library(stringr)
    library(survival)
    library(broom)

    #-----------------------------------------------------------

    0. Input data assumed: ohsaki_raw

    #-----------------------------------------------------------

    Expected columns:

    id, sex, age, ggt, alcohol, liver_history, smoking, bmi,

    education, walking, sports,

    cancer_date, death_date, emigration_date, nhi_loss_date,

    cancer_icdo3

    Dates should be Date class

    ohsaki <- ohsaki_raw %>%
    mutate(
    follow_start = as.Date("1996-01-01"),
    end_admin = as.Date("2005-12-31"),
    censor_date = pmin(death_date, emigration_date, nhi_loss_date, end_admin, na.rm = TRUE),
    final_date = if_else(!is.na(cancer_date) & cancer_date < censor_date, cancer_date, censor_date),
    py_days = as.numeric(final_date - follow_start),
    py = py_days / 365.25
    ) %>%
    filter(final_date > follow_start) %>%
    mutate(
    ggt_q = case_when(
    ggt < 13 ~ 1L,
    ggt >= 13 & ggt <18 ~ 2L,
    ggt >= 18 & ggt <30 ~ 3L,
    ggt >= 30 ~ 4L,
    TRUE ~ NA_integer_
    ),
    ggt_q = factor(ggt_q, levels = c(1,2,3,4),
    labels = c("<13", "13.0-17.9", "18.0-29.9", ">=30.0")),
    log_ggt = ifelse(ggt > 0, log(ggt), NA_real_),
    bmi_cat = case_when(
    bmi < 18.5 ~ "<18.5",
    bmi >= 18.5 & bmi < 25 ~ "18.5-24.9",
    bmi >= 25 ~ ">=25",
    TRUE ~ NA_character_
    ),
    bmi_cat = factor(bmi_cat, levels = c("<18.5", "18.5-24.9", ">=25")),
    sex = factor(sex, levels = c(1,2), labels = c("Male","Female")),
    alcohol = factor(alcohol, levels = c(0,1,2,3),
    labels = c("Never", "Former", "Current_light", "Current_heavy")),
    smoking = factor(smoking, levels = c(0,1,2),
    labels = c("Never", "Former", "Current")),
    education = factor(education, levels = c(0,1), labels = c("<HS","HS+")),
    walking = factor(walking, levels = c(0,1), labels = c("<30min", ">=30min")),
    sports = factor(sports, levels = c(0,1), labels = c("<1h/wk", ">=1h/wk")),
    liver_history = factor(liver_history, levels = c(0,1), labels = c("No","Yes"))
    ) %>%
    mutate(
    all_cancer = !is.na(cancer_date) & cancer_date <= censor_date,
    liver_cancer = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C22",
    esophageal = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C15",
    stomach = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C16",
    colorectal = all_cancer & str_sub(cancer_icdo3, 1, 3) %in% c("C18", "C19", "C20"),
    pancreatic = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C25",
    breast = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C50",
    prostate = all_cancer & str_sub(cancer_icdo3, 1, 3) == "C61",
    urinary = all_cancer & str_sub(cancer_icdo3, 1, 3) %in% c("C64","C65","C66","C67","C68"),
    resp_intra = all_cancer & str_sub(cancer_icdo3, 1, 3) %in% c("C33","C34","C37","C38","C39"),
    non_liver_cancer = all_cancer & !liver_cancer,
    early3y_cancer = all_cancer & cancer_date < as.Date("1999-01-01")
    )

    #-----------------------------------------------------------

    1. Table 1 style summary

    #-----------------------------------------------------------
    ohsaki %>%
    group_by(ggt_q) %>%
    summarise(
    n = n(),
    mean_ggt = mean(ggt, na.rm = TRUE),
    sd_ggt = sd(ggt, na.rm = TRUE),
    mean_age = mean(age, na.rm = TRUE),
    sd_age = sd(age, na.rm = TRUE),
    mean_bmi = mean(bmi, na.rm = TRUE),
    sd_bmi = sd(bmi, na.rm = TRUE),
    women_pct = mean(sex == "Female", na.rm = TRUE) * 100,
    liver_history_pct = mean(liver_history == "Yes", na.rm = TRUE) * 100,
    current_smoker_pct = mean(smoking == "Current", na.rm = TRUE) * 100,
    current_drinker_pct = mean(alcohol %in% c("Current_light","Current_heavy"), na.rm = TRUE) * 100
    )

    #-----------------------------------------------------------

    2. Helper functions

    #-----------------------------------------------------------
    fit_models <- function(data, event_var, sex_adjust = TRUE, alcohol_adjust = TRUE,
    smoking_adjust = TRUE, exclude_early3y = FALSE) {

    dat <- data
    if (exclude_early3y) {
    dat <- dat %>% filter(!early3y_cancer)
    }

    surv_obj <- with(dat, Surv(py, .data[[event_var]]))

    Model 1

    if (sex_adjust) {
    f1 <- as.formula(surv_obj ~ ggt_q + age + sex)
    } else {
    f1 <- as.formula(surv_obj ~ ggt_q + age)
    }

    Model 2

    rhs2 <- c("ggt_q", "age")
    if (sex_adjust) rhs2 <- c(rhs2, "sex")
    if (alcohol_adjust) rhs2 <- c(rhs2, "alcohol")
    rhs2 <- c(rhs2, "liver_history")
    if (smoking_adjust) rhs2 <- c(rhs2, "smoking")
    rhs2 <- c(rhs2, "bmi_cat", "education", "walking", "sports")

    f2 <- as.formula(
    paste0("surv_obj ~ ", paste(rhs2, collapse = " + "))
    )

    Trend model

    rhs_trend <- rhs2
    rhs_trend[match("ggt_q", rhs_trend)] <- "log_ggt"
    ftrend <- as.formula(
    paste0("surv_obj ~ ", paste(rhs_trend, collapse = " + "))
    )

    m1 <- coxph(f1, data = dat)
    m2 <- coxph(f2, data = dat)
    mt <- coxph(ftrend, data = dat)

    list(model1 = m1, model2 = m2, trend = mt)
    }

    print_hr <- function(model) {
    broom::tidy(model, exponentiate = TRUE, conf.int = TRUE)
    }

    #-----------------------------------------------------------

    3. Main analyses (Table 2)

    #-----------------------------------------------------------
    res_all <- fit_models(ohsaki, "all_cancer")
    print_hr(res_all$model1)
    print_hr(res_all$model2)
    print_hr(res_all$trend)

    res_liver <- fit_models(ohsaki, "liver_cancer")
    res_nonliver <- fit_models(ohsaki, "non_liver_cancer")
    res_esoph <- fit_models(ohsaki, "esophageal")
    res_stomach <- fit_models(ohsaki, "stomach")
    res_resp <- fit_models(ohsaki, "resp_intra")
    res_pancreas <- fit_models(ohsaki, "pancreatic")
    res_crc <- fit_models(ohsaki, "colorectal")
    res_urinary <- fit_models(ohsaki, "urinary")

    Prostate: men only, no sex covariate

    res_prostate <- fit_models(
    ohsaki %>% filter(sex == "Male"),
    "prostate",
    sex_adjust = FALSE
    )

    Breast: women only, no sex covariate

    res_breast <- fit_models(
    ohsaki %>% filter(sex == "Female"),
    "breast",
    sex_adjust = FALSE
    )

    #-----------------------------------------------------------

    4. Model 3: excluding cancers in first 3 years

    #-----------------------------------------------------------
    res_all_m3 <- fit_models(ohsaki, "all_cancer", exclude_early3y = TRUE)
    print_hr(res_all_m3$model2)

    #-----------------------------------------------------------

    5. Stratified analyses (Table 3)

    #-----------------------------------------------------------

    Never drinkers

    res_neverdrink <- fit_models(
    ohsaki %>% filter(alcohol == "Never"),
    "non_liver_cancer",
    alcohol_adjust = FALSE
    )

    Former drinkers

    res_formerdrink <- fit_models(
    ohsaki %>% filter(alcohol == "Former"),
    "non_liver_cancer",
    alcohol_adjust = FALSE
    )

    Current drinkers

    res_currentdrink <- fit_models(
    ohsaki %>% filter(alcohol %in% c("Current_light", "Current_heavy")),
    "non_liver_cancer",
    alcohol_adjust = FALSE
    )

    Never smokers

    res_neversmoke <- fit_models(
    ohsaki %>% filter(smoking == "Never"),
    "non_liver_cancer",
    smoking_adjust = FALSE
    )

    Former smokers

    res_formersmoke <- fit_models(
    ohsaki %>% filter(smoking == "Former"),
    "non_liver_cancer",
    smoking_adjust = FALSE
    )

    Current smokers

    res_currentsmoke <- fit_models(
    ohsaki %>% filter(smoking == "Current"),
    "non_liver_cancer",
    smoking_adjust = FALSE
    )

    Men

    res_men <- fit_models(
    ohsaki %>% filter(sex == "Male"),
    "non_liver_cancer",
    sex_adjust = FALSE
    )

    Women

    res_women <- fit_models(
    ohsaki %>% filter(sex == "Female"),
    "non_liver_cancer",
    sex_adjust = FALSE
    )

    #-----------------------------------------------------------

    6. Interaction tests

    #-----------------------------------------------------------
    m_int_alcohol <- coxph(
    Surv(py, non_liver_cancer) ~ ggt_q * alcohol + age + sex + liver_history +
    smoking + bmi_cat + education + walking + sports,
    data = ohsaki
    )
    summary(m_int_alcohol)

    m_int_smoking <- coxph(
    Surv(py, non_liver_cancer) ~ ggt_q * smoking + age + sex + alcohol +
    liver_history + bmi_cat + education + walking + sports,
    data = ohsaki
    )
    summary(m_int_smoking)

    m_int_sex <- coxph(
    Surv(py, non_liver_cancer) ~ ggt_q * sex + age + alcohol + liver_history +
    smoking + bmi_cat + education + walking + sports,
    data = ohsaki
    )
    summary(m_int_sex)



    プログラムをざっと斜め読みしましたが、おおむねあっているように思いました(実際に回してみていないのでやてみたら何かエラー出る可能性はあるが)。


    いやこれすごいね。。。


    一番驚いた点

    AIは単に文章をコードにしたのではなく、

    論文中に暗黙にある

    「疫学者が普通こう処理する」

    まで補っていました。

    例えば:

    • 3年以内発癌除外 → reverse causation対策

    • log(GGT) trend test → skewed distribution対応

    • liver cancerとnon-liver cancer分離

    • sex-specific cancer(乳癌・前立腺癌)の別解析

    これはMethodsに全部は書いていない部分もあります。

    つまり、論文の行間にある解析思想まで推定している

    ということです。🤖📊


    研究者として感じたこと

    昔は、解析コードは「個人の職人技」に近かった。

    しかし今は、

    論文が十分に書かれていれば、かなり復元できる

    時代になっています。

    これは再現性にとって大きい。



    10年以上前の自分の論文をAIで読むと

    少し不思議です。

    当時は必死にプログラミングを勉強して、1つ1つ分析して、

    SASの出力を何度も見て、ハザード比の小数点を確認して、時にはエラーが出て、どこにエラーがあるか分からず、全角スペースが入っていたりして、、、、

    そんな思い出があるわけですが、令和の現代では、そんな努力とか不毛なエラー対応とかなく、AIが数分で再構成する。時代はかなり変わりましたね、、、。


    でも本質は変わらない

    重要なのはコードではなく、

    何を問い、どこまで交絡を疑うか

    です。

    この論文でも結論は、

    GGT高値そのものが癌を作るというより、飲酒曝露を反映している可能性が高い

    でした。

    つまり、

    分析して数字を出すことではなく、結果の先にある解釈が研究の中心

    です。 そもそもいいテーマに着手することが最も重要ともいえますが。


    これから起きること

    今後はたぶん、

    • 古い論文から解析コード復元

    • 査読前にAIで再現性チェック

    • 生データなしでMethods監査

    が普通になります。

    研究者は、「コードを書く人」から、「問いと構造を設計する人」

    へさらに寄っていくでしょう。良いことと思います。

    希望としてはもっと先に進んで、AIが適切なジャーナルを見つけてくれて、興味を持ったエディターはAIでエディットして最終原稿を作成して、著者がそれを承認すれば掲載、という世の中が早く来てほしいと思います。


    少しだけ感慨

    10年以上前の自分の論文を、

    未来の道具で読み直すと、

    当時気づかなかった設計の癖も見えます。

    研究は論文を書いて終わりではなく、

    時間が経ってから別の技術で再読される

    ものなのだと思いました。


    なぜAIがここまで「復元」できるのか。


    理由1:疫学には「文法」がある

    疫学論文は自由作文ではありません。

    Methodsには実はかなり強い文法があります。

    たとえば、

    Cox proportional hazards regression model was used

    と書かれた時点で、

    かなりの部分が決まります。

    自動的に想定されるのは、

    • survival object

    • follow-up time

    • censoring

    • event indicator

    • reference category

    • hazard ratio

    • confidence interval

    です。

    つまり、

    1行で解析構造の骨格がほぼ確定する

    のです。


    理由2:変数の書き方にも定型がある

    この論文では、

    GGTを quartile にしています。

    しかも cut-off が明示されている。

    • <13

    • 13–17.9

    • 18–29.9

    • ≥30

    これが書かれていれば、

    コード上ではほぼ一意です。

    if ggt <13 → Q1
    if 13<=ggt<18 → Q2
    

    ここは人間でもAIでも同じになります。


    理由3:疫学者は暗黙の補完をする

    論文には全部は書かれていません。

    でも読む側は補います。

    たとえば、

    P for trend was computed with log-transformed GGT

    これがあれば、

    GGTの分布が右裾に長いことを前提に、

    log(GGT)
    

    を連続投入すると分かります。

    つまり、

    Methodsは全部を書かなくても、専門家は補完して読む

    文化があります。

    AIがここにかなり乗ってきている。


    面白かった点:AIは「書かれていない研究者の癖」まで読む

    たとえば今回、

    Model 3 の

    first 3 years excluded

    に対して、

    AIは即座に

    reverse causation対策

    と認識しました。

    つまり、

    「潜在癌が先にGGTを上げていた可能性」

    を消す処理だと理解している。

    これは単なる翻訳ではありません。

    疫学の発想そのものを踏んでいる

    ということです。


    逆に言えば、Methodsが甘い論文は危うい

    今後かなり起きるのは、

    AIによる再現性チェックです。

    Methodsを読むだけで、

    「ここが曖昧」

    がすぐ見える。

    例えば:

    • 欠測処理が書いていない

    • cut-off根拠がない

    • censoring ruleが曖昧

    • time origin不明

    この論文でも、

    もし follow-up 起点を書いていなければ、

    復元はかなり不安定になります。


    研究者に必要になるもの

    昔は、

    「解析できる人」が強かった。

    これからは、

    第三者が復元できるように設計する人

    が強くなります。

    つまり、

    • codeを書く力

    • Methodsを書く力

    • data dictionaryを残す力

    が同じくらい重要になる。


    古いSASコードが消える問題

    これは実際かなりあります。

    10年以上前の研究だと、

    • PCが変わる

    • SAS versionが変わる

    • pathが消える

    • commentがない

    で読めなくなる。

    でも論文が丁寧なら、

    かなり戻せる。

    今回それを実感しました。


    これからの現実

    将来たぶん普通になります。

    • 良い論文をAIに読みこませる

    • 解析コード自動生成

    • 手直しして分析を回す

    つまり、

    Methodsが実質コード化される

    時代です。


    #疫学
    #コホート研究
    #AI活用
    #生成AI
    #SAS
    #Stata
    #R言語
    #統計解析
    #Cox回帰
    #論文再現
    #研究再現性
    #医学研究
    #γGTP
    #GGT
    #癌疫学
    #大崎コホート
    #東北大学
    #研究方法論
    #医療データ分析
    #アカデミア
    #疫学
    #コホート研究
    #AI活用
    #SAS
    #Stata
    #R言語
    #統計解析
    #医学研究
    #論文再現
    #研究再現性
    #γGTP
    #GGT
    #癌疫学
    #大崎コホート
    #東北大学
    #Cox回帰
    #医療データ分析
    #研究方法論
    #生成AI
    #医学論文

     
     
    Evidence-based Pragmatist/ナレッジブローカー/人口減少地域における医療介護の持続可能モデル研究者・実務者/ACP/元バックパッカーで海外30国以上/腰痛患者/子育て/引越13回/ 総合内科専門医/ 老年科専門医/ 博士(医学) / Harvard

    あなたへのおすすめ