NHANES數據庫介紹及使用(六)-幾步學會回歸

在繁雜的現場工作中找到片刻閑暇時間,加之最近又有讀者問起,便繼續更新之前的教程,希望能對大家有所幫助。本次主要分享的是線性回歸以及logistic回歸的內容~

1. 線性回歸
按以往慣例,還是以官方教程提供的數據和代碼為參考,采用的dataset與之前教程一致,就不再放鏈接了,直接上代碼和結果

  • SAS代碼 (主要就是變量的重新賦值,為之后校正混雜因素等做好準備)
data analysis_data_1;  
set analysis_data;
if ridstatr=2; *all mec exam data;

/*set don't know and refused (7,9) to missing*/
if dmdeduc>3 then dmdeduc=.;

/*define smokers*/
if smq020 eq 2 then smoker=1;
else if smq020 eq 1 and smq040 eq 3 then smoker=2;
else if smq020 eq 1 and smq040 in(1,2) then smoker=3;

/*for input to SAS PROC SURVEYREG - recode gender so that men is the reference group*/
if riagendr eq 1 then sex=2;
else if riagendr eq 2 then sex=1;

/*for input to SAS PROC SURVEYREG - recode race/ethnicity so that non-Hispanic white is the reference group*/
ethn=ridreth1;
if ridreth1 eq 3 then ethn=5;
else if ridreth1 eq 4 then ethn=2;
else if ridreth1 eq 2 then ethn=3;
else if ridreth1 eq 5 then ethn=4;

if 0 le bmxbmi lt 18.5 then bmicatf=1; 
else if 18.5 le bmxbmi lt 25 then bmicatf=4; 
else if 25 le bmxbmi lt 30 then bmicatf=2; 
else if bmxbmi ge 30 then bmicatf=3; 

if 0 le bmxbmi lt 18.5 then bmicat=1; 
else if 18.5 le bmxbmi lt 25 then bmicat=2; 
else if 25 le bmxbmi lt 30 then bmicat=3; 
else if bmxbmi ge 30 then bmicat=4; 

if (lbdhdl^=. and riagendr^=. and  ridreth1^=. and smoker^=. and dmdeduc^=. and bmxbmi^=.)and wtmec4yr>0
   and (ridageyr>=20) then eligible=1;  *else eligible=2;

run;
  • SAS代碼 (簡單線性回歸以及多元線性回歸)
/*簡單線性回歸*/
PROC SURVEYREG data=analysis_data_1 nomcar;
STRATA sdmvstra;
CLUSTER sdmvpsu;
WEIGHT wtmec4yr;
MODEL  lbdhdl= bmxbmi/CLPARM  vadjust=none;
DOMAIN eligible;
run; 
/*多元線性回歸*/
PROC SURVEYREG data=analysis_data_1 nomcar;
STRATA sdmvstra;
CLUSTER sdmvpsu;
WEIGHT wtmec4yr;
CLASS  sex ethn smoker dmdeduc bmicatf;
DOMAIN eligible;
MODEL  lbdhdl= sex ethn ridageyr smoker dmdeduc smoker bmicatf/CLPARM solution vadjust=none;
run; 
  • 結果展示


    簡單線性回歸結果

    多元線性回歸結果

2.logistic回歸

  • SAS代碼 (主要就是變量的重新賦值,為之后校正混雜因素等做好準備)
data analysis_data_1;
    set analysis_data;
    if ridstatr=2; *all mec examined data;

   if ridageyr >= 20 then sel=1; *else sel=2;

*create an indicator of hypertension based on blood pressure and medication;
    if (bpxsar >= 140 or bpxdar >= 90 or bpq050a = 1) then Hyper = 1;
    else if (bpxsar ne . and bpxdar ne .) then Hyper = 0;

*create an indicator of high cholesterol based on total cholesterol and medication;
    if (lbxtc>=240 or bpq100d = 1) then HiChol = 1;
    else if (lbxtc ne . ) then HiChol = 0;

    *create bmi groups;
    if 0<=bmxbmi<25 then bmigrp=1;
    else if 25<=bmxbmi<30 then bmigrp=2;
    else if bmxbmi>=30 then bmigrp=3;

    *create age groups;
    if 20<=ridageyr<40 then age=1;
    else if 40<=ridageyr<60 then age=2;
    else if ridageyr>=60 then age=3;

    *create log of fasting triglycerides;
    logtrig=log(lbxtr);

run;
  • SAS代碼 (多元logistic回歸)
PROC SURVEYLOGISTIC DATA = Analysis_Data_1 nomcar; /* can add "noprint" option to suppress printing if using ods statement*/
STRATA sdmvstra;
CLUSTER sdmvpsu;
WEIGHT wtsaf4yr;
DOMAIN  sel;
CLASS age (PARAM=REF REF="2") 
      riagendr (PARAM=REF REF="2") 
      hichol (PARAM=REF REF="1") 
      bmigrp (PARAM=REF REF="2"); /*分別以2組和1組作為對照組*/
MODEL hyper (desc)=age riagendr hichol bmigrp logtrig/clparm vadjust=none;
run;
  • 結果展示


  • 一點總結
    總體而言,演示程序并不復雜,完成前期的賦值,之后帶入模型即可。但是程序中仍有可學習的地方,比如是否患高血壓的賦值,滿足收縮壓>140mmHg或者舒張壓>90mmHg或者服用高血壓藥物;通過lbdhdl^=.來排除缺失值,篩選最后需要的人群


4. 參考內容

https://wwwn.cdc.gov/nchs/nhanes/tutorials/samplecode.aspx

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。