Inflammation Dataset Analysis

This is based on the Carpentries lesson on R Programming

#Loading Data

read.csv(file = "data/inflammation-01.csv", header = FALSE)
##    V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
## 1   0  0  1  3  1  2  4  7  8   3   3   3  10   5   7   4   7   7  12  18   6
## 2   0  1  2  1  2  1  3  2  2   6  10  11   5   9   4   4   7  16   8   6  18
## 3   0  1  1  3  3  2  6  2  5   9   5   7   4   5   4  15   5  11   9  10  19
## 4   0  0  2  0  4  2  2  1  6   7  10   7   9  13   8   8  15  10  10   7  17
## 5   0  1  1  3  3  1  3  5  2   4   4   7   6   5   3  10   8  10   6  17   9
## 6   0  0  1  2  2  4  2  1  6   4   7   6   6   9   9  15   4  16  18  12  12
## 7   0  0  2  2  4  2  2  5  5   8   6   5  11   9   4  13   5  12  10   6   9
## 8   0  0  1  2  3  1  2  3  5   3   7   8   8   5  10   9  15  11  18  19  20
## 9   0  0  0  3  1  5  6  5  5   8   2   4  11  12  10  11   9  10  17  11   6
## 10  0  1  1  2  1  3  5  3  5   8   6   8  12   5  13   6  13   8  16   8  18
## 11  0  1  0  0  4  3  3  5  5   4   5   8   7  10  13   3   7  13  15  18   8
## 12  0  1  0  0  3  4  2  7  8   5   2   8  11   5   5   8  14  11   6  11   9
## 13  0  0  2  1  4  3  6  4  6   7   9   9   3  11   6  12   4  17  13  15  13
## 14  0  0  0  0  1  3  1  6  6   5   5   6   3   6  13   3  10  13   9  16  15
## 15  0  1  2  1  1  1  4  1  5   2   3   3  10   7  13   5   7  17   6   9  12
## 16  0  1  1  0  1  2  4  3  6   4   7   5   5   7   5  10   7   8  18  17   9
## 17  0  0  0  0  2  3  6  5  7   4   3   2  10   7   9  11  12   5  12   9  13
## 18  0  0  0  1  2  1  4  3  6   7   4   2  12   6  12   4  14   7   8  14  13
## 19  0  0  2  1  2  5  4  2  7   8   4   7  11   9   8  11  15  17  11  12   7
## 20  0  1  2  0  1  4  3  2  2   7   3   3  12  13  11  13   6   5   9  16   9
## 21  0  1  1  3  1  4  4  1  8   2   2   3  12  12  10  15  13   6   5   5  18
## 22  0  0  2  3  2  3  2  6  3   8   7   4   6   6   9   5  12  12   8   5  12
## 23  0  0  0  3  4  5  1  7  7   8   2   5  12   4  10  14   5   5  17  13  16
## 24  0  1  1  1  1  3  3  2  6   3   9   7   8   8   4  13   7  14  11  15  14
## 25  0  1  1  1  2  3  5  3  6   3   7  10   3   8  12   4  12   9  15   5  17
## 26  0  0  2  1  3  3  2  7  4   4   3   8  12   9  12   9   5  16   8  17   7
## 27  0  0  1  2  4  2  2  3  5   7  10   5   5  12   3  13   4  13   7  15   9
## 28  0  0  1  1  1  5  1  5  2   2   4  10   4   8  14   6  15   6  12  15  15
## 29  0  0  2  2  3  4  6  3  7   6   4   5   8   4   7   7   6  11  12  19  20
## 30  0  0  0  1  4  4  6  3  8   6   4  10  12   3   3   6   8   7  17  16  14
## 31  0  1  1  0  3  2  4  6  8   6   2   3  11   3  14  14  12   8   8  16  13
## 32  0  0  2  3  3  4  5  3  6   7  10   5  10  13  14   3   8  10   9   9  19
## 33  0  1  2  2  2  3  6  6  6   7   6   3  11  12  13  15  15  10  14  11  11
## 34  0  0  2  1  3  5  6  7  5   8   9   3  12  10  12   4  12   9  13  10  10
## 35  0  0  1  2  4  1  5  5  2   3   4   8   8  12   5  15   9  17   7  19  14
## 36  0  0  0  3  1  3  6  4  3   4   8   3   4   8   3  11   5   7  10   5  15
## 37  0  1  2  2  2  5  5  1  4   6   3   6   5   9   6   7   4   7  16   7  16
## 38  0  1  1  2  3  1  5  1  2   2   5   7   6   6   5  10   6   7  17  13  15
## 39  0  1  0  3  2  4  1  1  5   9  10   7  12  10   9  15  12  13  13   6  19
## 40  0  1  1  3  1  1  5  5  3   7   2   2   3  12   4   6   8  15  16  16  15
## 41  0  0  0  2  2  1  3  4  5   5   6   5   5  12  13   5   7   5  11  15  18
## 42  0  0  1  3  3  1  2  1  8   9   2   8  10   3   8   6  10  13  11  17  19
## 43  0  1  1  3  4  5  2  1  3   7   9   6  10   5   8  15  11  12  15   6  12
## 44  0  0  1  3  1  4  3  6  7   8   5   7  11   3   6  11   6  10   6  19  18
## 45  0  1  1  3  3  4  4  6  3   4   9   9   7   6   8  15  12  15   6  11   6
## 46  0  1  2  2  4  3  1  4  8   9   5  10  10   3   4   6   7  11  16   6  14
## 47  0  0  2  3  4  5  4  6  2   9   7   4   9  10   8  11  16  12  15  17  19
## 48  0  1  1  3  1  4  6  2  8   2  10   3  11   9  13  15   5  15   6  10  10
## 49  0  0  1  3  2  5  1  2  7   6   6   3  12   9   4  14   4   6  12   9  12
## 50  0  0  1  2  3  4  5  7  5   4  10   5  12  12   5   4   7   9  18  16  16
## 51  0  1  2  1  1  3  5  3  6   3  10  10  11  10  13  10  13   6   6  14   5
## 52  0  1  2  2  3  5  2  4  5   6   8   3   5   4   3  15  15  12  16   7  20
## 53  0  0  0  2  4  4  5  3  3   3  10   4   4   4  14  11  15  13  10  14  11
## 54  0  0  2  1  1  4  4  7  2   9   4  10  12   7   6   6  11  12   9  15  15
## 55  0  1  2  1  1  4  5  4  4   5   9   7  10   3  13  13   8   9  17  16  16
## 56  0  0  1  3  2  3  6  4  5   7   2   4  11  11   3   8   8  16   5  13  16
## 57  0  1  1  2  2  5  1  7  4   2   5   5   4   6   6   4  16  11  14  16  14
## 58  0  1  1  1  4  1  6  4  6   3   6   5   6   4  14  13  13   9  12  19   9
## 59  0  0  0  1  4  5  6  3  8   7   9  10   8   6   5  12  15   5  10   5   8
## 60  0  0  1  0  3  2  5  4  8   2   9   3   3  10  12   9  14  11  13   8   6
##    V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40
## 1   13  11  11   7   7   4   6   8   8   4   4   5   7   3   4   2   3   0   0
## 2    4  12   5  12   7  11   5  11   3   3   5   4   4   5   5   1   1   0   1
## 3   14  12  17   7  12  11   7   4   2  10   5   4   2   2   3   2   2   1   1
## 4    4   4   7   6  15   6   4   9  11   3   5   6   3   3   4   2   3   2   1
## 5   14   9   7  13   9  12   6   7   7   9   6   3   2   2   4   2   0   1   1
## 6    5  18   9   5   3  10   3  12   7   8   4   7   3   5   4   4   3   2   1
## 7   17  15   8   9   3  13   7   8   2   8   8   4   2   3   5   4   1   1   1
## 8    8   5  13  15  10   6  10   6   7   4   9   3   5   2   5   3   2   2   1
## 9   16  12   6   8  14   6  13  10  11   4   6   4   7   6   3   2   1   0   0
## 10  15  16  14  12   7   3   8   9  11   2   5   4   5   1   4   1   2   0   0
## 11  15  15  16  11  14  12   4  10  10   4   3   4   5   5   3   3   2   2   1
## 12  16  18   6  12   5   4   3   5   7   8   3   5   4   5   5   4   0   1   1
## 13  12   8   7   4   7  12   9   5   6   5   4   7   3   5   4   2   3   0   1
## 14   9  11   4   6   4  11  11  12   3   5   8   7   4   6   4   1   3   0   0
## 15  13  10   4  12   4   6   7   6  10   8   2   5   1   3   4   2   0   2   0
## 16   8  12  11  11  11  14   6  11   2  10   9   5   6   5   3   4   2   2   0
## 17  19  14  17   5  13   8  11   5  10   9   8   7   5   3   1   4   0   2   1
## 18  19   6   9  12   6   4  13   6   7   2   3   6   5   4   2   3   0   1   0
## 19  12   7   6   7   4  13   5   7   6   6   9   2   1   1   2   2   0   1   0
## 20  19  16  11   8   9  14  12  11   9   6   6   6   1   1   2   4   3   1   1
## 21  19   9   6  11  12   7   6   3   6   3   2   4   3   1   5   4   2   2   0
## 22  10  16   7  14  12   5   4   6   9   8   5   6   6   1   4   3   0   2   0
## 23  15  13   6  12   9  10   3   3   7   4   4   8   2   6   5   1   0   1   0
## 24  13   5  13   7  14   9  10   5  11   5   3   5   1   1   4   4   1   2   0
## 25  16   5  10  10  15   7   5   3  11   5   5   6   1   1   1   1   0   2   1
## 26  11  14   7  13  11   7  12  12   7   8   5   7   2   2   4   1   1   1   0
## 27  12  18  14  16  12   3  11   3   2   7   4   8   2   2   1   3   0   1   1
## 28  13   7  17   4   5  11   4   8   7   9   4   5   3   2   5   4   3   2   1
## 29  18   9   5   4   7  14   8   4   3   7   7   8   3   5   4   1   3   1   0
## 30  15  17   4  14  13   4   4  12  11   6   9   5   5   2   5   2   1   0   1
## 31   7   6   9  15   7   6   4  10   8  10   4   2   6   5   5   2   3   2   1
## 32  15  15   6   8   8  11   5   5   7   3   6   6   4   5   2   2   3   0   0
## 33   8   6  12  10   5  12   7   7  11   5   8   5   2   5   5   2   0   2   1
## 34   6  10  11   4  15  13   7   3   4   2   9   7   2   4   2   1   2   1   1
## 35  18  12  17  14   4  13  13   8  11   5   6   6   2   3   5   2   1   1   1
## 36   9  16  17  16   3   8   9   8   3   3   9   5   1   6   5   4   2   2   0
## 37  13   9  16  12   6   7   9  10   3   6   4   5   4   6   3   4   3   2   1
## 38  16  17  14   4   4  10  10  10  11   9   9   5   4   4   2   1   0   1   0
## 39   9  10   6  13   5  13   6   7   2   5   5   2   1   1   1   1   3   0   1
## 40   4  14   5  13  10   7  10   6   3   2   3   6   3   3   5   4   3   2   1
## 41   7   9  10  14  12  11   9  10   3   2   9   6   2   2   5   3   0   0   1
## 42   6   4  11   6  12   7   5   5   4   4   8   2   6   6   4   2   2   0   0
## 43  16   6   4  14   3  12   9   6  11   5   8   5   5   6   1   2   1   2   0
## 44  14   6  10   7   9   8   5   8   3  10   2   5   1   5   4   2   1   0   1
## 45  18   5  14  15  12   9   8   3   6  10   6   8   7   2   5   4   3   1   1
## 46   9  11  10  10   7  10   8   8   4   5   8   4   4   5   2   4   1   1   0
## 47  10  18  13  15  11   8   4   7  11   6   7   6   5   1   3   1   0   0   0
## 48   5  14  15  12   7   4   5  11   4   6   9   5   6   1   1   2   1   2   1
## 49   7  11   7  16   8  13   6   7   6  10   7   6   3   1   5   4   3   0   0
## 50  10  15  15  10   4   3   7   5   9   4   6   2   4   1   4   2   2   2   1
## 51   4   5   5   9   4  12   7   7   4   7   9   3   3   6   3   4   1   2   0
## 52  15  12   8   9   6  12   5   8   3   8   5   4   1   3   2   1   3   1   0
## 53  17   9  11  11   7  10  12  10  10  10   8   7   5   2   2   4   1   2   1
## 54   6   6  13   5  12   9   6   4   7   7   6   5   4   1   4   2   2   2   1
## 55  15  12  13   5  12  10   9  11   9   4   5   5   2   2   5   1   0   0   1
## 56   5   8   8   6   9  10  10   9   3   3   5   3   5   4   5   3   3   0   1
## 57  14   8  17   4  14  13   7   6   3   7   7   5   6   3   4   2   2   1   1
## 58  10  15  10   9  10  10   7   5   6   8   6   6   4   3   5   2   1   1   1
## 59  13  18  17  14   9  13   4  10  11  10   8   8   6   5   5   2   0   2   0
## 60  18  11   9  13  11   8   5   5   2   8   5   3   5   4   1   3   1   1   0
#Loading a .csv2 format file
read.csv(file = "data/commadec.txt", sep = ";", dec = ",")
##         ID Gender      Group BloodPressure  Age Aneurisms_q1 Aneurisms_q2
## 1   Sub001      m    Control           132 16.0          114          140
## 2   Sub002      m Treatment2           139 17.2          148          209
## 3   Sub003      m Treatment2           130 19.5          196          251
## 4   Sub004      f Treatment1           105 15.7          199          140
## 5   Sub005      m Treatment1           125 19.9          188          120
## 6   Sub006      M Treatment2           112 14.3          260          266
## 7   Sub007      f    Control           173 17.7          135           98
## 8   Sub008      m Treatment2           108 19.8          216          238
## 9   Sub009      m Treatment2           131 19.4          117          215
## 10  Sub010      f    Control           129 18.8          188          144
## 11  Sub011      m Treatment1           126 14.8          134          155
## 12  Sub012      f Treatment2            96 15.3          152          177
## 13  Sub013      f    Control            77 16.5          112          220
## 14  Sub014      m    Control           158 12.6          109          150
## 15  Sub015      m    Control            81 14.3          146          140
## 16  Sub016      m    Control           137 15.9           97          172
## 17  Sub017      f Treatment1           147 18.4          165          157
## 18  Sub018      m Treatment2           130 18.3          158          265
## 19  Sub019      m Treatment1           105 15.4          178          109
## 20  Sub020      F Treatment1            92 14.3          107          188
## 21  Sub021      f    Control           111 12.7          174          160
## 22  Sub022      m Treatment1           122 15.4           97          110
## 23  Sub023      f Treatment2            97 17.2          187          239
## 24  Sub024      f Treatment2           118 17.3          188          191
## 25  Sub025      m Treatment1            82 16.7          114          199
## 26  Sub026      M Treatment1           123 19.6          115          160
## 27  Sub027      M Treatment2           126 15.0          128          249
## 28  Sub028      f Treatment1            94 16.1          112          230
## 29  Sub029      m    Control           135 17.6          136          109
## 30  Sub030      f    Control           108 18.6          103          148
## 31  Sub031      f Treatment1           133 18.3          132          151
## 32  Sub032      m Treatment1           108 16.7          118          154
## 33  Sub033      m Treatment2           122 12.5          166          176
## 34  Sub034      m Treatment1           134 14.3          152          105
## 35  Sub035      m Treatment1           145 19.7          191          148
## 36  Sub036      f    Control           133 17.6          152          178
## 37  Sub037      f Treatment2            90 17.0          161          270
## 38  Sub038      m Treatment2           118 12.2          239          184
## 39  Sub039      M Treatment1           113 15.1          132          137
## 40  Sub040      m Treatment2           115 17.7          168          255
## 41  Sub041      f Treatment1           142 19.0          140          184
## 42  Sub042      m Treatment1           114 14.7          166           85
## 43  Sub043      m    Control           139 15.2          141          160
## 44  Sub044      m Treatment1            90 15.3          161          168
## 45  Sub045      f    Control           126 12.9          103          111
## 46  Sub046      f Treatment2           109 18.4          231          240
## 47  Sub047      M    Control           125 18.1          192          141
## 48  Sub048      M    Control            99 15.6          178          180
## 49  Sub049      m    Control           122 19.5          167          123
## 50  Sub050      m Treatment1           111 13.5          135          150
## 51  Sub051      m Treatment2           109 13.5          150          166
## 52  Sub052      f Treatment1           134 13.7          192           80
## 53  Sub053      f Treatment1           113 18.7          153          153
## 54  Sub054      f Treatment2           105 12.2          205          264
## 55  Sub055      m Treatment2           125 16.9          117          194
## 56  Sub056      f Treatment2           123 19.5          199          119
## 57  Sub057      m    Control           155 12.1          182          129
## 58  Sub058      m Treatment2           117 17.0          180          196
## 59  Sub059      m Treatment1           116 19.2          111          111
## 60  Sub060      f    Control           133 14.7          101           98
## 61  Sub061      f    Control            94 20.0          166          167
## 62  Sub062      f Treatment2           106 14.1          158          171
## 63  Sub063      f Treatment1           144 14.7          189          178
## 64  Sub064      M Treatment1           149 16.6          189          101
## 65  Sub065      f Treatment2           108 15.0          239          189
## 66  Sub066      m Treatment1           116 15.0          185          224
## 67  Sub067      f Treatment2           136 13.8          224          112
## 68  Sub068      f    Control            98 14.8          104          139
## 69  Sub069      M Treatment2           148 19.1          222          199
## 70  Sub070      m    Control            74 18.9          107           98
## 71  Sub071      m Treatment2           147 17.7          153          255
## 72  Sub072      m    Control           116 17.4          118          165
## 73  Sub073      F Treatment1           133 15.5          102          184
## 74  Sub074      m    Control            97 13.1          188          125
## 75  Sub075      m Treatment2           132 12.2          180          283
## 76  Sub076      f Treatment2           153 17.0          178          214
## 77  Sub077      M Treatment1           151 17.7          168          184
## 78  Sub078      M Treatment1           121 19.5          118          170
## 79  Sub079      M Treatment1           116 19.5          169          114
## 80  Sub080      f    Control           104 12.8          156          138
## 81  Sub081      m Treatment2           111 17.6          232          211
## 82  Sub082      M Treatment1            62 17.7          188          108
## 83  Sub083      M Treatment2           124 14.2          169          168
## 84  Sub084      m Treatment2           124 19.2          241          233
## 85  Sub085      m Treatment2           109 16.0           65          207
## 86  Sub086      f    Control           117 15.2          225          185
## 87  Sub087      f    Control            90 17.6          104          116
## 88  Sub088      f Treatment1           158 17.6          179          158
## 89  Sub089      m Treatment1           113 15.1          103          140
## 90  Sub090      m    Control           150 17.8          112          130
## 91  Sub091      f Treatment2           115 16.2          226          170
## 92  Sub092      m Treatment2            83 16.6          228          221
## 93  Sub093      F    Control           116 19.1          209          142
## 94  Sub094      f Treatment1           141 17.2          153          104
## 95  Sub095      m    Control           108 13.6          111          118
## 96  Sub096      m    Control           102 14.6          148          132
## 97  Sub097      F Treatment2            90 19.6          141          196
## 98  Sub098      m Treatment1           133 17.0          193          112
## 99  Sub099      M Treatment2            83 16.2          130          226
## 100 Sub100      M Treatment1           122 18.4          126          157
##     Aneurisms_q3 Aneurisms_q4
## 1            202          237
## 2            248          248
## 3            122          177
## 4            233          220
## 5            222          228
## 6            320          294
## 7            154          245
## 8            279          251
## 9            181          272
## 10           192          185
## 11           247          223
## 12           323          245
## 13           225          195
## 14           177          189
## 15           239          223
## 16           203          207
## 17           200          193
## 18           243          187
## 19           206          182
## 20           167          218
## 21           203          183
## 22           194          133
## 23           281          214
## 24           256          265
## 25           242          195
## 26           158          228
## 27           294          315
## 28           281          126
## 29           105          155
## 30           219          228
## 31           234          162
## 32           260          160
## 33           253          233
## 34           197          299
## 35           166          185
## 36           158          170
## 37           232          284
## 38           317          269
## 39           193          206
## 40           273          274
## 41           239          202
## 42           179          196
## 43           179          239
## 44           212          181
## 45           254          126
## 46           260          310
## 47           180          225
## 48           169          183
## 49           236          224
## 50           208          279
## 51           153          204
## 52           138          222
## 53           236          216
## 54           269          207
## 55           216          211
## 56           183          251
## 57           226          218
## 58           250          294
## 59           244          201
## 60           178          116
## 61           232          241
## 62           237          212
## 63           177          238
## 64           193          172
## 65           297          300
## 66           151          182
## 67           304          288
## 68           211          204
## 69           280          196
## 70           204          138
## 71           218          234
## 72           220          227
## 73           246          222
## 74           191          157
## 75           204          298
## 76           291          240
## 77           184          229
## 78           249          249
## 79           248          233
## 80           218          258
## 81           219          246
## 82           180          136
## 83           180          211
## 84           292          182
## 85           234          235
## 86           195          235
## 87           173          221
## 88           216          244
## 89           209          186
## 90           175          191
## 91           307          244
## 92           316          259
## 93           199          184
## 94           194          214
## 95           173          191
## 96           200          194
## 97           322          273
## 98           123          181
## 99           286          281
## 100          129          160
read.csv2(file = "data/commadec.txt")
##         ID Gender      Group BloodPressure  Age Aneurisms_q1 Aneurisms_q2
## 1   Sub001      m    Control           132 16.0          114          140
## 2   Sub002      m Treatment2           139 17.2          148          209
## 3   Sub003      m Treatment2           130 19.5          196          251
## 4   Sub004      f Treatment1           105 15.7          199          140
## 5   Sub005      m Treatment1           125 19.9          188          120
## 6   Sub006      M Treatment2           112 14.3          260          266
## 7   Sub007      f    Control           173 17.7          135           98
## 8   Sub008      m Treatment2           108 19.8          216          238
## 9   Sub009      m Treatment2           131 19.4          117          215
## 10  Sub010      f    Control           129 18.8          188          144
## 11  Sub011      m Treatment1           126 14.8          134          155
## 12  Sub012      f Treatment2            96 15.3          152          177
## 13  Sub013      f    Control            77 16.5          112          220
## 14  Sub014      m    Control           158 12.6          109          150
## 15  Sub015      m    Control            81 14.3          146          140
## 16  Sub016      m    Control           137 15.9           97          172
## 17  Sub017      f Treatment1           147 18.4          165          157
## 18  Sub018      m Treatment2           130 18.3          158          265
## 19  Sub019      m Treatment1           105 15.4          178          109
## 20  Sub020      F Treatment1            92 14.3          107          188
## 21  Sub021      f    Control           111 12.7          174          160
## 22  Sub022      m Treatment1           122 15.4           97          110
## 23  Sub023      f Treatment2            97 17.2          187          239
## 24  Sub024      f Treatment2           118 17.3          188          191
## 25  Sub025      m Treatment1            82 16.7          114          199
## 26  Sub026      M Treatment1           123 19.6          115          160
## 27  Sub027      M Treatment2           126 15.0          128          249
## 28  Sub028      f Treatment1            94 16.1          112          230
## 29  Sub029      m    Control           135 17.6          136          109
## 30  Sub030      f    Control           108 18.6          103          148
## 31  Sub031      f Treatment1           133 18.3          132          151
## 32  Sub032      m Treatment1           108 16.7          118          154
## 33  Sub033      m Treatment2           122 12.5          166          176
## 34  Sub034      m Treatment1           134 14.3          152          105
## 35  Sub035      m Treatment1           145 19.7          191          148
## 36  Sub036      f    Control           133 17.6          152          178
## 37  Sub037      f Treatment2            90 17.0          161          270
## 38  Sub038      m Treatment2           118 12.2          239          184
## 39  Sub039      M Treatment1           113 15.1          132          137
## 40  Sub040      m Treatment2           115 17.7          168          255
## 41  Sub041      f Treatment1           142 19.0          140          184
## 42  Sub042      m Treatment1           114 14.7          166           85
## 43  Sub043      m    Control           139 15.2          141          160
## 44  Sub044      m Treatment1            90 15.3          161          168
## 45  Sub045      f    Control           126 12.9          103          111
## 46  Sub046      f Treatment2           109 18.4          231          240
## 47  Sub047      M    Control           125 18.1          192          141
## 48  Sub048      M    Control            99 15.6          178          180
## 49  Sub049      m    Control           122 19.5          167          123
## 50  Sub050      m Treatment1           111 13.5          135          150
## 51  Sub051      m Treatment2           109 13.5          150          166
## 52  Sub052      f Treatment1           134 13.7          192           80
## 53  Sub053      f Treatment1           113 18.7          153          153
## 54  Sub054      f Treatment2           105 12.2          205          264
## 55  Sub055      m Treatment2           125 16.9          117          194
## 56  Sub056      f Treatment2           123 19.5          199          119
## 57  Sub057      m    Control           155 12.1          182          129
## 58  Sub058      m Treatment2           117 17.0          180          196
## 59  Sub059      m Treatment1           116 19.2          111          111
## 60  Sub060      f    Control           133 14.7          101           98
## 61  Sub061      f    Control            94 20.0          166          167
## 62  Sub062      f Treatment2           106 14.1          158          171
## 63  Sub063      f Treatment1           144 14.7          189          178
## 64  Sub064      M Treatment1           149 16.6          189          101
## 65  Sub065      f Treatment2           108 15.0          239          189
## 66  Sub066      m Treatment1           116 15.0          185          224
## 67  Sub067      f Treatment2           136 13.8          224          112
## 68  Sub068      f    Control            98 14.8          104          139
## 69  Sub069      M Treatment2           148 19.1          222          199
## 70  Sub070      m    Control            74 18.9          107           98
## 71  Sub071      m Treatment2           147 17.7          153          255
## 72  Sub072      m    Control           116 17.4          118          165
## 73  Sub073      F Treatment1           133 15.5          102          184
## 74  Sub074      m    Control            97 13.1          188          125
## 75  Sub075      m Treatment2           132 12.2          180          283
## 76  Sub076      f Treatment2           153 17.0          178          214
## 77  Sub077      M Treatment1           151 17.7          168          184
## 78  Sub078      M Treatment1           121 19.5          118          170
## 79  Sub079      M Treatment1           116 19.5          169          114
## 80  Sub080      f    Control           104 12.8          156          138
## 81  Sub081      m Treatment2           111 17.6          232          211
## 82  Sub082      M Treatment1            62 17.7          188          108
## 83  Sub083      M Treatment2           124 14.2          169          168
## 84  Sub084      m Treatment2           124 19.2          241          233
## 85  Sub085      m Treatment2           109 16.0           65          207
## 86  Sub086      f    Control           117 15.2          225          185
## 87  Sub087      f    Control            90 17.6          104          116
## 88  Sub088      f Treatment1           158 17.6          179          158
## 89  Sub089      m Treatment1           113 15.1          103          140
## 90  Sub090      m    Control           150 17.8          112          130
## 91  Sub091      f Treatment2           115 16.2          226          170
## 92  Sub092      m Treatment2            83 16.6          228          221
## 93  Sub093      F    Control           116 19.1          209          142
## 94  Sub094      f Treatment1           141 17.2          153          104
## 95  Sub095      m    Control           108 13.6          111          118
## 96  Sub096      m    Control           102 14.6          148          132
## 97  Sub097      F Treatment2            90 19.6          141          196
## 98  Sub098      m Treatment1           133 17.0          193          112
## 99  Sub099      M Treatment2            83 16.2          130          226
## 100 Sub100      M Treatment1           122 18.4          126          157
##     Aneurisms_q3 Aneurisms_q4
## 1            202          237
## 2            248          248
## 3            122          177
## 4            233          220
## 5            222          228
## 6            320          294
## 7            154          245
## 8            279          251
## 9            181          272
## 10           192          185
## 11           247          223
## 12           323          245
## 13           225          195
## 14           177          189
## 15           239          223
## 16           203          207
## 17           200          193
## 18           243          187
## 19           206          182
## 20           167          218
## 21           203          183
## 22           194          133
## 23           281          214
## 24           256          265
## 25           242          195
## 26           158          228
## 27           294          315
## 28           281          126
## 29           105          155
## 30           219          228
## 31           234          162
## 32           260          160
## 33           253          233
## 34           197          299
## 35           166          185
## 36           158          170
## 37           232          284
## 38           317          269
## 39           193          206
## 40           273          274
## 41           239          202
## 42           179          196
## 43           179          239
## 44           212          181
## 45           254          126
## 46           260          310
## 47           180          225
## 48           169          183
## 49           236          224
## 50           208          279
## 51           153          204
## 52           138          222
## 53           236          216
## 54           269          207
## 55           216          211
## 56           183          251
## 57           226          218
## 58           250          294
## 59           244          201
## 60           178          116
## 61           232          241
## 62           237          212
## 63           177          238
## 64           193          172
## 65           297          300
## 66           151          182
## 67           304          288
## 68           211          204
## 69           280          196
## 70           204          138
## 71           218          234
## 72           220          227
## 73           246          222
## 74           191          157
## 75           204          298
## 76           291          240
## 77           184          229
## 78           249          249
## 79           248          233
## 80           218          258
## 81           219          246
## 82           180          136
## 83           180          211
## 84           292          182
## 85           234          235
## 86           195          235
## 87           173          221
## 88           216          244
## 89           209          186
## 90           175          191
## 91           307          244
## 92           316          259
## 93           199          184
## 94           194          214
## 95           173          191
## 96           200          194
## 97           322          273
## 98           123          181
## 99           286          281
## 100          129          160
#Assiging Variables

