1.10.1 Workspace
It is where your R code and files are located and were all the data objects you create reside.
C:/Users/marss/Documents/R_Workspace
R_Workspace
“knitr”“,”rmarkdown“”, “.GlobalEnv”“,”tools:rstudio“,”package:stats“,”package:graphics“,”package:grDevices“,”package:utils“,”package:datasets“,”package:methods“,”Autoloads“,”package:base"
“C:/Program Files/R/R-3.5.1/library/
Current objects: “Cumulative_risk_IAI”, “Cumulative_risk_IDU,”Cumulative_risk_IOI“,”Cumulative_risk_IPVI“,”Cumulative_risk_PNS“,”Cumulative_risk_RAI“,”Cumulative_risk_ROI“,”Cumulative_risk_RPVI“,”P_IAI“,”P_IDU“,”P_IOI“, P_IPVI”, “P_PNS”, “P_RAI”, “P_ROI”, “P_RPVI”
1.10.2 Math Operations
Modulus: Gives you the remainder of a division problem
10%%3
## [1] 1
Integer Divide: Gives you the quotient of a division problem
10%/%3
## [1] 3
1.10.3 Body Mass Index
Caculated BMI (did not report as requested)
1.10.4 Logarithm
curve(log(x), 0, 6)
abline(v = c(1, exp(1)), h = c(0, 1), lty = 2)
Graph is logistic, meaning as X increases it eventually begins to level out/not climb as steeply.
1.10.5 Risk and Risk Odds
curve(x/(1-x), 0, 1)
curve(log(x/(1-x)), 0, 1)
Odds at is exponential and begins at 0, however when the log of odds is taken now both ends are infinity and -infinity.
1.10.6 HIV Transmission Probabilities
Needle-sharing injection-drug use (IDU):
P_IDU <- 67/10000
P_IDU
## [1] 0.0067
Cumulative_risk_IDU <- 1-(1-P_IDU)^365
Cumulative_risk_IDU
## [1] 0.9140276
Receptive anal intercourse (RAI):
P_RAI <- 50/10000
P_RAI
## [1] 0.005
Cumulative_risk_RAI <- 1-(1-P_RAI)^365
Cumulative_risk_RAI
## [1] 0.8395187
Percutaneous needle stick (PNS):
P_PNS <- 30/10000
P_PNS
## [1] 0.003
Cumulative_risk_PNS <- 1-(1-P_PNS)^365
Cumulative_risk_PNS
## [1] 0.6660105
Receptive penile-vaginal intercourse (RPVI):
P_RPVI <- 10/10000
P_RPVI
## [1] 0.001
Cumulative_risk_RPVI <- 1-(1-P_RPVI)^365
Cumulative_risk_RPVI
## [1] 0.3059301
Insertive anal intercourse (IAI):
P_IAI <- 6.5/10000
P_IAI
## [1] 0.00065
Cumulative_risk_IAI <- 1-(1-P_IAI)^365
Cumulative_risk_IAI
## [1] 0.2112668
Insertive penile-vaginal intercourse (IPVI):
P_IPVI <- 5/10000
P_IPVI
## [1] 5e-04
Cumulative_risk_IPVI <- 1-(1-P_IPVI)^365
Cumulative_risk_IPVI
## [1] 0.1668534
Receptive oral intercourse on penis (ROI):
P_ROI <- 1/10000
P_ROI
## [1] 1e-04
Cumulative_risk_ROI <- 1-(1-P_ROI)^365
Cumulative_risk_ROI
## [1] 0.03584367
Insertive oral intercourse with penis (IOI):
P_IOI <- 0.5/10000
P_IOI
## [1] 5e-05
Cumulative_risk_IOI <- 1-(1-P_IOI)^365
Cumulative_risk_IOI
## [1] 0.01808493
The cumulative risks do make sense because each time you do the same risky action you increase your overall chance of HIV infection.
1.10.7 Sourcing Files
source("C:/Users/marss/Documents/R_Workspace/job01.R")
The code runs/reads in directly into R but no output appears.
source("C:/Users/marss/Documents/R_Workspace/job01.R", echo = TRUE)
##
## > P_IDU <- 67/10000
##
## > P_IDU
## [1] 0.0067
##
## > Cumulative_risk_IDU <- 1 - (1 - P_IDU)^365
##
## > Cumulative_risk_IDU
## [1] 0.9140276
Adding echo = TRUE made R print the actual code in found in the file.
sink("C:/Users/marss/Documents/R_Workspace/job01.log1a")
source("C:/Users/marss/Documents/R_Workspace/job01.R")
sink()
sink("C:/Users/marss/Documents/R_Workspace/job01.log1b")
source("C:/Users/marss/Documents/R_Workspace/job01.R", echo = TRUE)
##
## > P_IDU <- 67/10000
##
## > P_IDU
## [1] 0.0067
##
## > Cumulative_risk_IDU <- 1 - (1 - P_IDU)^365
##
## > Cumulative_risk_IDU
## [1] 0.9140276
sink()
Created two new files, one blank (job01.log1a) and the other(job01.log1b) with the code found in the original job01.R file.
source("C:/Users/marss/Documents/R_Workspace/job02.R", echo = TRUE)
##
## > n <- 365
##
## > per.act.risk <- c(0.5, 1, 5, 6.5, 10, 30, 50, 67)/10000
##
## > risks <- 1 - (1 - per.act.risk)^n
##
## > show(risks)
## [1] 0.01808493 0.03584367 0.16685338 0.21126678 0.30593011 0.66601052
## [7] 0.83951869 0.91402762
The code calculated the cumulative risks that I calculated earlier, except in only a few lines rather than the many I wrote to complete the same task.