{"id":320,"date":"2009-12-17T20:30:19","date_gmt":"2009-12-18T01:30:19","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=320"},"modified":"2009-12-17T20:34:43","modified_gmt":"2009-12-18T01:34:43","slug":"multiple-imputation-seriously-now","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/multiple-imputation-seriously-now\/","title":{"rendered":"Multiple imputation, seriously now"},"content":{"rendered":"<p>A few days ago I gave an example of multiple imputation but I glossed over a number of things, which is fine when you are just getting into a topic, or when the mad scientist part of your personality has taken over, but seriously now &#8230;<\/p>\n<p><em>Our story continues &#8230; when last seen, our data were being multiply imputed while Ronda was downstairs not driving the car through the lobby and not running over the guard at the front desk&#8230;.<\/em><\/p>\n<p>So, let&#8217;s look at the reason people would do an imputation, seriously now. It is not to create data so I don&#8217;t have ugly looking cells and so I can get higher N&#8217;s for the means. No, au contraire !<\/p>\n<p>Generally, it is because you have a number of variables, let&#8217;s say four, and you are missing data on some, but not all of the variables, for a number of people. You would like to do, say,a multiple regression. If you are missing 10% of the data for each subject, that is not too terrible, but if each of four different variables is missing 10% you end up losing 40% of your sample. That&#8217;s bad.<\/p>\n<p>Let&#8217;s say, because the psychopathic half of my split personality happened to feel like it, that I randomly deleted 10% of four different variables using the code:<\/p>\n<p>rd = round ((10*(ranuni(0))),1) ;<\/p>\n<p>if rd = 9 then weekend = . ;<\/p>\n<p>else if rd\u00a0 = 4 then svc_lvl_pct = . ;<\/p>\n<p>and so on.\u00a0 Then, when the hard-working statistician part resumed control of our shared brain it went, &#8220;@!$*)+ ! &#8221; or something like that realizing that now, if I wanted to perform a regression analysis, for example, 40% of my data were missing. In my case, the data are missing completely at random so at least that&#8217;s something to be happy about.<\/p>\n<p><strong>Stuff to know:<\/strong><\/p>\n<p><em>1. Code your variables correctly. <\/em><\/p>\n<p>Now let&#8217;s look at our variables. If I use weekday as a variable, that is going to be coded 1 = Sunday through 7 = Saturday. It&#8217;s rather unlikely that sales, service or anything else is a linear function with Sunday being the lowest and Saturday being the highest (bar tabs, maybe).\u00a0\u00a0 We can get to imputing class variables later, but for now let&#8217;s just assume we have numeric variables and we are going to do a plain vanilla regression. I am going to create a new variable, weekend (= 1 on the weekends, and 0 other days).<\/p>\n<p>If you have a categorical variable, such as department, you can use that using the CLASS statement, unless you are using an ancient version of SAS. (I am using 9.2 &amp; I highly recommend it). However, that does require doing things a little differently. For simplicity sake I am going to use all numeric variables, including one variable dummy-coded as 0,1 .<\/p>\n<p><em>2. Choose the right variables for the imputation<\/em><\/p>\n<p>This may seem rather obvious but just playing around, I first did this analysis with variables I selected off the top of my head, that &#8220;made sense&#8221;, some of which ended up being related to one another and others that didn&#8217;t. Next, I actually did a bit of research to find out what variables really ought to be related, based on previous analyses, and discussions with experienced people in the organization, took some time to make sure the data were coded as assumed (which they never are).\u00a0 I ended up with a similar, but not identical, set of variables. My first analysis was okay, but not nearly as close to the real model as the second one. The added work took me about eight hours, but it was well worth it. I make this obvious point because I have had too many conversations with people who say, &#8220;I have 47 years of experience, I know what is significant in blah-de-blah.&#8221;<\/p>\n<p>Maybe they do and maybe they don&#8217;t. Even if they do, the data may not be coded the way they expect. For example, weekday is not a variable that tells if it was a weekday or not but rather, the day of the week from 1 = Sunday to 7 = Saturday.<\/p>\n<p><strong>An example (seriously now).<\/strong><\/p>\n<p>Have you ever been put on hold for tech support, making reservations or anything else and waited so long that you got disgusted and hung up? Well the service level percentage is 100% &#8211; the percentage of people who hung up. I want to predict the service level percentage and I think it is a function of whether it is a weekend or not (fewer people on staff), the average amount of time people spend on each call (which means other callers will have to wait) and the average time someone waits before hanging up .<\/p>\n<p>Step 1: Proc MI<\/p>\n<p>proc mi data = history out = histmi minimum\u00a0 = 0 round =\u00a0 .01 1 1 1\u00a0\u00a0\u00a0 ;<br \/>\nvar\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 svc_lvl_pct weekend ab_time a_time ;<\/p>\n<p>This will create a dataset name histmi which will have five times as many observations as my original dataset, as it will do five imputations. The minimum value I want imputed is 0, because you can&#8217;t have negative time or percentage. <a href=\"http:\/\/www2.sas.com\/proceedings\/sugi30\/113-30.pdf \">Although Paul Allison has written that rounding gives you biased estimates I did it anyway just to spite him<\/a> (actually, I have never met the man and I am sure that he is way cool. I did do this with rounding to 1 second, rounding to .01 second and without rounding. Actually, the one with rounding to 1 gave the closest estimate but that was with an N of 3 trials so it doesn&#8217;t really mean anything. He did his study with random data and mega-iterations and I am sure he is right, rounding is bad. The truth is I had run this and then read his article the next day. How is that for bad timing? )<\/p>\n<p>Step 2: Perform your analysis<\/p>\n<p>This is simple. Sort your data by _imputation_\u00a0 (which is the imputation number, a variable created by PROC MI) . Then perform your regression analysis by imputation. Output the parameter estimates and covariance matrix for estimates to a dataset, in my case I called it outhistmi .<\/p>\n<p>proc sort data = histmi ;<br \/>\nby _imputation_ ;<br \/>\nproc reg data\u00a0 = histmi outest =outhistmi covout ;<br \/>\nmodel svc_lvl_pct\u00a0 = weekend A_time\u00a0\u00a0 ab_time ;<br \/>\nby _imputation_\u00a0 ;<\/p>\n<p>Step 3: Use MI Analyze to get parameter estimates<\/p>\n<p>proc mianalyze data = outhistmi edf = 1231 ;<br \/>\nvar\u00a0 weekend A_time\u00a0\u00a0 ab_time ;<\/p>\n<p>Edf is the estimated degrees of freedom. Since I had 1,235 observations and four parameters (including the intercept)<\/p>\n<p>edf\u00a0 =\u00a0 1235 &#8211; 4<\/p>\n<p>So, how well did it work?<\/p>\n<p><a href=\"http:\/\/its.usc.edu\/~ademars\/fulldata.html\">You can go here and see the model for the complete data<\/a> for all 1,235 records.\u00a0 <a href=\"http:\/\/its.usc.edu\/~ademars\/impudata.html\">The estimates from MIANALYZE are shown here<\/a>.<\/p>\n<p>Actual estimates\u00a0\u00a0 vs\u00a0 results of MIAnalyze<\/p>\n<p>Weekend\u00a0\u00a0 -.044 \u00a0\u00a0\u00a0\u00a0\u00a0 -.029<\/p>\n<p>Average call time\u00a0 .00021\u00a0\u00a0 .00020<\/p>\n<p>Abandoned call time\u00a0\u00a0 -.00068\u00a0\u00a0 -.00056<\/p>\n<p>In all cases, the actual parameter estimates did fall within the 95% confidence intervals. However,\u00a0 because I am not that easily satisfied, I went back and performed the regression with the 767 records that had complete data.\u00a0 It also gave me pretty similar results to the full data, which is what I would expect since in this case the data were missing completely at random (probably not a good representation of real life) as I had deleted these out using a random number function.<\/p>\n<p>I am still not wholly convinced of the benefit of multiple imputation versus just going with those that have complete data. I&#8217;ll have to think about this some more. In the meantime, I have one daughter telling me that normal people play with guitar hero instead of PROC MIANALYZE and another one saying I am going to be late to hear her play the saxophone in her Christmas concert, so\u00a0 I guess I&#8217;ll think about it later.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I gave an example of multiple imputation but I glossed over a number of things, which is fine when you are just getting into a topic, or when the mad scientist part of your personality has taken over, but seriously now &#8230; Our story continues &#8230; when last seen, our data&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-statistics"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":5,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/320\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}