weight_kg <- 55

weight_kg
## [1] 55
#Weight in pounds
2.2 * weight_kg
## [1] 121
weight_kg <- 57.5
weight_kg
## [1] 57.5
weight_lb <- 2.2 * weight_kg

#Weight in kg
weight_kg
## [1] 57.5
#Weight in Pounds
weight_lb
## [1] 126.5
dat <- read.csv(file = "data/inflammation-01.csv", header = FALSE)

View(dat)

head(dat)
##   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
## 1  0  0  1  3  1  2  4  7  8   3   3   3  10   5   7   4   7   7  12  18   6
## 2  0  1  2  1  2  1  3  2  2   6  10  11   5   9   4   4   7  16   8   6  18
## 3  0  1  1  3  3  2  6  2  5   9   5   7   4   5   4  15   5  11   9  10  19
## 4  0  0  2  0  4  2  2  1  6   7  10   7   9  13   8   8  15  10  10   7  17
## 5  0  1  1  3  3  1  3  5  2   4   4   7   6   5   3  10   8  10   6  17   9
## 6  0  0  1  2  2  4  2  1  6   4   7   6   6   9   9  15   4  16  18  12  12
##   V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40
## 1  13  11  11   7   7   4   6   8   8   4   4   5   7   3   4   2   3   0   0
## 2   4  12   5  12   7  11   5  11   3   3   5   4   4   5   5   1   1   0   1
## 3  14  12  17   7  12  11   7   4   2  10   5   4   2   2   3   2   2   1   1
## 4   4   4   7   6  15   6   4   9  11   3   5   6   3   3   4   2   3   2   1
## 5  14   9   7  13   9  12   6   7   7   9   6   3   2   2   4   2   0   1   1
## 6   5  18   9   5   3  10   3  12   7   8   4   7   3   5   4   4   3   2   1
tail(dat)
##    V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
## 55  0  1  2  1  1  4  5  4  4   5   9   7  10   3  13  13   8   9  17  16  16
## 56  0  0  1  3  2  3  6  4  5   7   2   4  11  11   3   8   8  16   5  13  16
## 57  0  1  1  2  2  5  1  7  4   2   5   5   4   6   6   4  16  11  14  16  14
## 58  0  1  1  1  4  1  6  4  6   3   6   5   6   4  14  13  13   9  12  19   9
## 59  0  0  0  1  4  5  6  3  8   7   9  10   8   6   5  12  15   5  10   5   8
## 60  0  0  1  0  3  2  5  4  8   2   9   3   3  10  12   9  14  11  13   8   6
##    V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35 V36 V37 V38 V39 V40
## 55  15  12  13   5  12  10   9  11   9   4   5   5   2   2   5   1   0   0   1
## 56   5   8   8   6   9  10  10   9   3   3   5   3   5   4   5   3   3   0   1
## 57  14   8  17   4  14  13   7   6   3   7   7   5   6   3   4   2   2   1   1
## 58  10  15  10   9  10  10   7   5   6   8   6   6   4   3   5   2   1   1   1
## 59  13  18  17  14   9  13   4  10  11  10   8   8   6   5   5   2   0   2   0
## 60  18  11   9  13  11   8   5   5   2   8   5   3   5   4   1   3   1   1   0
mass <- 47.5
mass
## [1] 47.5
age <- 122
age
## [1] 122
mass <- mass * 2.0
mass
## [1] 95
age <- age - 20
age
## [1] 102
#Manipulating Data
class(dat)
## [1] "data.frame"
dim(dat)
## [1] 60 40
dat[1,1]
## [1] 0
View(dat)
#Middle Value in dat, row 30, column 20
dat[30,20]
## [1] 16
#Picking columns 10 and 20 from rows 1,3, and 5
dat[c(1,3,5), c(10,20)]
##   V10 V20
## 1   3  18
## 3   9  10
## 5   4  17
#Choosing contiguous rows
1:5
## [1] 1 2 3 4 5
3:12
##  [1]  3  4  5  6  7  8  9 10 11 12
#From the dataset 'dat', choose the first 4 rows and the first 10 columns
dat[1:4, 1:10]
##   V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
## 1  0  0  1  3  1  2  4  7  8   3
## 2  0  1  2  1  2  1  3  2  2   6
## 3  0  1  1  3  3  2  6  2  5   9
## 4  0  0  2  0  4  2  2  1  6   7
#From the dataset 'dat', choose the rows 5 to 10 and the first 10 columns
dat[5:10, 1:10]
##    V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
## 5   0  1  1  3  3  1  3  5  2   4
## 6   0  0  1  2  2  4  2  1  6   4
## 7   0  0  2  2  4  2  2  5  5   8
## 8   0  0  1  2  3  1  2  3  5   3
## 9   0  0  0  3  1  5  6  5  5   8
## 10  0  1  1  2  1  3  5  3  5   8
#All the columns from row 5
all_columns_for_row_5 <- dat[5,]

