getwd()
## [1] "/Users/jared/Desktop/repitest"
## "/Users/jared/Desktop/jwilber.github.io" currently
search() # shows loaded packages
## [1] ".GlobalEnv" "package:stats" "package:graphics"
## [4] "package:grDevices" "package:utils" "package:datasets"
## [7] "package:methods" "Autoloads" "package:base"
searchpaths() #displays paths to loaded packages
## [1] ".GlobalEnv"
## [2] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/stats"
## [3] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/graphics"
## [4] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/grDevices"
## [5] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/utils"
## [6] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/datasets"
## [7] "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/methods"
## [8] "Autoloads"
## [9] "/Library/Frameworks/R.framework/Resources/library/base"
ls() # could also use objects()
## character(0)
rm(list = ls()) # removes all objects
inches <- 1:12
centimeters <- inches * 2.54 # use "*", not "/"
cbind(inches, centimeters)
## inches centimeters
## [1,] 1 2.54
## [2,] 2 5.08
## [3,] 3 7.62
## [4,] 4 10.16
## [5,] 5 12.70
## [6,] 6 15.24
## [7,] 7 17.78
## [8,] 8 20.32
## [9,] 9 22.86
## [10,] 10 25.40
## [11,] 11 27.94
## [12,] 12 30.48
points <- c(0,100)
points2 <- list(9 / 5 * points + 32)
print(paste("freezing: ", points2[[1]][1],
"boiling: ", points2[[1]][2]))
## [1] "freezing: 32 boiling: 212"
conv_to_f <- function(x) {
9 / 5 * x + 32
}
celsius <- seq(0, 100, 5)
print( cbind( celsius, conv_to_f(celsius)))
## celsius
## [1,] 0 32
## [2,] 5 41
## [3,] 10 50
## [4,] 15 59
## [5,] 20 68
## [6,] 25 77
## [7,] 30 86
## [8,] 35 95
## [9,] 40 104
## [10,] 45 113
## [11,] 50 122
## [12,] 55 131
## [13,] 60 140
## [14,] 65 149
## [15,] 70 158
## [16,] 75 167
## [17,] 80 176
## [18,] 85 185
## [19,] 90 194
## [20,] 95 203
## [21,] 100 212
bmi <- function(kg, m) {
kg / m**2
}
bmi(192/2.2, 6.3/3.3)
## [1] 23.94558
curve(log(x), 0, 6)
abline(v = c(1, exp(1)), h = c(0, 1), lty = 2)
It grows monotoincally (though very slowly) and is undefined for inputs below zero. This appears to be related to disease counts?
par(mfrow=c(1,2))
curve(x/(1-x), 0, 1)
curve(log(x/(1-x)), 0, 1)
The log transformation changes the range of values, allowing us to obtain negative numbers. Note that it also creates the sigmoid/logit function, which has far-reaching applications (e.g. logistic regression)
risks <- c(9000, 67, 50, 30, 10, 6.5, 5, 1, .5)
risks <- risks/10000
1 - (1-risks)**365
## [1] 1.00000000 0.91402762 0.83951869 0.66601052 0.30593011 0.21126678
## [7] 0.16685338 0.03584367 0.01808493
The risks make sense. We’d expect those events with smaller probabilities (per 10000 acts) to remain small (relative to the other risks). Likewise, we’d expect those activities for which risk is high to result in very high rates of infection given a large number of acts.
# source("~/Desktop/spring2016/stat154/hw2")
# It ran the selected file, displaying only the outout
# source("~/Desktop/spring2016/stat154/hw2")
# It ran the selected file, displaying both the output and the commands
# sink("~/Desktop/rforepi/jobs/job01.log1a")
# source("~/Desktop/rforepi/jobs/job01.R")
# sink() #closes connection
# sink("~/Desktop/rforepi/jobs/job01.log1b")
# source("~/Desktop/rforepi/jobs/job01.R", echo = TRUE)
# sink() #closes connection
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 above is in job3
# source("~/Desktop/rforepi/jobs/job01.R", echo = FALSE)
Unless echo = TRUE, source will not return anything to the screen (unless we use the show() function)