morning <- 123
evening <- 456
rm(list = ls()); ls()
## character(0)
13%/%5 #integer divide: shows the quotient
## [1] 2
13%%5 #modulus divide: shows the remainder
## [1] 3
BMI = (155/2.2)/((5+7/12)/3.3)^2
BMI
## [1] 24.61216
curve(log(x),0,6)
abline(v = c(1,exp(1)), h = c(0,1), lty = 2)
log(e) = 1; when x < e, log(x) < 1; when x > e, log(x) > 1.
curve(x/(1-x), 0, 1)
curve(log(x/(1-x)), 0, 1)
When risk < 0.5, log(risk) < 0; when risk > 0.5, log(risk) > 0. As risk increases from 0 to 1, log(risk) also increases. The increase rate of log(risk) first decreases until risk = 0.5; after risk = 0.5, the increase rate of log(risk) goes up.
HIV_transmission <- c(67,50,30,10,6.5,5,1,0.5)
p <- HIV_transmission / 10000
cumulative_infection_risk <- 1-(1-p)^365
Exposure_route <- c("IDU","RAI","PNS","RPVI","IAI","IPVI","ROI","IOI")
result <- data.frame(Exposure_route, cumulative_infection_risk)
result
## Exposure_route cumulative_infection_risk
## 1 IDU 0.91402762
## 2 RAI 0.83951869
## 3 PNS 0.66601052
## 4 RPVI 0.30593011
## 5 IAI 0.21126678
## 6 IPVI 0.16685338
## 7 ROI 0.03584367
## 8 IOI 0.01808493
I think intuitively it doesn’t make sense because the above calculation is based on the assumption that the risk of each act is independent. However, I think that for each exposure route, there could be a cumulative effect, which means that the first act may affect the infection risk of the sencond act.
source("~/Desktop/job01.R")
# although there's no printout of the text file within the Rmarkdown, the variables within the text file appears in the environment.
source("~/Desktop/job01.R", echo = TRUE)
##
## > HIV_transmission_2 <- c(67, 50, 30, 10, 6.5, 5, 1,
## + 0.5)
##
## > p <- HIV_transmission_2/10000
##
## > cumulative_infection_risk <- 1 - (1 - p)^365
##
## > Exposure_route <- c("IDU", "RAI", "PNS", "RPVI", "IAI",
## + "IPVI", "ROI", "IOI")
##
## > result <- data.frame(Exposure_route, cumulative_infection_risk)
##
## > result
## Exposure_route cumulative_infection_risk
## 1 IDU 0.91402762
## 2 RAI 0.83951869
## 3 PNS 0.66601052
## 4 RPVI 0.30593011
## 5 IAI 0.21126678
## 6 IPVI 0.16685338
## 7 ROI 0.03584367
## 8 IOI 0.01808493
# When I ran the code, it shows all the commands in the text file, and it also evaluates (shows the result) of the code within the text file.
sink("~/Desktop/job01.log1a")
source("~/Desktop/job01.R")
sink()
# there's nothing in the job01.log1a file
sink("~/Desktop/job01.log1b")
source("~/Desktop/job01.R", echo = TRUE)
##
## > HIV_transmission_2 <- c(67, 50, 30, 10, 6.5, 5, 1,
## + 0.5)
##
## > p <- HIV_transmission_2/10000
##
## > cumulative_infection_risk <- 1 - (1 - p)^365
##
## > Exposure_route <- c("IDU", "RAI", "PNS", "RPVI", "IAI",
## + "IPVI", "ROI", "IOI")
##
## > result <- data.frame(Exposure_route, cumulative_infection_risk)
##
## > result
## Exposure_route cumulative_infection_risk
## 1 IDU 0.91402762
## 2 RAI 0.83951869
## 3 PNS 0.66601052
## 4 RPVI 0.30593011
## 5 IAI 0.21126678
## 6 IPVI 0.16685338
## 7 ROI 0.03584367
## 8 IOI 0.01808493
sink()
# job01.log1b file prints out all commans in text file job01.R, and it also evaluate the code within the text file. Basically, the log1b file stores the output of source(... echo = TRUE) into a new file.
source("~/Desktop/job02.R")
## [1] 0.01808493 0.03584367 0.16685338 0.21126678 0.30593011 0.66601052
## [7] 0.83951869 0.91402762
# although there's no printout of the text file within the Rmarkdown, the variables within the text file appears in the environment.