2024-04-04

Evaluate Data

##   Age Sex ChestPainType RestingBP Cholesterol FastingBS RestingECG MaxHR
## 1  40   1             1       140         289         0          0   172
## 2  49   0             2       160         180         0          0   156
## 3  37   1             1       130         283         0          1    98
## 4  48   0             3       138         214         0          0   108
## 5  54   1             2       150         195         0          0   122
## 6  39   1             2       120         339         0          0   170
##   ExerciseAngina Oldpeak HeartDisease
## 1              0     0.0            0
## 2              0     1.0            1
## 3              0     0.0            0
## 4              1     1.5            1
## 5              0     0.0            0
## 6              0     0.0            0

Visualize Data Set

Visualize Data Set 2

Difference in Means Equation

filter(HeartDisease == "1")

\(HeartDisease_{mean} = \frac{Sum(Cholesterol)}{sum(HeartDisease)}\)

filter(HeartDisease == "0")

\(NoHeartDisease_{mean} = \frac{Sum(Cholesterol)}{sum(NoHeartDisease)}\)

Difference in Means = 

\(HeartDisease_{mean} - NoHeartDisease_{mean}\)

point estimate/observed statistic

difference in mean cholesterol levels =

df %>%

  specify(formula = Cholesterol ~ HeartDisease) %>%

  calculate(stat = "diff in means", 
  order = c("Heart Disease", "No Heart Disease"))
## Response: Cholesterol (numeric)
## Explanatory: HeartDisease (factor)
## # A tibble: 1 × 1
##    stat
##   <dbl>
## 1 0.496

The difference in average cholesterol levels between patients with and without heart disease is 0.496.

Run Hypothesis Test

Null distribution is created by generating samples using replicated data that is shuffled.

Null Distribution Visualization

scatter plot with null distribution

P-value Equation

P-value is calculated by comparing the generated samples to the observed statistic(difference in means of cholesterol levels). A two-tailed p-value is calculated by finding the percentage of samples that fall into the range of the absolute value of the point estimate.

Observed Statistic(point estimate) = 0.496

X = Sum of replicates with stat variable: \[-0.496 < stat < 0.496\]

Y = Sum of replicates with stat variable: \[stat > 0.496 || stat < -0.496\]

\[ Pvalue = \frac{X}Y \]

analyzing P-value

P-values range from 0-1 and represent the percent chance that a test statistic will be as or more extreme than the observed statistic

## # A tibble: 1 × 1
##   p_value
##     <dbl>
## 1   0.929

A higher P value means we can’t reject the null hypothesis that cholesterol levels aren’t dependent on heart disease. This means that heart disease probably has no effect on cholesterol levels for samples in our data set.