Programming Assignment 3: Hospital Quality

My code repository for coursera data science specialization by john hopkins university, assignment instructions.

The data for this assignment come from the Hospital Compare web site (http://hospitalcompare.hhs.gov) run by the U.S. Department of Health and Human Services. The purpose of the web site is to provide data and information about the quality of care at over 4,000 Medicare-certified hospitals in the U.S. This dataset es- sentially covers all major U.S. hospitals. This dataset is used for a variety of purposes, including determining whether hospitals should be fined for not providing high quality care to patients (see http://goo.gl/jAXFX for some background on this particular topic).

The Hospital Compare web site contains a lot of data and we will only look at a small subset for this assignment. The zip file for this assignment contains three files

  • outcome-of-care-measures.csv: Contains information about 30-day mortality and readmission rates for heart attacks, heart failure, and pneumonia for over 4,000 hospitals.
  • hospital-data.csv: Contains information about each hospital.
  • Hospital_Revised_Flatfiles.pdf: Descriptions of the variables in each file (i.e the code book).

A description of the variables in each of the files is in the included PDF file named Hospital_Revised_Flatfiles.pdf. This document contains information about many other files that are not included with this programming assignment. You will want to focus on the variables for Number 19 (“Outcome of Care Measures.csv”) and Number 11 (“Hospital Data.csv”). You may find it useful to print out this document (at least the pages for Tables 19 and 11) to have next to you while you work on this assignment. In particular, the numbers of the variables for each table indicate column indices in each table (i.e. “Hospital Name” is column 2 in the outcome-of-care-measures.csv file)

More information about the assignment here

Data zip file - link

1 Plot the 30-day mortality rates for heart attack - outcome.R

histogram for heart attack

2 Finding the best hospital in a state - best.R

Write a function called best that take two arguments: the 2-character abbreviated name of a state and an outcome name. The function reads the outcome-of-care-measures.csv file and returns a character vector with the name of the hospital that has the best (i.e. lowest) 30-day mortality for the specified outcome in that state. The hospital name is the name provided in the Hospital.Name variable. The outcomes can be one of “heart attack”, “heart failure”, or “pneumonia”. Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

3 Ranking hospitals by outcome in a state - rankhospital.R

Write a function called rankhospital that takes three arguments: the 2-character abbreviated name of a state (state), an outcome (outcome), and the ranking of a hospital in that state for that outcome (num). The function reads the outcome-of-care-measures.csv file and returns a character vector with the name of the hospital that has the ranking specified by the num argument. For example, the call rankhospital(“MD”, “heart failure”, 5) would return a character vector containing the name of the hospital with the 5th lowest 30-day death rate for heart failure. The num argument can take values “best”, “worst”, or an integer indicating the ranking (smaller numbers are better). If the number given by num is larger than the number of hospitals in that state, then the function should return NA. Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

4 Ranking hospitals in all states - rankall.R

Write a function called rankall that takes two arguments: an outcome name (outcome) and a hospital ranking (num). The function reads the outcome-of-care-measures.csv file and returns a 2-column data frame containing the hospital in each state that has the ranking specified in num. For example the function call rankall(“heart attack”, “best”) would return a data frame containing the names of the hospitals that are the best in their respective states for 30-day heart attack death rates. The function should return a value for every state (some may be NA). The first column in the data frame is named hospital, which contains the hospital name, and the second column is named state, which contains the 2-character abbreviation for the state name. Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Repository for R Programming Assignment 3: Hospital Quality

tgowda/R-Programming-Assignment-3

Folders and files, repository files navigation, r-programming-assignment-3.

Introduction Download the file ProgAssignment3-data.zip file containing the data for Programming Assignment 3 from the Coursera web site. Unzip the file in a directory that will serve as your working directory. When you start up R make sure to change your working directory to the directory where you unzipped the data. The data for this assignment come from the Hospital Compare web site ( http://hospitalcompare.hhs.gov ) run by the U.S. Department of Health and Human Services. The purpose of the web site is to provide data and information about the quality of care at over 4,000 Medicare-certified hospitals in the U.S. This dataset essentially covers all major U.S. hospitals. This dataset is used for a variety of purposes, including determining whether hospitals should be fined for not providing high quality care to patients (see http://goo.gl/jAXFX for some background on this particular topic). The Hospital Compare web site contains a lot of data and we will only look at a small subset for this assignment. The zip file for this assignment contains three files • outcome-of-care-measures.csv: Contains information about 30-day mortality and readmission rates for heart attacks, heart failure, and pneumonia for over 4,000 hospitals. • hospital-data.csv: Contains information about each hospital. • Hospital_Revised_Flatfiles.pdf: Descriptions of the variables in each file (i.e the code book). A description of the variables in each of the files is in the included PDF file named Hospital_Revised_Flatfiles.pdf. This document contains information about many other files that are not included with this programming assignment. You will want to focus on the variables for Number 19 (“Outcome of Care Measures.csv”) and Number 11 (“Hospital Data.csv”). You may find it useful to print out this document (at least the pages for Tables 19 and 11) to have next to you while you work on this assignment. In particular, the numbers of the variables for each table indicate column indices in each table (i.e. “Hospital Name” is column 2 in the outcome-of-care-measures.csv file).

Submitted code is in the following files

rankhospital.R

source(" http://d396qusza40orc.cloudfront.net/rprog%2Fscripts%2Fsubmitscript3.R ")

  • [Programming Assignment 3] R Programming
  • by Anderson Hitoshi Uyekita
  • Last updated over 2 years ago
  • Hide Comments (–) Share Hide Toolbars

Twitter Facebook Google+

Or copy & paste this link into an email or IM:

R Programming Assignment 3: Hospital Quality

Introduction.

Download the file ProgAssignment3-data.zip file containing the data for Programming Assignment 3 from the Coursera web site. Unzip the file in a directory that will serve as your working directory. When you start up R make sure to change your working directory to the directory where you unzipped the data.

The data for this assignment come from the Hospital Compare web site ( http://hospitalcompare.hhs.gov ) run by the U.S. Department of Health and Human Services. The purpose of the web site is to provide data and information about the quality of care at over 4,000 Medicare-certified hospitals in the U.S. This dataset essentially covers all major U.S. hospitals. This dataset is used for a variety of purposes, including determining whether hospitals should be fined for not providing high quality care to patients (see http://goo.gl/jAXFX for some background on this particular topic).

The Hospital Compare web site contains a lot of data and we will only look at a small subset for this assignment. The zip file for this assignment contains three files:

  • outcome-of-care-measures.csv : Contains information about 30-day mortality and readmission rates for heart attacks, heart failure, and pneumonia for over 4,000 hospitals.
  • hospital-data.csv : Contains information about each hospital.
  • Hospital_Revised_Flatfiles.pdf : Descriptions of the variables in each file (i.e the code book).

A description of the variables in each of the files is in the included PDF file named Hospital_Revised_Flatfiles.pdf . This document contains information about many other files that are not included with this programming assignment. You will want to focus on the variables for Number 19 (“Outcome of Care Measures.csv”) and Number 11 (“Hospital Data.csv”). You may find it useful to print out this document (at least the pages for Tables 19 and 11) to have next to you while you work on this assignment. In particular, the numbers of the variables for each table indicate column indices in each table (i.e. “Hospital Name” is column 2 in the outcome-of-care-measures.csv file).

Part 1: Plot the 30-day mortality rates for heart attack

Read the outcome data into R via the read.csv function and look at the first few rows.

There are many columns in this dataset. You can see how many by typing ncol(outcome) (you can see the number of rows with the nrow function). In addition, you can see the names of each column by typing names(outcome) (the names are also in the PDF document).

To make a simple histogram of the 30-day death rates from heart attack (column 11 in the outcome dataset), run

Because we originally read the data in as character (by specifying colClasses = “character” we need to coerce the column to be numeric. You may get a warning about NAs being introduced but that is okay.

There is nothing to submit for this part.

Part 2: Finding the best hospital in a state

Write a function called best that take two arguments: the 2-character abbreviated name of a state and an outcome name. The function reads the outcome-of-care-measures.csv file and returns a character vector with the name of the hospital that has the best (i.e. lowest) 30-day mortality for the specified outcome in that state. The hospital name is the name provided in the Hospital.Name variable. The outcomes can be one of “heart attack”, “heart failure”, or “pneumonia”. Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

Handling ties. If there is a tie for the best hospital for a given outcome, then the hospital names should be sorted in alphabetical order and the first hospital in that set should be chosen (i.e. if hospitals “b”, “c”, and “f” are tied for best, then hospital “b” should be returned).

The function should use the following template.

The function should check the validity of its arguments. If an invalid state value is passed to best , the function should throw an error via the stop function with the exact message “invalid state”. If an invalid outcome value is passed to best , the function should throw an error via the stop function with the exact message “invalid outcome”.

Here is some sample output from the function.

Save your code for this function to a file named best.R .

Part 3: Ranking hospitals by outcome in a state

Write a function called rankhospital that takes three arguments: the 2-character abbreviated name of a state ( state ), an outcome ( outcome ), and the ranking of a hospital in that state for that outcome ( num ). The function reads the outcome-of-care-measures.csv file and returns a character vector with the name of the hospital that has the ranking specified by the num argument. For example, the call

would return a character vector containing the name of the hospital with the 5th lowest 30-day death rate for heart failure. The num argument can take values “best”, “worst”, or an integer indicating the ranking (smaller numbers are better). If the number given by num is larger than the number of hospitals in that state, then the function should return NA . Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

Handling ties . It may occur that multiple hospitals have the same 30-day mortality rate for a given cause of death. In those cases ties should be broken by using the hospital name. For example, in Texas (“TX”), the hospitals with lowest 30-day mortality rate for heart failure are shown here.

Note that Cypress Fairbanks Medical Center and Detar Hospital Navarro both have the same 30-day rate (8.7). However, because Cypress comes before Detar alphabetically, Cypress is ranked number 3 in this scheme and Detar is ranked number 4. One can use the order function to sort multiple vectors in this manner (i.e. where one vector is used to break ties in another vector).

The function should check the validity of its arguments. If an invalid state value is passed to rankhospital , the function should throw an error via the stop function with the exact message “invalid state”. If an invalid outcome value is passed to rankhospital , the function should throw an error via the stop function with the exact message “invalid outcome”.

Save your code for this function to a file named rankhospital.R .

Part 4: Ranking hospitals in all states

Write a function called rankall that takes two arguments: an outcome name ( outcome ) and a hospital ranking ( num ). The function reads the outcome-of-care-measures.csv file and returns a 2-column data frame containing the hospital in each state that has the ranking specified in num . For example the function call rankall(“heart attack”, “best”) would return a data frame containing the names of the hospitals that are the best in their respective states for 30-day heart attack death rates. The function should return a value for every state (some may be NA ). The first column in the data frame is named hospital , which contains the hospital name, and the second column is named state , which contains the 2-character abbreviation for the state name. Hospitals that do not have data on a particular outcome should be excluded from the set of hospitals when deciding the rankings.

Handling ties . The rankall function should handle ties in the 30-day mortality rates in the same way that the rankhospital function handles ties.

NOTE : For the purpose of this part of the assignment (and for efficiency), your function should NOT call the rankhospital function from the previous section.

The function should check the validity of its arguments. If an invalid outcome value is passed to rankall , the function should throw an error via the stop function with the exact message “invalid outcome”. The num variable can take values “best”, “worst”, or an integer indicating the ranking (smaller numbers are better). If the number given by num is larger than the number of hospitals in that state, then the function should return NA .

Save your code for this function to a file named rankall.R .

My Solution

A good tutorial.

Link: https://github.com/DanieleP/PA3-tutorial

xmuxiaomo

  • 1. Introduction
  • 2. Part 1: Plot the 30-day mortality rates for heart attack
  • 3. Part 2: Finding the best hospital in a state
  • 4. Part 3: Ranking hospitals by outcome in a state
  • 5. Part 4: Ranking hospitals in all states
  • 6. My Solution
  • 8. A Good Tutorial

IMAGES

  1. Programming Assignment 3 Instructions Hospital Quality

    r programming assignment 3 hospital quality

  2. GitHub

    r programming assignment 3 hospital quality

  3. Programming Assignment 3 Instructions Hospital Quality

    r programming assignment 3 hospital quality

  4. Programming Assignment 3 Instructions Hospital Quality

    r programming assignment 3 hospital quality

  5. Programming Assignment 3 Instructions Hospital Quality

    r programming assignment 3 hospital quality

  6. Programming Assignment 3 Instructions Hospital Quality

    r programming assignment 3 hospital quality

VIDEO

  1. Your small act of kindness can made someone's festival good 🥺❤ #story #shorts

  2. 6. Week

  3. Dependency & Static Level 2|Assignment Set-3|Object Oriented Programming Using Python|NM|Infosys

  4. Programming Assignment 3 COP3330

  5. Overview of extemporaneous preparations at community d pharmacy assignment 1st year pharmaceutics

  6. Intro to R for Public Health