#All rows from columns 16-18
all_rows_from_columns_16to18 <- dat[,16:18]

dat$V5
##  [1] 1 2 3 4 3 2 4 3 1 1 4 3 4 1 1 1 2 2 2 1 1 2 4 1 2 3 4 1 3 4 3 3 2 3 4 1 2 3
## [39] 2 1 2 3 4 1 3 4 4 1 2 3 1 3 4 1 1 2 2 4 4 3
dat[,'V5']
##  [1] 1 2 3 4 3 2 4 3 1 1 4 3 4 1 1 1 2 2 2 1 1 2 4 1 2 3 4 1 3 4 3 3 2 3 4 1 2 3
## [39] 2 1 2 3 4 1 3 4 4 1 2 3 1 3 4 1 1 2 2 4 4 3
#First row, all the columns
patient_1 <- dat[1,]

#Maximum inflammation value for Patient 1
max(patient_1)
## [1] 18
min(patient_1)
## [1] 0
#Maximum inflmmation for Patient 2
patient_2 <- dat[2,]
max(patient_2)
## [1] 18
max(dat[2,])
## [1] 18
#Minimum inflammation on Day 7
min(dat[,7])
## [1] 1
#Mean inflammation on day 7

mean(dat[,7])
## [1] 3.8
#Median inflammation on day 7
median(dat[,7])
## [1] 4
#Standard Deviation of inflammation on Day 7
sd(dat[,7])
## [1] 1.725187
mean(dat[1,])
## Warning in mean.default(dat[1, ]): argument is not numeric or logical:
## returning NA
## [1] NA
mean(as.numeric(dat[1,]))
## [1] 5.45
#Summarize Function
summary(dat[,1:4])
##        V1          V2             V3              V4      
##  Min.   :0   Min.   :0.00   Min.   :0.000   Min.   :0.00  
##  1st Qu.:0   1st Qu.:0.00   1st Qu.:1.000   1st Qu.:1.00  
##  Median :0   Median :0.00   Median :1.000   Median :2.00  
##  Mean   :0   Mean   :0.45   Mean   :1.117   Mean   :1.75  
##  3rd Qu.:0   3rd Qu.:1.00   3rd Qu.:2.000   3rd Qu.:3.00  
##  Max.   :0   Max.   :1.00   Max.   :2.000   Max.   :3.00
#Maximum Inflammation for all patients
max_inflammation_for_all_patients <- apply(dat,1,max)
max_inflammation_for_all_patients
##  [1] 18 18 19 17 17 18 17 20 17 18 18 18 17 16 17 18 19 19 17 19 19 16 17 15 17
## [26] 17 18 17 20 17 16 19 15 15 19 17 16 17 19 16 18 19 16 19 18 16 19 15 16 18
## [51] 14 20 17 15 17 16 17 19 18 18
#Average Inflammation for each day
avg_day_inflammation <- apply(dat, 2, mean)
avg_day_inflammation
##         V1         V2         V3         V4         V5         V6         V7 
##  0.0000000  0.4500000  1.1166667  1.7500000  2.4333333  3.1500000  3.8000000 
##         V8         V9        V10        V11        V12        V13        V14 
##  3.8833333  5.2333333  5.5166667  5.9500000  5.9000000  8.3500000  7.7333333 
##        V15        V16        V17        V18        V19        V20        V21 
##  8.3666667  9.5000000  9.5833333 10.6333333 11.5666667 12.3500000 13.2500000 
##        V22        V23        V24        V25        V26        V27        V28 
## 11.9666667 11.0333333 10.1666667 10.0000000  8.6666667  9.1500000  7.2500000 
##        V29        V30        V31        V32        V33        V34        V35 
##  7.3333333  6.5833333  6.0666667  5.9500000  5.1166667  3.6000000  3.3000000 
##        V36        V37        V38        V39        V40 
##  3.5666667  2.4833333  1.5000000  1.1333333  0.5666667
avg_patient_inflammation <- apply(dat,1, mean)
avg_patient_inflammation
##  [1] 5.450 5.425 6.100 5.900 5.550 6.225 5.975 6.650 6.625 6.525 6.775 5.800
## [13] 6.225 5.750 5.225 6.300 6.550 5.700 5.850 6.550 5.775 5.825 6.175 6.100
## [25] 5.800 6.425 6.050 6.025 6.175 6.550 6.175 6.350 6.725 6.125 7.075 5.725
## [37] 5.925 6.150 6.075 5.750 5.975 5.725 6.300 5.900 6.750 5.925 7.225 6.150
## [49] 5.950 6.275 5.700 6.100 6.825 5.975 6.725 5.700 6.250 6.400 7.050 5.900
#Subsetting Character/String Data

