Loading the CSV file in RMarkdown

library(readr)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ dplyr   1.0.10
## ✔ tibble  3.1.8      ✔ stringr 1.4.1 
## ✔ tidyr   1.2.1      ✔ forcats 0.5.2 
## ✔ purrr   0.3.5      
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## 
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## 
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(ggplot2)
library(glm2)
## 
## Attaching package: 'glm2'
## 
## The following object is masked from 'package:survival':
## 
##     heart
library(knitr)
#Loading the dataset
uphia<-read.csv(file.choose())

Well-labelled summary tables

summary(uphia)
##        X          personid             region          gender         
##  Min.   :   1   Length:2893        Min.   : 1.000   Length:2893       
##  1st Qu.: 724   Class :character   1st Qu.: 4.000   Class :character  
##  Median :1447   Mode  :character   Median : 5.000   Mode  :character  
##  Mean   :1447                      Mean   : 5.491                     
##  3rd Qu.:2170                      3rd Qu.: 7.000                     
##  Max.   :2893                      Max.   :10.000                     
##                                                                       
##       age          work12mo           occuptn             ethnic         
##  Min.   :15.00   Length:2893        Length:2893        Length:2893       
##  1st Qu.:20.00   Class :character   Class :character   Class :character  
##  Median :29.00   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :33.19                                                           
##  3rd Qu.:42.00                                                           
##  Max.   :80.00                                                           
##                                                                          
##    mcstatus           firstsxage     lifetimesex      part12monum    
##  Length:2893        Min.   :14.00   Min.   : 1.000   Min.   :-7.000  
##  Class :character   1st Qu.:15.00   1st Qu.: 3.000   1st Qu.: 1.000  
##  Mode  :character   Median :17.00   Median : 4.000   Median : 1.000  
##                     Mean   :17.17   Mean   : 5.773   Mean   : 1.033  
##                     3rd Qu.:18.00   3rd Qu.: 6.000   3rd Qu.: 1.000  
##                     Max.   :30.00   Max.   :21.000   Max.   : 7.000  
##                     NA's   :737     NA's   :658      NA's   :622     
##     urban           wealthquintile     hivstatusfinal      education        
##  Length:2893        Length:2893        Length:2893        Length:2893       
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    uniontype       marital           evertested         bt_status        
##  Min.   : 1.00   Length:2893        Length:2893        Length:2893       
##  1st Qu.: 2.00   Class :character   Class :character   Class :character  
##  Median : 3.00   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :18.01                                                           
##  3rd Qu.: 3.00                                                           
##  Max.   :99.00                                                           
##                                                                          
##  sex12months          sexever          condomlastsex12months
##  Length:2893        Length:2893        Length:2893          
##  Class :character   Class :character   Class :character     
##  Mode  :character   Mode  :character   Mode  :character     
##                                                             
##                                                             
##                                                             
##                                                             
##  lastpartnerrelation12months lastpartnerspouselivein12months
##  Length:2893                 Length:2893                    
##  Class :character            Class :character               
##  Mode  :character            Mode  :character               
##                                                             
##                                                             
##                                                             
##                                                             
##  allpartnersspouselivein12months condomlastnonmaritalsex12months
##  Length:2893                     Length:2893                    
##  Class :character                Class :character               
##  Mode  :character                Mode  :character               
##                                                                 
##                                                                 
##                                                                 
## 
hist(uphia$age)

plot(uphia$lifetimesex)

Tables stratified by all variables

