Question9_Page17
library(ggplot2)
# Set variables
n_vector <- seq(1, 15, 1)
delta_a <- c(3, 5, 10, 11, 15, 18, 22, 25, 28, 31, 33, 37, 41, 43, 51)
dt <- cbind.data.frame(n_vector, delta_a)
fig1 <- ggplot(dt, aes(x=n_vector, y=delta_a)) + geom_point(color = "purple")
fig1 <- fig1 + xlab("Speed n") + ylab("Delta")
fig1
fig2 <- fig1 + geom_abline(intercept = 0, slope = 3)
fig2
p <- 1000
n <- 0
r0 <- 4
k <- 0.001
r <- r0
loop_continue <- TRUE
r_n <- double()
while(loop_continue){
n <- n + 1
b <- r
r <- b + k*b*(p-b)
i <- trunc(r)
r_n <- c(r_n, i)
if(i>=p){
loop_continue <- FALSE
}
}
Question 13
n_vector <- seq(1, 14, 1)
dt <- cbind.data.frame(n_vector, r_n)
fig3 <- ggplot(dt, aes(x=n_vector, y=r_n)) + geom_point(colour = "blue")
fig3 <- fig3 + xlab("Days") + ylab("Number of People Rumor Reached")
fig3 <- fig3 + geom_text(aes(label = r_n, y=r_n-50), size = 3)
fig3
Page 69 Question 12
Page 79 Question 11
y <- c(0,1,2,6,14,24,37,58,82,114)
x <- 1:10
pmodelx <- x^3
k = median(y/pmodelx)
pmodely <- k*pmodelx
modeltest <- as.data.frame(cbind(x,y, pmodely))
ggplot(modeltest, aes(x))+
geom_line(aes(y=pmodely, colour = 'Stated Proportion'))+
geom_line(aes(y=y, colour = 'Actual Data'))