animal <- c("m","o","n","k","e","y")

#First three characters
animal[1:3]
## [1] "m" "o" "n"
#Last three characters
animal[4:6]
## [1] "k" "e" "y"
animal[4:1]
## [1] "k" "n" "o" "m"
animal[-1:-4]
## [1] "e" "y"
animal[5:6]
## [1] "e" "y"
#Use a subset of animal to create a new character vector that spells the word "eon" i.e.c("e","o","n")
animal[c(5,2,3)]
## [1] "e" "o" "n"
#Creating Functions

fahrenheit_to_celsius <- function(temp_F){
  temp_C <- (temp_F - 32) * 5 / 9
  return(temp_C)
}

#Freezing Point of Water
fahrenheit_to_celsius(32)
## [1] 0
#Boiling Point of Water
fahrenheit_to_celsius(212)
## [1] 100
celsius_to_kelvin <- function(temp_C){
  temp_K <- temp_C + 273.15
  return(temp_K)
}

#Freezing Point of Water in kelvin
celsius_to_kelvin(0)
## [1] 273.15
#Convert value from Fahrenheit to Kelvin

fahrenheit_to_kelvin <- function(temp_F){
  temp_C <- fahrenheit_to_celsius(temp_F)
  temp_K <- celsius_to_kelvin(temp_C)
  return(temp_K)
}