table(uphia$gender, uphia$hivstatusfinal)
##         
##            99 negative positive
##   female  166     1309      104
##   male    255     1013       46
table(uphia$region, uphia$hivstatusfinal)
##     
##       99 negative positive
##   1   42      182       22
##   2   37      183       19
##   3   35      171       18
##   4   48      257       15
##   5   59      363       22
##   6   53      262       11
##   7   36      336        8
##   8   56      193       12
##   9   26      207       11
##   10  29      168       12
table(uphia$work12mo, uphia$hivstatusfinal)
##      
##         99 negative positive
##   -9     1        0        0
##   no    10     1113       62
##   yes   27     1209       88
table(uphia$occuptn, uphia$hivstatusfinal)
##                                    
##                                      99 negative positive
##   agriculture                         9      429       27
##   clerical                            0        3        2
##   domestic service                    1       64        3
##   other specify                       2       69        2
##   professional/technical/managerial   2      111        4
##   sales and services                  6      201       20
##   skiled manual                       1      109        8
##   unskilled manual                    6      223       22
table(uphia$ethnic, uphia$hivstatusfinal)
##                 
##                   99 negative positive
##   99             383        2        0
##   Acholi           4      216        4
##   Alur/Jopadhola   0       67        6
##   Baganda          9      325       38
##   BAgisu/Sabiny    1       47        6
##   Bakiga           0      205       10
##   Banyankole       1      159       14
##   Banyoro          9      577       28
##   Basoga           3      217       16
##   Iteso            4      214       11
##   Karimojong       4       67        7
##   Langi            3      135        4
##   Lugbara/Madi     0       91        6
table(uphia$mcstatus, uphia$hivstatusfinal)
##      
##        99 negative positive
##   -8    0        3        0
##   no   13      550       34
##   yes  11      460       12
table(uphia$urban, uphia$hivstatusfinal)
##      
##         99 negative positive
##   no   299     1705       90
##   yes  122      617       60
table(uphia$part12monum, uphia$hivstatusfinal)
##     
##        99 negative positive
##   -7    0        3        0
##   0     6      385       40
##   1    16     1393       85
##   2     4      225       14
##   3     2       56        2
##   4     0       16        0
##   5     1        8        2
##   6     0        3        1
##   7     2        5        2
table(uphia$region, uphia$hivstatusfinal)
##     
##       99 negative positive
##   1   42      182       22
##   2   37      183       19
##   3   35      171       18
##   4   48      257       15
##   5   59      363       22
##   6   53      262       11
##   7   36      336        8
##   8   56      193       12
##   9   26      207       11
##   10  29      168       12
table(uphia$wealthquintile, uphia$hivstatusfinal)
##            
##              99 negative positive
##   middle     81      425       32
##   poor       96      482       24
##   rich       59      370       41
##   very poor 107      652       15
##   very rich  78      393       38
table(uphia$education, uphia$hivstatusfinal)
##               
##                  99 negative positive
##   99            383       22        1
##   no education    5      194       10
##   primary        19     1013       69
##   secondary       5      347       21
##   tertiary        7      543       40
##   university      2      203        9
table(uphia$uniontype, uphia$hivstatusfinal)
##     
##       99 negative positive
##   1    4      329       20
##   2   14      923       46
##   3   17      996       74
##   99 386       74       10
table(uphia$marital, uphia$hivstatusfinal)
##                  
##                     99 negative positive
##   99               384        2        1
##   divorced           1       77       23
##   living together    1       44       10
##   married           20     1324       75
##   seperated         10      673       17
##   widowed            5      202       24
table(uphia$evertested, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   383        8        0
##   no     9      554       13
##   yes   29     1760      137
table(uphia$bt_status, uphia$hivstatusfinal)
##      
##         99 negative positive
##   9      0       55        2
##   no    36        0        0
##   yes    0     2267      148
table(uphia$sex12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   390      304        7
##   no     6      309       37
##   yes   25     1709      106
table(uphia$sexever, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   383        3        0
##   no     5      290        6
##   yes   33     2029      144
table(uphia$condomlastsex12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   3      6      309       37
##   99   391      319        9
##   no    22     1485       88
##   yes    2      209       16
table(uphia$lastpartnerrelation12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   3      3      208       19
##   4      1       47        2
##   5      3      192       10
##   8      0        2        0
##   9      0        2        1
##   96     0        4        0
##   99   397      627       46
##   no     1      145       12
##   yes   16     1095       60
table(uphia$lastpartnerspouselivein12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   397      627       46
##   no     7      455       32
##   yes   17     1240       72
table(uphia$allpartnersspouselivein12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   396      617       44
##   no    11      562       39
##   yes   14     1143       67
table(uphia$condomlastnonmaritalsex12months, uphia$hivstatusfinal)
##      
##         99 negative positive
##   99   410     1766      113
##   no     8      383       27
##   yes    3      173       10

Assessing Relationships

chisq.test(uphia$hivstatusfinal, uphia$gender)
## 
##  Pearson's Chi-squared test
## 
## data:  uphia$hivstatusfinal and uphia$gender
## X-squared = 55.163, df = 2, p-value = 1.051e-12
anova<-aov(uphia$age~uphia$hivstatusfinal)
summary(anova)
##                        Df Sum Sq Mean Sq F value Pr(>F)    
## uphia$hivstatusfinal    2  73481   36741   170.2 <2e-16 ***
## Residuals            2890 623708     216                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova1<-aov(uphia$age~uphia$wealthquintile)
summary(anova1)
##                        Df Sum Sq Mean Sq F value  Pr(>F)   
## uphia$wealthquintile    4   4383  1095.6   4.567 0.00112 **
## Residuals            2888 692806   239.9                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova2<-aov(uphia$age~uphia$hivstatusfinal)
summary(anova2)
##                        Df Sum Sq Mean Sq F value Pr(>F)    
## uphia$hivstatusfinal    2  73481   36741   170.2 <2e-16 ***
## Residuals            2890 623708     216                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova3<-aov(uphia$lifetimesex~uphia$condomlastsex12months)
summary(anova3)
##                               Df Sum Sq Mean Sq F value Pr(>F)    
## uphia$condomlastsex12months    3   1289   429.6   26.61 <2e-16 ***
## Residuals                   2231  36017    16.1                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 658 observations deleted due to missingness
chisq.test(uphia$education, uphia$urban)
## 
##  Pearson's Chi-squared test
## 
## data:  uphia$education and uphia$urban
## X-squared = 157.37, df = 5, p-value < 2.2e-16
chisq.test(uphia$wealthquintile, uphia$urban)
## 
##  Pearson's Chi-squared test
## 
## data:  uphia$wealthquintile and uphia$urban
## X-squared = 1209, df = 4, p-value < 2.2e-16

Necessary Plots

boxplot(uphia$age~uphia$hivstatusfinal)

boxplot(uphia$age~uphia$wealthquintile)

boxplot(uphia$lifetimesex~uphia$condomlastsex12months)

boxplot(uphia$lifetimesex~uphia$condomlastnonmaritalsex12months)

END