library(readxl)
dataset <- read_excel("dataset.xlsx")
## New names:
## • `` -> `...4`
summary(dataset[,c("Observed Deaths","Expected Deaths","Potentially excess deaths")])
##  Observed Deaths  Expected Deaths   Potentially excess deaths
##  Min.   :  16.0   Min.   :   6.00   Min.   :   5.00          
##  1st Qu.: 177.2   1st Qu.:  68.75   1st Qu.:  93.25          
##  Median : 499.5   Median : 224.50   Median : 249.00          
##  Mean   : 862.1   Mean   : 470.65   Mean   : 391.48          
##  3rd Qu.:1391.5   3rd Qu.: 711.75   3rd Qu.: 617.25          
##  Max.   :4217.0   Max.   :2785.00   Max.   :1453.00
dataset$`Observed Deaths`-dataset$`Expected Deaths`
##  [1]  247  177   69  549  402  147  943  690  253 1432 1046  386  372  279   94
## [16]  594  450  143  994  779  215 1453 1117  336   56   40   17  119   85   34
## [31]  251  182   68  457  322  134   53   47    5   91   80   11  145  113   32
## [46]  229  172   57  821  603  218  893  660  233 1012  750  262 1035  767  268
hist(dataset$`Observed Deaths`-dataset$`Expected Deaths`, main="Histogram of number of deaths for all diseases",col="blue",xlab ="paired differences")

boxplot(dataset$`Observed Deaths`-dataset$`Expected Deaths`,main="Boxplot of number of deaths over all diseases",col="blue")

qqnorm(dataset$`Observed Deaths`-dataset$`Expected Deaths`,pch=19,frame=FALSE)
qqline(dataset$`Observed Deaths`-dataset$`Expected Deaths`, col="blue",lwd=3)

t.test(dataset$`Observed Deaths`,dataset$`Expected Deaths`,paired=T)
## 
##  Paired t-test
## 
## data:  dataset$`Observed Deaths` and dataset$`Expected Deaths`
## t = 8.0458, df = 59, p-value = 4.578e-11
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  294.1214 488.8453
## sample estimates:
## mean difference 
##        391.4833

Barplot for Metro diseases

Metro_percent=c(136.5,201.3,251,207.7,193.4)
names(Metro_percent)=c("Cancer","Heart Disease","Respiratory","Stroke","Unintentional Injury")
barplot(Metro_percent,col="blue",ylab="percentage",main="Barplot of Excess Deaths by Disease in Metropolitian Areas")

barplot(Metro_percent,col=c("yellow","blue","pink","green","orange"),main="Barplot of Excess Deaths by Disease in Metropolitian Areas",ylab="percentage")

Piechart for Metro diseases

pie(Metro_percent,main="Piechart of Excess Deaths by Disease in Metropolitian Areas")

pie(Metro_percent,col=c("yellow","blue","pink","green","orange"))

Barplot for NonMetro diseases

Nonmetro_percent=c(160.2,202.3,281.4,168.8,220)
names(Nonmetro_percent)=c("Cancer","Heart Disease","Respiratory","Stroke","Unintentional Injury")
barplot(Nonmetro_percent,col="blue",ylab="percentage",main="Barplot of Excess Deaths by Disease in Non-Metropolitian Areas")

barplot(Nonmetro_percent,col=c("yellow","blue","pink","green","orange"),main="Barplot of Excess Deaths by Disease in Non-Metropolitian Areas",ylab="percentage")

Piechart for NonMetro diseases

pie(Nonmetro_percent,main="Piechart of Excess Deaths by Disease in Non-Metropolitian Areas")

pie(Nonmetro_percent,col=c("yellow","blue","pink","green","orange"))

Side by side barcharts

par(mfrow=c(1,2))
barplot(Metro_percent,ylab="percentage",main="Metro",col=c("yellow","blue","pink","green","orange"))
barplot(Nonmetro_percent,ylab="percentage",main="Non-Metro",col=c("yellow","blue","pink","green","orange"))

side by side pie charts

par(mfrow=c(1,2))
pie(Metro_percent,main="Metro",col=c("yellow","blue","pink","green","orange"))
pie(Nonmetro_percent,main="Non-Metro",col=c("yellow","blue","pink","green","orange"))

2 way table

tableA=matrix(c(136.5,201.3,251,207.7,193.4,160.2,202.3,281.4,168.8,220),nrow=2,byrow=TRUE)
rownames(tableA)=c("Metro","Nonmetro")
colnames(tableA)=c("Cancer","Heart Disease","Respiratory","Stroke","Uintentional")
tableA
##          Cancer Heart Disease Respiratory Stroke Uintentional
## Metro     136.5         201.3       251.0  207.7        193.4
## Nonmetro  160.2         202.3       281.4  168.8        220.0
barplot(tableA,beside=TRUE,legend=T,col=c("purple","lightblue"),main="Disease information by Locality")

barplot(as.matrix(tableA),col=c("purple","lightblue"),legend=T,main="Disease information by locality")

chi-square

test_a=chisq.test(tableA)
test_a
## 
##  Pearson's Chi-squared test
## 
## data:  tableA
## X-squared = 8.4603, df = 4, p-value = 0.0761
test_a$expected
##            Cancer Heart Disease Respiratory   Stroke Uintentional
## Metro    145.2108      197.5297     260.567 184.2665      202.326
## Nonmetro 151.4892      206.0703     271.833 192.2335      211.074

This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.