#Freezing Point of Water in Kelvin
fahrenheit_to_kelvin(32.0)
## [1] 273.15
#Freezing Point of Water in Fahrenheit
celsius_to_kelvin(fahrenheit_to_celsius(32.0))
## [1] 273.15
#Content and Wrapper Exercise
best_practice <- c('Write', "programs", "for", "people", "not", "computers")

asterisk <- "****"

highlight <- function(content, wrapper){
  answer <- c(wrapper, content, wrapper)
  return(answer)
}

highlight(best_practice, asterisk)
## [1] "****"      "Write"     "programs"  "for"       "people"    "not"      
## [7] "computers" "****"
#Exercise 6

dry_principle <- c("Don't", "repeat", "yourself", "or", "others")

edges <- function(v) {
  first <- v[1]
  last <- v[length(v)]
  answer <- c(first, last)
  return(answer)
}

edges(dry_principle)
## [1] "Don't"  "others"
input_1 <- 20
mySum <- function(input_1, input_2 =10) {
  output <- input_1 + input_2
  return(output)
}

mySum(input_1 =1,3)
## [1] 4
center <- function(data, midpoint){
  new_data <- (data - mean(data)) + midpoint
  return(new_data)
}

z <- c(0,0,0,0)
z
## [1] 0 0 0 0
center(z,3)
## [1] 3 3 3 3
#Centering our dat dataset from day 4 around 0

