oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Heart Disease Research Part 1 #460

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

In this project, you'll investigate some data from a sample patients who were evaluated for heart disease at the Cleveland Clinic Foundation. The data was downloaded from the UCI Machine Learning Repository and then cleaned for analysis.

oldoc63 commented 1 year ago

Cholesterol Analysis

  1. The full dataset has been loaded as heart, then split into two subsets:

    • yes_hd, which contains data for patients with heart disease
    • no_hd, which contains data for patients without heart disease
  2. For this project, we'll investigate the following variables:

    • chol: serum cholesterol in mg/dl
    • fbs: An indicator for whether fasting blood sugar is greater than 120 mg/dl (1=true; 0=false).
  3. To start, we'll investigate cholesterol levels for patients with heart disease. Use the dataset yes_hd to save cholesterol levels for patients with heart disease as a variable named chol_hd.

oldoc63 commented 1 year ago
  1. In general, total cholesterol over 240 mg/dl is considered 'high' (and therefore unhealthy). Calculate the mean cholesterol level for patients who were diagnosed with heart disease and print it out. Is it higher than 240 mg/dl?
oldoc63 commented 1 year ago
  1. Do people with heart disease have high cholesterol levels (greater than or equal to 240 mg/dl) on average? Import the function from scipy.stats that you can use to test the following null and alternative hypotheses:

    • Null: People with heart disease have an average cholesterol level equal to 240 mg/dl
    • Alternative: People with heart disease have an average cholesterol level that is greater than 240 mg/dl
  2. Unfortunately, the scipy.stats function we've been using does not have an alternative parameter to change the alternative hypothesis for this test. Therefore, you'll have to run a two-sided test. However, since you calculated earlier that the average cholesterol level for heart disease patients is greater than 240 mg/dl, you can calculate the value for the one-sided test indicated above simply by dividing the two-sided p-value in half.

  3. Run the hypothesis test indicated and print out the p-value. Can you conclude that heart disease patients have an average cholesterol level significantly greater than 240 mg/dl? Use a significance threshold of 0.05.

oldoc63 commented 1 year ago
  1. Run the same hypothesis test, but for patients in the sample who were not diagnosed with heart disease. Do patients without heart disease have average cholesterol levels significantly above 240 mg/dl?
oldoc63 commented 1 year ago

Fasting Blood Sugar Analysis

  1. Let's now return to the full dataset (saved as heart). How many patients are there in this dataset? Save the number of patients as num_patients and print it out.
oldoc63 commented 1 year ago
  1. Remember that the fbs column of this dataset indicates whether or not a patient's fasting blood sugar was greater than 120 mg/dl (1 means that their fasting blood sugar was greater than 120 mg/dl; 0 means it was less than or equal to 120 mg/dl). Calculate the number of patients with fasting blood sugar greater than 120. Save this number as num_highfbs_patients and print it out.
oldoc63 commented 1 year ago
  1. Sometimes, part of an analysis will involve comparing a sample to known population values to see if the sample appears to be representative of the general population. By some estimates, about 8% of the U.S. population had diabetes (diagnosed or undiagnosed) in 1988 when this data was collected. While there are multiple tests that contribute to a diabetes diagnosis, fasting blood sugar levels greater than 120 mg/dl can be indicative of diabetes (or at least, prediabetes). If this sample were representative of the population, approximately how many people would you expect to have diabetes? Calculate and print out this number. Is this value similar to the number of patients with a resting blood sugar above 120 mg/dl -or different?
oldoc63 commented 1 year ago
  1. We want to calculate 8% of the sample size (which is 303). Therefore, we should multiply 0.08*303. This comes out to approximately 24 patients, which is almost half the number with fbs > 120 in the sample (45).
oldoc63 commented 1 year ago
  1. Does this sample come from a population in which the rate of fbs > 120 mg/dl is equal to 8%? Import the function from scipy.stats that you can use to test the followin null and alternative hypotheses:

    Null: This sample was drawn from a population where 8% of people have fasting blood sugar > 120 mg/dl

    Alternative: This sample was drawn from a population where more than 8% of people have fasting blood sugar > 120 mg/dl.

oldoc63 commented 1 year ago
  1. Run the hypothesis test indicated in task 9 and print out the p-value. Using a significance threshold of 0.05, can you conclude that this sample was drawn from a population where the rate of fasting blood sugar > 120 mg/dl is significantly greater than 8%?
oldoc63 commented 1 year ago
  1. The binom_test() function takes four parameters (in order):
    • The observed number of "successes" (in this case, the number of people in the sample who had fasting blood sugar greater than 120 mg/dl)
    • The number of "trials" (in this case, the number of patients)
    • The null probability of "success" (in this case, 0.08)
    • The alternative parameter, which indicates the alternative hypothesis for the test (eg., two-sided, greater or less)
    • The output is the p-value
oldoc63 commented 1 year ago
  1. If you run the test correctly, you should get a p-value of 4.689471951449078e-05 which is equivalent to 0.0000469 (the e-5 at the end indicates scientific notation). This is less than 0.05, indicating that this sample likely comes from a population where more than 8% of people have fbs > 120 mg/dl.