<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 All About
Step1:  Graphic Interpretation
The graphic above illustrates the pattern of follow-ups in the CMMI data set for each of the 1,640 unique patients. Using your cursor, you can hover over a particular color to find out the specific care setting. Each concentric circle going out from the middle represent a new follow-up visit for a person. For example, in the figure above, starting in the center, there is a red layer in the first concentric circle. If you hover over the first red circle, this says 41.8%. This means that 41.8% of the 1,640 patients reported 'Long Term Care' at their first visit. Hovering over the next layer that is black, gives a value of 7.26%. This means that 7.26% of the population had a first visit labeled as 'Long Term Care' and then had no additional visits.
Statistical Inference
I'm not sure if there is a hypothesis we want to test in relation to these two variables (i.e. Care Setting and number of follow-up visits). 
<a id='ua'></a>
Unadjusted Associations with Care Setting (First Visit Only)
In this AIM, we will look at testing the null hypothesis of no association between each row variable and the column variable (ConsultLoc). There is obviously a time aspect to this data, but for this aim, we will stick to the first encounter only.
Here is how the data is munged for this aim
<ASSISTANT_TASK:>
Python Code:
from IPython.core.display import display, HTML;from string import Template;
HTML('<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>')
css_text2 = '''
#main {  float: left;  width: 750px;}#sidebar {  float: right;  width: 100px;}#sequence {  width: 600px;  height: 70px;}#legend {  padding: 10px 0 0 3px;}#sequence text, #legend text {  font-weight: 400;  fill: #000000; font-size: 0.75em;}#graph-div2 {  position: relative;}#graph-div2 {  stroke: #fff;}#explanation {  position: absolute;  top: 330px;  left: 405px;  width: 140px;  text-align: center;  color: #666;  z-index: -1;}#percentage {  font-size: 2.3em;}
'''
with open('interactive_circle_cl.js', 'r') as myfile:
    data=myfile.read()
js_text_template2 = Template(data)
html_template = Template('''
<style> $css_text </style>
<div id="sequence"></div>
      <div id="graph-div2"></div>
        <div id="explanation" style="visibility: hidden;">
          <span id="percentage"></span><br/>
          of patients meet this criteria
        </div>
      </div>
<script> $js_text </script>
''');
js_text2 = js_text_template2.substitute({'graphdiv': 'graph-div2'});
HTML(html_template.substitute({'css_text': css_text2, 'js_text': js_text2}))
Explanation: All About: Care Setting
NOTE: 
- There is only 1 encounter that contains the value consultloc=7 (Palliative Care Unit) - it is on the third visit for this particular individual. Because there is only 1 individual with this trait, this will cause problems, so I need to collapse this category to something. After discussing with Don (7/26/16), we decided to delete this encounter.
There are only 7 encounters that contain the values consultLoc=6 (Emergency Department) - this will cause problems with modeling, from viewing individuals with this value, it seems the most appropriate level to collapse this too is consultloc=1 (Hospital - ICU ( includes MICU, SICU, TICU)). After discussing with Don (7/26/16), we decided to delete these encounters. 
It is important to note that we are dealing with a dataset of 5,066 encounters. As such, it is possible that a particular patient's care setting field (on QDACT) will change (or be different) over time. Therefore for the remainer of this notebook, we will only explore the first care setting assigned to a patient and how that correlated to their number of follow-up visits. Also, it is important to note that due to the nebulous design of this exploration, we are not adjusting for the multiple tests that follow. This could be a critique that many reviewers would have if this work is ever submitted.  
Because this is only exploratory (not confirmatory or a clincal trial), I would recommend not adjusting (and have not done so below).
Table of Contents
Follow-up Visit Distribution by Care Setting Graphic
Unadjusted Associations with Care Setting (First Visit Only)
<a id='fuvdig'></a>
Follow-up Visit Distribution by Care Setting (Interactive Graphic)
To explore the entire follow-up distribution of the CMMI population stratified by care setting, we will use an interactive graphic. Because it is interactive, it requires you to place your cursor in the first cell below (starting with 'from IPython.core.display...') and then press the play button in the toolbar above. You will need to press play 5 times. After pressing play 5 times, the interactive graphic will appear. Instructions for interpreting the graphic are given below the figure.
End of explanation
import pandas as pd
table = pd.read_csv(open('./python_scripts/11_primarydiagnosis_tables_catv2_consultLoc.csv','r'))
#Anxiety
table[0:5]
#Appetite
table[5:10]
#Constipation
table[10:15]
#Depression
table[15:20]
#Drowsiness
table[20:25]
#Nausea
table[25:30]
#Pain
table[30:35]
#Shortness
table[35:40]
#Tiredness
table[40:45]
#Well Being
table[45:50]
# PPSScore
table[50:51]
Explanation: Graphic Interpretation
The graphic above illustrates the pattern of follow-ups in the CMMI data set for each of the 1,640 unique patients. Using your cursor, you can hover over a particular color to find out the specific care setting. Each concentric circle going out from the middle represent a new follow-up visit for a person. For example, in the figure above, starting in the center, there is a red layer in the first concentric circle. If you hover over the first red circle, this says 41.8%. This means that 41.8% of the 1,640 patients reported 'Long Term Care' at their first visit. Hovering over the next layer that is black, gives a value of 7.26%. This means that 7.26% of the population had a first visit labeled as 'Long Term Care' and then had no additional visits.
Statistical Inference
I'm not sure if there is a hypothesis we want to test in relation to these two variables (i.e. Care Setting and number of follow-up visits). 
<a id='ua'></a>
Unadjusted Associations with Care Setting (First Visit Only)
In this AIM, we will look at testing the null hypothesis of no association between each row variable and the column variable (ConsultLoc). There is obviously a time aspect to this data, but for this aim, we will stick to the first encounter only.
Here is how the data is munged for this aim:
- Get the first encounter for each internalid, we start with a dataset that is 5,066 records in length and end up with a data set that is 1,640 records in length. Note: we sort data by internalid and AssessmentDate, if there is another alternative date variable we should use, please let us know. This will determine the "first visit" by sort order.
- We apply our "set-to-missing" algorithm to every variable to be analyzed. This will limit the the number of indiviudals to at least 1,618 as there are 22 who are initially missing their consultloc. We should also rerun the missing data analysis by incorporating this algorithm as it is a truer state of the data.
- This number will further be limited by running each row variable through the set-to-missing algorithm. Each row will try to be as transparent as possible about this process.
- Because this is a public server, actual data can't be posted, but the source code used to get to these results can. Here is the location to that file.
End of explanation
<END_TASK>