This document tries to compare the mean payment for a heart attack and tests it statistically

library(dplyr, warn=F)
library(tidyr)
library(DT)
library(readr)
library(ggplot2)
auto = mtcars[mtcars$am ==0,]$mpg
man = mtcars[mtcars$am==1,]$mpg
t.test(man,auto)##t test for difference of two independent means
## 
##  Welch Two Sample t-test
## 
## data:  man and auto
## t = 3.7671, df = 18.332, p-value = 0.001374
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   3.209684 11.280194
## sample estimates:
## mean of x mean of y 
##  24.39231  17.14737

Data is from data.gov and the dataset analysed is the payment for heart-attack data

##payment of heart attack data from data.gov
heart = read_csv('heartattack.csv')
## Warning: 387 problems parsing 'heartattack.csv'. See problems(...) for more
## details.
##removing dollar sign
heart$Payment = sapply(heart$Payment, function(x)gsub('\\$', '', x))
heart$Payment = as.numeric(heart$Payment)
##replacing missing values with mean
heart$Payment[is.na(heart$Payment)] = mean(heart$Payment, na.rm=T)

kent = heart %>% filter(State=="KY")##for kentucky

ohio = heart %>% filter(State=="OH")##ohio

Comparing the mean payment for heart attack between Kentucky and Ohio(unpaired t test)

##unpaired t test on payment in ohio and kentucky
t.test(ohio$Payment, kent$Payment )
## 
##  Welch Two Sample t-test
## 
## data:  ohio$Payment and kent$Payment
## t = 3.7199, df = 590.64, p-value = 0.0002183
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   398.7025 1290.5775
## sample estimates:
## mean of x mean of y 
##  16972.39  16127.75
##or alternatively
ohkent = rbind(ohio, kent)

t.test(Payment ~ State, data=ohkent)
## 
##  Welch Two Sample t-test
## 
## data:  Payment by State
## t = -3.7199, df = 590.64, p-value = 0.0002183
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1290.5775  -398.7025
## sample estimates:
## mean in group KY mean in group OH 
##         16127.75         16972.39

Conclusion: the difference of payment for ohio and kentucy is not zero