NHANES数据库NHANES数据分析教程

NHANES数据库介绍及使用(六)-几步学会回归

2021-03-19  本文已影响0人  不学临床的医学生

在繁杂的现场工作中找到片刻闲暇时间,加之最近又有读者问起,便继续更新之前的教程,希望能对大家有所帮助。本次主要分享的是线性回归以及logistic回归的内容~

1. 线性回归
按以往惯例,还是以官方教程提供的数据和代码为参考,采用的dataset与之前教程一致,就不再放链接了,直接上代码和结果

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;
/*简单线性回归*/
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回归

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;
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;

4. 参考内容

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

上一篇 下一篇

猜你喜欢

热点阅读