Question: POSIT CLOUD POSIT CLOUD POSIT CLOUD library ( tidyverse ) library ( DBI ) library ( RSQLite ) library ( treemapify ) tbl _ explore
POSIT CLOUD
POSIT CLOUD
POSIT CLOUD
librarytidyverse
libraryDBI
libraryRSQLite
librarytreemapify
tblexplore functiontblname
myquery pasteSELECT FROM",tblname
printmyquery
dbGetQuerymydbmyquery
glimpse
# Instructions
mydb dbConnectRSQLite::SQLite "MIMICIII.db
#Database Investigation Functions
dbListTablesmydb
dbListFieldsmydb "ADMISSIONS"
##The MIMICIII simulates a real healthcarebased Electronic Medical
##Record System similar to what would be used in a real hospital.
##This homework will provide you a chance to use the skills you have
##learned in an unfamiliar, realworld data environment.
##Here is an example query pulling some sample demographic information
##from the patients table. Notice how similar it is to what you have done
##previously. Only the table and field names have changed.
dbGetQuerymydb 'SELECT subjectid gender
FROM PATIENTS'
##Another example where I query the database and then plot the
##genders of patients with ggplot. Again, notice the similarities.
myquery 'SELECT subjectid gender FROM PATIENTS'
ggplotdata dbGetQuerymydbmyquery
aesgender
geombar
# Homework
##AFTER FILLING IN YOUR ANSWERS, COPY AND PASTE THE
##SCRIPT INTO THE PROVIDED MOODLE DROPBOX.
##Create a SQL query that will pull the names of Fentanyl family drugs
##That is drugs that include the name "Fent" or something similar
##from the prescriptions table. Create a bar chart of this data.
##Your bar chart should clearly show
##which form of Fentanyl is most often prescribed if you have
#created it correctly.
myquery
dbGetQuerymydbmyquery
##Create a select statement that will pull the gender and insurance
##of patients admitted to the hospital from the tables that have this data
##Im not telling you which tables they are, but I will tell you the information
##is on two different tables. So a join is necessary and the join key is subjectid
#Once you are happy with your SQL query, use ggplot to create a stacked bar chart showing
#the insurance data with fill gender.
myquery
dbGetQuerymydbmyquery
#Join the patients and icustays tables so that you can select
#the dodhosp date of death in the hospital and firstcareunit.
#group the data by firstcareunit and count the number of
#dodhosp to see how many people have died in ONLY
#the CCU, MICU and SICU firstcareunits.
#graph this information using a geomcol
myquery
dbGetQuerymydbmyquery
#Create a SQL query using the PRESCRIPTIONS
#table that will provide what you believe is sufficient data to create
#a useful summary of all the prescriptions ever
#prescribed to the patient with ID
#When you're happy with your query, save it to a variable
#called "patienthistory". You can then click on patient history in the
#environment window to see your report.
myquery
patienthistory dbGetQuerymydb myquery
##Create a custom query of your own using a JOIN, a GROUP BY
##and graphing your output in some way.
myquery
dbGetQuerymydb myquery
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
