### Exercise - Insurance -
## Load the health insurance dataset from https://cbdm.uni-mainz.de/mb16/
#
Patients <- read.delim("https://cbdm.uni-mainz.de/files/2016/02/Patients.txt")
View(Patients)
# Have a look at the data in "Patients"
# plot them from different perspektives and create a summary over the two Variables "Age" and "Contribution"
##
# Now you'd like to plot a histogram of age with a self-chosen partitioning.
# Please choose the following breakpoints
# 0,5,10,15,...,100
# hint: help(seq)
# help(hist) -> check here the information about "breaks"
#and compare the outcome to the German population census data
## from http://www.indexmundi.com/germany/age_structure.html
# is the sample representative ?
## Load the data "Claims" and "Fever" from https://cbdm.uni-mainz.de/mb16/
#Have a look at the data in "Claims"
# Claims per Patient and Month for one year
# Change the Column-Names to show that V1-V12 are the 12 Month
## Plot the claims from January
## Plot the sorted claims # hint: help("sort")
##### Plot the claims from patient Nr 1 over the whole year ######
# extract the first row from the table
#remove row-Numbers
d<-data.matrix(Claim_P1, rownames.force = NA)
#### Make the plot nicer (add lines between the points and add labels to the axes) ##
# hint: "help(plot)" and "help(title)"
## Plot a histogram of the Claims in January
# hint: indexing a matrix via (i,j) while "i" is the row and "j" is the column.
hist(Claims[1:1000,1])
# add the x-label : "Claims in Euro" hint: "xlab".
## Plot a Histogram of the Claims in August
# Plot a Histogram of the total Claims per month over the whole year
# hint: "help(apply)"
row.sums_Claims <- apply(Claims, 1, sum)
col.sums_Claims <- apply(Claims, 2, sum)
## Create a bar-plot for the monthly claims
barplot(col.sums_Claims)
##### Now have a look at the data in "Fever" ########
# Fever per Patient and Month for one year
# Change the Column-Names to show that V1-V12 are the 12 Month
colnames(Fever) <- c("Jan", "Feb", "March", "April","May","June","July","Aug","Sept","Oct","Nov","Dec")
summary(Fever)
## Plot the claims from January
## Plot the sorted claims # hint: help("sort")
## recode -99 to missing (NA) in table Fever
Fever[Fever==-99]<-NA
Fever
## How many patients had Fever in January ?
## Create a bar-plot for the monthly report of fever
a) # All patients having fever per month
b) ## All events of having fever over the year per patient over the year
##### Plot the Fever-Curve from patient Nr 5 over the whole year ######
# extract the row Nr. 5 from the table
##### Plot the Claims-Curve from patient Nr 5 over the whole year ######
# extract the row Nr. 5 from the table
#### Plot both curves together in one figure
# Hint: use par(mfrow=c(2,1))