SAS中文论坛

标题: Fundamental Diagnostics for Two-Level Mixed Models: The SAS [打印本页]

作者: shiyiming    时间: 2011-7-2 23:16
标题: Fundamental Diagnostics for Two-Level Mixed Models: The SAS
From LCChien's blog on blogspot

原文載點:http://support.sas.com/resources/papers/proceedings10/201-2010.pdf<br /><br />在進行 mixed model 分析時,模型的檢定是相當重要但也是相當煩人的一環。幾位南卡大和南佛大的學者寫了一個巨集程式來簡化相關程式的寫作,雖然目前這個程式只能使用在 2-level model,但也是具有相當貢獻。<br /><a name='more'></a><br />這個名叫 %mixed_dx 的巨集程式如下所示:<br /><pre><code>%mixed_dx (ModelI = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dims = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; solnF = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; solnR =,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Level1 = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Influence = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min_nj = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pr = ,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GroupVar = );</code></pre>每個參數的設定如下:<br /><ul><li>ModelI:讀取由ODS OUTPUT的ModelInfo選項所生成的包含所有模型資訊的資料</li><li>Dims:讀取由ODS OUTPUT的Dimensions選項所生成的資料維度數據</li><li>solnF:讀取由ODS OUTPUT的SolutionF選項所生成的固定效應參數估計值</li><li>solnR:讀取由ODS OUTPUT的SolutionR選項所生成的隨機效應參數估計值</li><li>Level1:讀取由model statement的outp選項所生成的Level-1殘差值資料</li><li>Influence:讀取由model statement的influence選項所生成的模型檢定數據</li><li>min_nj:設定Level-2 unit的最小組內樣本數</li><li>pr:定義檢定內所需要用到的threshold percentile rank(預設值=90)</li><li>GroupVar:若有使用名義(nominal)類別的Level-2 unit的因子,則必須要把每個名義類別的定義另存一個新檔並用此巨集變數來呼叫。</li></ul>首先,利用PROC MIXED程序去估計一個模型,並且利用ODS OUTPUT的功能把%mixed_dx要用到的資料給另存出來:<br /><pre><code>ods exclude influence SolutionR;<br />title;<br />proc mixed data = temp covtest noclprint NAMELEN=32;<br />&nbsp;&nbsp; &nbsp; &nbsp;class schoolid;<br />&nbsp;&nbsp; &nbsp; &nbsp;model mathach = SIZE FEMALE SES MEANSES SES*MEANSES SES*SIZE&nbsp;FEMALE*SIZE/ solution <span class="Apple-style-span" style="color: blue;">outp=L1Resid</span> <span class="Apple-style-span" style="background-color: orange;">influence(effect=schoolid iter=5)</span>;<br />&nbsp;&nbsp; &nbsp; &nbsp;random &nbsp;intercept FEMALE SES / sub=schoolid solution type=un;<br />&nbsp;&nbsp; &nbsp; &nbsp;<span class="Apple-style-span" style="color: red;">ods output SolutionR=L2Resid SolutionF=Fixed ModelInfo=ModelStuff&nbsp;Dimensions=DatStuff Influence=influence</span>;<br />run;</code></pre>其中,outp選項所輸出的資料L1Resid是level 1的殘差值,這是要用在Level1參數裡面的。橘色高亮部分即為原始PROC MIXED內定的模型檢定指令,若配合ODS HTML的話可以輸出高解析度的圖表,但就是因為裡面包含太多圖了,所以才需要使用%mixed_dx來把幾個重要的圖整理出來。而紅色部分即為ODS OUTPUT輸出的指令。此處是缺一不可,即為重要。<br /><br />接下來就來執行巨集程式:<br /><pre><code>%mixed_dx (ModelI = modelstuff, Dims = datstuff, solnF = Fixed, solnR =&nbsp;L2Resid, Level1 = L1Resid, Influence = influence, min_nj = 5, pr = 90,&nbsp;GroupVar = None);</code></pre>在生成的圖形當中,主要以殘差的箱型圖、柱狀分布圖以及散布圖為主。另外也有殘差變異數的散布圖(用來檢定同質性)還有離群值的柱狀分布圖。如下所示:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-lL4QzLw2xsU/Tfjg1GbcEzI/AAAAAAAAF7A/-x5y8CBngjo/s1600/1308156116691.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-lL4QzLw2xsU/Tfjg1GbcEzI/AAAAAAAAF7A/-x5y8CBngjo/s320/1308156116691.png" width="232" /></a><a href="http://3.bp.blogspot.com/-mVZs_x8oTl4/Tfjg6ZvR9SI/AAAAAAAAF7E/r2dkR4E1k48/s1600/1308156138323.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://3.bp.blogspot.com/-mVZs_x8oTl4/Tfjg6ZvR9SI/AAAAAAAAF7E/r2dkR4E1k48/s320/1308156138323.png" style="cursor: move;" width="249" /></a></div><br />表格方面,會整理出level-2 unit的常態統計量表、Levene’s同質性檢定表、離群值檢定和各種檢定統計量:<br /><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-ZES6TXJgcXc/TfjgaVouX1I/AAAAAAAAF60/viVUNfhBK4s/s1600/1308156009762.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-ZES6TXJgcXc/TfjgaVouX1I/AAAAAAAAF60/viVUNfhBK4s/s320/1308156009762.png" width="245" /></a><a href="http://1.bp.blogspot.com/-dZXo-rf_LAY/Tfjgj5mauHI/AAAAAAAAF64/oMkZRo0U2a8/s1600/1308156047388.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-dZXo-rf_LAY/Tfjgj5mauHI/AAAAAAAAF64/oMkZRo0U2a8/s320/1308156047388.png" style="cursor: move;" width="212" /></a><a href="http://1.bp.blogspot.com/-TAcTIX-wMNA/TfjgqLcoTxI/AAAAAAAAF68/2BuBcu5Lgpc/s1600/1308156073149.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-TAcTIX-wMNA/TfjgqLcoTxI/AAAAAAAAF68/2BuBcu5Lgpc/s320/1308156073149.png" style="cursor: move;" width="250" /></a></div><br />目前這段程式碼可以在他們的校方網站上面下載:<a href="http://www.ed.sc.edu/bell/"><!-- m --><a class="postlink" href="http://www.ed.sc.edu/bell/">http://www.ed.sc.edu/bell/</a><!-- m --></a><br /><br /><b>CONTACT INFORMATION &nbsp;</b><br />Your comments and questions are valued and encouraged. &nbsp;Contact the author at:<br />Bethany A. Bell<br />University of South Carolina<br />College of Education, Wardlaw 133<br />Columbia, SC 29208<br />Work Phone: 803-777-2387<br />E-mail:babell@sc.edu<br />Web: <!-- m --><a class="postlink" href="http://www.ed.sc.edu/bell/">http://www.ed.sc.edu/bell/</a><!-- m --><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6268919072942670865-5552643391491270112?l=sugiclub.blogspot.com' alt='' /></div>




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2