Skip to content

Instantly share code, notes, and snippets.

@mages
Last active January 3, 2016 04:09
tsNA <- ts(NA, start=c(2007, 1), end=c(2013, 12), frequency=12)
X <- merge(xt, tsNA)[,"xt"]
Z <- cumsum(X)
num.dates <- as.numeric(as.Date(time(Z)))
(summary(log.ss <- nls(Z ~ SSlogis(num.dates, K, xmid, r))))
#
# Formula: Z ~ SSlogis(num.dates, K, xmid, r)
#
# Parameters:
# Estimate Std. Error t value Pr(>|t|)
# K 14395.927 186.642 77.13 <2e-16 ***
# xmid 15344.129 11.829 1297.13 <2e-16 ***
# r 339.594 6.219 54.61 <2e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Residual standard error: 195.3 on 81 degrees of freedom
#
# Number of iterations to convergence: 0
# Achieved convergence tolerance: 1.605e-06
pred.dates <- min(num.dates) : as.numeric(as.Date("2016-12-31"))
pred <- predict(log.ss, data.frame(num.dates=pred.dates))
plot(pred ~ as.Date(pred.dates), t="l",
main = "Cumulative number of posts on R-bloggers",
xlab="Time", ylab="# blog posts")
points(time(Z), Z, col="blue")
pred[length(pred)] - sum(X)
# 1268.894
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment