-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescriptiveAnalysis.R
133 lines (97 loc) · 2.53 KB
/
DescriptiveAnalysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Case study on surveillance data analysis; cryptosporidosis
# Lore Merdrignac and Esther Kissling
# EpiConcept
# Created Oct 2016, revised July 2018
# R-code written by Alexander Spina September 2018
#### Reading in datasets ####
# load your dataset
load("crypto.Rda")
#### Focusing on 2015 data ####
# assign your 2015 subset to crypto (over-write original crypto)
crypto <- subset(
x = crypto,
subset = year == 2015
)
#### What is the number of cases for 2015? ####
# check number of rows in your dataset
nrow(crypto)
#### Describing age ####
# Plot a histogram of age
# you can specify a bar for each age with "breaks"
# you can set your x axis from 0-100 using "xlim"
hist(crypto$age,
xlab = "Age",
ylab = "Count",
breaks = 100,
xlim = c(0, 100)
)
# Get a summary of age
summary(crypto$age)
# Plot a histogram of age by sex
# specify you want one row of two histograms
par(mfrow = c(1,2))
# plot a histogram for males (use squarebrackets to subset)
# give a title using "main",
# set the y axis limits using ylim
hist(crypto$age[crypto$sex == "male"],
main = "male",
xlab = "Age",
ylab = "Count",
breaks = 100,
xlim = c(0, 100),
ylim = c(0, 50) )
# plot a histogram for females
hist(crypto$age[crypto$sex == "female"],
main = "female",
xlab = "Age",
ylab = "Count",
breaks = 100,
xlim = c(0, 100),
ylim = c(0, 40) )
#### Describing sex ####
# get counts of sex
# save table as "counts"
counts <- table(crypto$sex)
# get proportions for counts table
prop.table(counts)
# you could also multiple by 100 and round to 2 digits
round(
prop.table(counts)*100,
digits = 2
)
#### Describing hospitalised ####
# get counts of hospitalisations
# save table as "counts"
counts <- table(crypto$hospitalised)
# get rounded proportions of counts
round(
prop.table(counts)*100,
digits = 2
)
# get counts of hospitalisations by agegroup
# save table as "counts"
counts <- table(crypto$ar_age, crypto$hospitalised)
# get rounded proportions of counts
# specify that you want row proportions (margin = 1)
round(
prop.table(counts, margin = 1) * 100,
digits = 2
)
#### Describe urban ####
#get counts
#save table as "counts"
counts <- table(crypto$urban)
#get rounded proportions of counts
round(
prop.table(counts)*100,
digits = 2
)
#### Describe imported ####
#get counts
#save table as "counts"
counts <- table(crypto$imported)
#get rounded proportions of counts
round(
prop.table(counts)*100,
digits = 2
)