centered <- center(dat[,4],0)
head(centered)
## [1]  1.25 -0.75  1.25 -1.75  1.25  0.25
#Original Mean
mean(dat[,4])
## [1] 1.75
#Centered Mean
mean(centered)
## [1] 0
#Original Standard Deviation
sd(dat[,4])
## [1] 1.067628
#Centered Standard Deviation
sd(centered)
## [1] 1.067628
#Difference in standard deviations before and after
sd(dat[,4]) - sd(centered)
## [1] 0
#New Data Object and set one value in Column 4 to NA

datNA <- dat
datNA[10,4] <- NA

#Return all NA Values
center(datNA[,4],0)
##  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [51] NA NA NA NA NA NA NA NA NA NA
#Modified Function

center <- function(data, midpoint){
  #return a new vector containing the original data centered around the midpoint
  #Example : center(c(1,2,3),0) => c(-1,0,1)
  new_data <- (data - mean(data, na.rm = TRUE)) + midpoint
  return(new_data)
}

center(datNA[,4],0)
##  [1]  1.2542373 -0.7457627  1.2542373 -1.7457627  1.2542373  0.2542373
##  [7]  0.2542373  0.2542373  1.2542373         NA -1.7457627 -1.7457627
## [13] -0.7457627 -1.7457627 -0.7457627 -1.7457627 -1.7457627 -0.7457627
## [19] -0.7457627 -1.7457627  1.2542373  1.2542373  1.2542373 -0.7457627
## [25] -0.7457627 -0.7457627  0.2542373 -0.7457627  0.2542373 -0.7457627
## [31] -1.7457627  1.2542373  0.2542373 -0.7457627  0.2542373  1.2542373
## [37]  0.2542373  0.2542373  1.2542373  1.2542373  0.2542373  1.2542373
## [43]  1.2542373  1.2542373  1.2542373  0.2542373  1.2542373  1.2542373
## [49]  1.2542373  0.2542373 -0.7457627  0.2542373  0.2542373 -0.7457627
## [55] -0.7457627  1.2542373  0.2542373 -0.7457627 -0.7457627 -1.7457627
#What happens if the center function encounters factor or character variable?

