Question: POSIT CLOUD POSIT CLOUD POSIT CLOUD library ( tidyverse ) library ( DBI ) library ( RSQLite ) library ( treemapify ) tbl _ explore

POSIT CLOUD
POSIT CLOUD
POSIT CLOUD
library(tidyverse)
library(DBI)
library(RSQLite)
library(treemapify)
tbl_explore <- function(tbl_name){
myquery <- paste("SELECT * FROM",tbl_name)
print(myquery)
dbGetQuery(mydb,myquery)|>
glimpse()
}
# Instructions ------------------------------------------------------------
mydb <- dbConnect(RSQLite::SQLite(), "MIMIC-III.db")
#Database Investigation Functions
dbListTables(mydb)
dbListFields(mydb, "ADMISSIONS")
##The MIMIC-III simulates a real healthcare-based 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, real-world 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.
dbGetQuery(mydb, 'SELECT subject_id, 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 subject_id, gender FROM PATIENTS'
ggplot(data = dbGetQuery(mydb,myquery),
aes(gender))+
geom_bar()
# 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.
myquery1<-''
dbGetQuery(mydb,myquery1)
##Create a select statement that will pull the gender and insurance
##of patients admitted to the hospital from the tables that have this data
##(I'm 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 subject_id).
#Once you are happy with your SQL query, use ggplot to create a stacked bar chart showing
#the insurance data with fill = gender.
myquery2<-''
dbGetQuery(mydb,myquery2)
#Join the patients and icustays tables so that you can select
#the dod_hosp (date of death in the hospital) and first_careunit.
#group the data by first_careunit and count the number of
#dod_hosp to see how many people have died in ONLY
#the CCU, MICU and SICU first_careunits.
#graph this information using a geom_col().
myquery3<-''
dbGetQuery(mydb,myquery3)
#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 =10032.
#When you're happy with your query, save it to a variable
#called "patient_history". You can then click on patient history in the
#environment window to see your report.
myquery4<-''
patient_history <- dbGetQuery(mydb, myquery4)
##Create a custom query of your own using a JOIN, a GROUP BY
##and graphing your output in some way.
myquery5<-''
dbGetQuery(mydb, myquery5)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!