In March 2020, the Covid-19 pandemic began to take hold in the United States. In that first month, the virus spread exponentially as more and more people tested positive for the virus. My project focuses primarily on the state of New York where some of the highest numbers of positive Covid-19 tests were seen in the US.
Cited from https://coronavirus.health.ny.gov/positive-tests-over-time-region-and-county
x <- seq(1,31,1)
x # x = number of days
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31
y <- c(0,1,0,2,22,11,24,28,63,44,56,102,164,131,294,432,1009,1769,2950,3254,4812,5707,4790,5145,6448,7379,7681,7195,6984,9298,7917)
y # y = number of positive Covid-19 tests in New York State
## [1] 0 1 0 2 22 11 24 28 63 44 56 102 164 131 294
## [16] 432 1009 1769 2950 3254 4812 5707 4790 5145 6448 7379 7681 7195 6984 9298
## [31] 7917
plot(x, y, main="Growth of Covid-19 March 2020",
xlab= "Time (days)", ylab="Positive Covid-19 Tests",
xlim = c(0,31), ylim=c(0,10000))
In the following program, we will use the calculated half-life of the virus to create an additional exponential growth as well as logistic model for the data set.
t <- 0 # initial time
P <- 10000 # number of people
N = 31 # Number of time increments
Time = 31 # each time is one day
dt <- Time/N
k = 0.3 # rate constant per day
#P = 10000, Pini = 1, t = 31 for equation ln(P/Pini)=k*t
# t[1] and P[1] are initialized
for(i in 2:N)
{ t[i] <- t[i-1] + dt
P[i] <- P[i-1] + k*P[i-1]*dt
print(P)
}
## [1] 10000 13000
## [1] 10000 13000 16900
## [1] 10000 13000 16900 21970
## [1] 10000 13000 16900 21970 28561
## [1] 10000.0 13000.0 16900.0 21970.0 28561.0 37129.3
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09 62748.52
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09 62748.52
## [9] 81573.07
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85 302875.11
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85 302875.11
## [15] 393737.64
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85 302875.11
## [15] 393737.64 511858.93
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85 302875.11
## [15] 393737.64 511858.93 665416.61
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30 48268.09
## [8] 62748.52 81573.07 106044.99 137858.49 179216.04 232980.85 302875.11
## [15] 393737.64 511858.93 665416.61 865041.59
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02 11925332.93
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02 11925332.93 15502932.80
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02 11925332.93 15502932.80 20153812.64
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02 11925332.93 15502932.80 20153812.64
## [31] 26199956.44
t
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## [26] 25 26 27 28 29 30
P
## [1] 10000.00 13000.00 16900.00 21970.00 28561.00 37129.30
## [7] 48268.09 62748.52 81573.07 106044.99 137858.49 179216.04
## [13] 232980.85 302875.11 393737.64 511858.93 665416.61 865041.59
## [19] 1124554.07 1461920.29 1900496.38 2470645.29 3211838.88 4175390.54
## [25] 5428007.70 7056410.01 9173333.02 11925332.93 15502932.80 20153812.64
## [31] 26199956.44
plot(t,P,type = "p", main="Exponential Growth of Covid-19 March 2020", xlab= "Time (days)", ylab="Positive Covid-19 Tests",xlim = c(0,Time), ylim = c(10000,15000000), col = "red")
Pc <- P[1] * exp(k*t)
lines(t,Pc)
# Logistic equation
Cap <- 1000000
t <- 0 # initialize time
P <- 10000 # number of people
N = 31 # Number of time increments
Time = 31 # each time is one day
dt <- Time/N
k = 0.3 # rate constant sec-1
# t[1] and P[1] are initialized
for(i in 2:N)
{ t[i] <- t[i-1] + dt
P[i] <- P[i-1] + k*P[i-1]* (1-P[i-1]/Cap) * dt # we did by hand
print(P)
}
## [1] 10000 12970
## [1] 10000.00 12970.00 16810.53
## [1] 10000.00 12970.00 16810.53 21768.92
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08 60284.78
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08 60284.78
## [9] 77279.93
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08 60284.78
## [9] 77279.93 98672.26
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55 965760.95
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55 965760.95
## [29] 975680.97
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55 965760.95
## [29] 975680.97 982799.25
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55 965760.95
## [29] 975680.97 982799.25 987870.72
t
## [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## [26] 25 26 27 28 29 30
P
## [1] 10000.00 12970.00 16810.53 21768.92 28157.42 36366.80 46880.08
## [8] 60284.78 77279.93 98672.26 125353.07 158244.97 198206.02 245882.14
## [15] 301509.38 364689.82 434197.17 507898.16 582879.45 655818.75 723534.90
## [22] 783544.55 834425.29 875873.21 908489.01 933430.03 952071.55 965760.95
## [29] 975680.97 982799.25 987870.72
plot(t,P,type = "p",main="Logistic Model of Covid-19 Growth",xlim = c(0,Time), ylim = c(10000,1000000),
col = "red")
Pc <- P[1] * exp(k*t)
lines(t,Pc)
Pex = Cap / (1+(Cap/100+1) * exp(k*t))
x <- seq(15,31,1)
x # x = number of days
## [1] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
y <- c(294,432,1009,1769,2950,3254,4812,5707,4790,5145,6448,7379,7681,7195,6984,9298,7917)
y # y = number of positive Covid-19 tests in New York State
## [1] 294 432 1009 1769 2950 3254 4812 5707 4790 5145 6448 7379 7681 7195 6984
## [16] 9298 7917
tryfit <- nls(y~a * x ^ 3 + b * x + c,
start = list(a = 1, b = 2, c = 1))
plot(x, y, col.lab ="black",
col.axis ="black")
lines(x, predict(tryfit))
# error value
print(sum(resid(tryfit)^2))
## [1] 5756980
summary(tryfit)
##
## Formula: y ~ a * x^3 + b * x + c
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## a -2.971e-01 1.054e-01 -2.820 0.0136 *
## b 1.024e+03 1.746e+02 5.861 4.14e-05 ***
## c -1.455e+04 2.603e+03 -5.589 6.67e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 641.3 on 14 degrees of freedom
##
## Number of iterations to convergence: 1
## Achieved convergence tolerance: 1.025e-07