datNA[,1] <- as.numeric(datNA[,1])
datNA[,2] <- as.numeric(datNA[,2])

center(datNA[,1],0)
##  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [39] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
center(datNA[,2],0)
##  [1] -0.45  0.55  0.55 -0.45  0.55 -0.45 -0.45 -0.45 -0.45  0.55  0.55  0.55
## [13] -0.45 -0.45  0.55  0.55 -0.45 -0.45 -0.45  0.55  0.55 -0.45 -0.45  0.55
## [25]  0.55 -0.45 -0.45 -0.45 -0.45 -0.45  0.55 -0.45  0.55 -0.45 -0.45 -0.45
## [37]  0.55  0.55  0.55  0.55 -0.45 -0.45  0.55 -0.45  0.55  0.55 -0.45  0.55
## [49] -0.45 -0.45  0.55  0.55 -0.45 -0.45  0.55 -0.45  0.55  0.55 -0.45 -0.45
#Function to create graphs

analyze <- function(filename) {
  #Plots the average, min, max inflammation over time.
  #Input is character string of a csv file.
  dat <- read.csv(file = filename, header = FALSE)
  avg_day_inflammation <- apply(dat,2,mean)
  plot(avg_day_inflammation)
  max_day_inflammation <- apply(dat,2,max)
  plot(max_day_inflammation)
  min_day_inflammation <- apply(dat,2,min)
  plot(min_day_inflammation)
}

analyze("data/inflammation-01.csv")

analyze("data/inflammation-02.csv")

#Rescale function. If L and H are the lowest and the highets values in the original vector, then the replacement value v should be (v-L)/(H-L)

rescale <- function(v){
  #Rescale a vector, v to lie in the range 0 to 1
  L <- min(v)
  H <- max(v)
  result <- (v-L)/(H-L)
  return(result)
}

rescale(c(3,4,5,6))
## [1] 0.0000000 0.3333333 0.6666667 1.0000000

Plots

\(\alpha = \dfrac{1}{(1- \beta)^2}\)