test_prophet.R 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. library(prophet)
  2. context("Prophet tests")
  3. DATA <- read.csv('data.csv')
  4. N <- nrow(DATA)
  5. train <- DATA[1:floor(N / 2), ]
  6. future <- DATA[(ceiling(N/2) + 1):N, ]
  7. DATA2 <- read.csv('data2.csv')
  8. test_that("fit_predict", {
  9. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  10. m <- prophet(train)
  11. expect_error(predict(m, future), NA)
  12. })
  13. test_that("fit_predict_no_seasons", {
  14. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  15. m <- prophet(train, weekly.seasonality = FALSE, yearly.seasonality = FALSE)
  16. expect_error(predict(m, future), NA)
  17. })
  18. test_that("fit_predict_no_changepoints", {
  19. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  20. m <- prophet(train, n.changepoints = 0)
  21. expect_error(predict(m, future), NA)
  22. })
  23. test_that("fit_predict_changepoint_not_in_history", {
  24. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  25. train_t <- dplyr::mutate(DATA, ds=prophet:::set_date(ds))
  26. train_t <- dplyr::filter(train_t,
  27. (ds < prophet:::set_date('2013-01-01')) |
  28. (ds > prophet:::set_date('2014-01-01')))
  29. future <- data.frame(ds=DATA$ds)
  30. m <- prophet(train_t, changepoints=c('2013-06-06'))
  31. expect_error(predict(m, future), NA)
  32. })
  33. test_that("fit_predict_duplicates", {
  34. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  35. train2 <- train
  36. train2$y <- train2$y + 10
  37. train_t <- rbind(train, train2)
  38. m <- prophet(train_t)
  39. expect_error(predict(m, future), NA)
  40. })
  41. test_that("fit_predict_constant_history", {
  42. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  43. train2 <- train
  44. train2$y <- 20
  45. m <- prophet(train2)
  46. fcst <- predict(m, future)
  47. expect_equal(tail(fcst$yhat, 1), 20)
  48. train2$y <- 0
  49. m <- prophet(train2)
  50. fcst <- predict(m, future)
  51. expect_equal(tail(fcst$yhat, 1), 0)
  52. })
  53. test_that("setup_dataframe", {
  54. history <- train
  55. m <- prophet(history, fit = FALSE)
  56. out <- prophet:::setup_dataframe(m, history, initialize_scales = TRUE)
  57. history <- out$df
  58. expect_true('t' %in% colnames(history))
  59. expect_equal(min(history$t), 0)
  60. expect_equal(max(history$t), 1)
  61. expect_true('y_scaled' %in% colnames(history))
  62. expect_equal(max(history$y_scaled), 1)
  63. })
  64. test_that("get_changepoints", {
  65. history <- train
  66. m <- prophet(history, fit = FALSE)
  67. out <- prophet:::setup_dataframe(m, history, initialize_scales = TRUE)
  68. history <- out$df
  69. m <- out$m
  70. m$history <- history
  71. m <- prophet:::set_changepoints(m)
  72. cp <- m$changepoints.t
  73. expect_equal(length(cp), m$n.changepoints)
  74. expect_true(min(cp) > 0)
  75. expect_true(max(cp) < N)
  76. mat <- prophet:::get_changepoint_matrix(m)
  77. expect_equal(nrow(mat), floor(N / 2))
  78. expect_equal(ncol(mat), m$n.changepoints)
  79. })
  80. test_that("get_zero_changepoints", {
  81. history <- train
  82. m <- prophet(history, n.changepoints = 0, fit = FALSE)
  83. out <- prophet:::setup_dataframe(m, history, initialize_scales = TRUE)
  84. m <- out$m
  85. history <- out$df
  86. m$history <- history
  87. m <- prophet:::set_changepoints(m)
  88. cp <- m$changepoints.t
  89. expect_equal(length(cp), 1)
  90. expect_equal(cp[1], 0)
  91. mat <- prophet:::get_changepoint_matrix(m)
  92. expect_equal(nrow(mat), floor(N / 2))
  93. expect_equal(ncol(mat), 1)
  94. })
  95. test_that("override_n_changepoints", {
  96. history <- train[1:20,]
  97. m <- prophet(history, fit = FALSE)
  98. out <- prophet:::setup_dataframe(m, history, initialize_scales = TRUE)
  99. m <- out$m
  100. history <- out$df
  101. m$history <- history
  102. m <- prophet:::set_changepoints(m)
  103. expect_equal(m$n.changepoints, 15)
  104. cp <- m$changepoints.t
  105. expect_equal(length(cp), 15)
  106. })
  107. test_that("fourier_series_weekly", {
  108. mat <- prophet:::fourier_series(DATA$ds, 7, 3)
  109. true.values <- c(0.9165623, 0.3998920, 0.7330519, -0.6801727, -0.3302791,
  110. -0.9438833)
  111. expect_equal(true.values, mat[1, ], tolerance = 1e-6)
  112. })
  113. test_that("fourier_series_yearly", {
  114. mat <- prophet:::fourier_series(DATA$ds, 365.25, 3)
  115. true.values <- c(0.69702635, -0.71704551, -0.99959923, 0.02830854,
  116. 0.73648994, 0.67644849)
  117. expect_equal(true.values, mat[1, ], tolerance = 1e-6)
  118. })
  119. test_that("growth_init", {
  120. history <- DATA[1:468, ]
  121. history$cap <- max(history$y)
  122. m <- prophet(history, growth = 'logistic', fit = FALSE)
  123. out <- prophet:::setup_dataframe(m, history, initialize_scales = TRUE)
  124. m <- out$m
  125. history <- out$df
  126. params <- prophet:::linear_growth_init(history)
  127. expect_equal(params[1], 0.3055671, tolerance = 1e-6)
  128. expect_equal(params[2], 0.5307511, tolerance = 1e-6)
  129. params <- prophet:::logistic_growth_init(history)
  130. expect_equal(params[1], 1.507925, tolerance = 1e-6)
  131. expect_equal(params[2], -0.08167497, tolerance = 1e-6)
  132. })
  133. test_that("piecewise_linear", {
  134. t <- seq(0, 10)
  135. m <- 0
  136. k <- 1.0
  137. deltas <- c(0.5)
  138. changepoint.ts <- c(5)
  139. y <- prophet:::piecewise_linear(t, deltas, k, m, changepoint.ts)
  140. y.true <- c(0, 1, 2, 3, 4, 5, 6.5, 8, 9.5, 11, 12.5)
  141. expect_equal(y, y.true)
  142. t <- t[8:length(t)]
  143. y.true <- y.true[8:length(y.true)]
  144. y <- prophet:::piecewise_linear(t, deltas, k, m, changepoint.ts)
  145. expect_equal(y, y.true)
  146. })
  147. test_that("piecewise_logistic", {
  148. t <- seq(0, 10)
  149. cap <- rep(10, 11)
  150. m <- 0
  151. k <- 1.0
  152. deltas <- c(0.5)
  153. changepoint.ts <- c(5)
  154. y <- prophet:::piecewise_logistic(t, cap, deltas, k, m, changepoint.ts)
  155. y.true <- c(5.000000, 7.310586, 8.807971, 9.525741, 9.820138, 9.933071,
  156. 9.984988, 9.996646, 9.999252, 9.999833, 9.999963)
  157. expect_equal(y, y.true, tolerance = 1e-6)
  158. t <- t[8:length(t)]
  159. y.true <- y.true[8:length(y.true)]
  160. cap <- cap[8:length(cap)]
  161. y <- prophet:::piecewise_logistic(t, cap, deltas, k, m, changepoint.ts)
  162. expect_equal(y, y.true, tolerance = 1e-6)
  163. })
  164. test_that("holidays", {
  165. holidays = data.frame(ds = c('2016-12-25'),
  166. holiday = c('xmas'),
  167. lower_window = c(-1),
  168. upper_window = c(0))
  169. df <- data.frame(
  170. ds = seq(prophet:::set_date('2016-12-20'),
  171. prophet:::set_date('2016-12-31'), by='d'))
  172. m <- prophet(train, holidays = holidays, fit = FALSE)
  173. out <- prophet:::make_holiday_features(m, df$ds)
  174. feats <- out$holiday.features
  175. priors <- out$prior.scales
  176. expect_equal(nrow(feats), nrow(df))
  177. expect_equal(ncol(feats), 2)
  178. expect_equal(sum(colSums(feats) - c(1, 1)), 0)
  179. expect_true(all(priors == c(10., 10.)))
  180. holidays = data.frame(ds = c('2016-12-25'),
  181. holiday = c('xmas'),
  182. lower_window = c(-1),
  183. upper_window = c(10))
  184. m <- prophet(train, holidays = holidays, fit = FALSE)
  185. out <- prophet:::make_holiday_features(m, df$ds)
  186. feats <- out$holiday.features
  187. priors <- out$prior.scales
  188. expect_equal(nrow(feats), nrow(df))
  189. expect_equal(ncol(feats), 12)
  190. expect_true(all(priors == rep(10, 12)))
  191. # Check prior specifications
  192. holidays <- data.frame(
  193. ds = prophet:::set_date(c('2016-12-25', '2017-12-25')),
  194. holiday = c('xmas', 'xmas'),
  195. lower_window = c(-1, -1),
  196. upper_window = c(0, 0),
  197. prior_scale = c(5., 5.)
  198. )
  199. m <- prophet(holidays = holidays, fit = FALSE)
  200. out <- prophet:::make_holiday_features(m, df$ds)
  201. priors <- out$prior.scales
  202. expect_true(all(priors == c(5., 5.)))
  203. # 2 different priors
  204. holidays2 <- data.frame(
  205. ds = prophet:::set_date(c('2012-06-06', '2013-06-06')),
  206. holiday = c('seans-bday', 'seans-bday'),
  207. lower_window = c(0, 0),
  208. upper_window = c(1, 1),
  209. prior_scale = c(8, 8)
  210. )
  211. holidays2 <- rbind(holidays, holidays2)
  212. m <- prophet(holidays = holidays2, fit = FALSE)
  213. out <- prophet:::make_holiday_features(m, df$ds)
  214. priors <- out$prior.scales
  215. expect_true(all(priors == c(8, 8, 5, 5)))
  216. holidays2 <- data.frame(
  217. ds = prophet:::set_date(c('2012-06-06', '2013-06-06')),
  218. holiday = c('seans-bday', 'seans-bday'),
  219. lower_window = c(0, 0),
  220. upper_window = c(1, 1)
  221. )
  222. holidays2 <- dplyr::bind_rows(holidays, holidays2)
  223. m <- prophet(holidays = holidays2, fit = FALSE, holidays.prior.scale = 4)
  224. out <- prophet:::make_holiday_features(m, df$ds)
  225. priors <- out$prior.scales
  226. expect_true(all(priors == c(4, 4, 5, 5)))
  227. # Check incompatible priors
  228. holidays <- data.frame(
  229. ds = prophet:::set_date(c('2016-12-25', '2016-12-27')),
  230. holiday = c('xmasish', 'xmasish'),
  231. lower_window = c(-1, -1),
  232. upper_window = c(0, 0),
  233. prior_scale = c(5., 6.)
  234. )
  235. m <- prophet(holidays = holidays, fit = FALSE)
  236. expect_error(prophet:::make_holiday_features(m, df$ds))
  237. })
  238. test_that("fit_with_holidays", {
  239. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  240. holidays <- data.frame(ds = c('2012-06-06', '2013-06-06'),
  241. holiday = c('seans-bday', 'seans-bday'),
  242. lower_window = c(0, 0),
  243. upper_window = c(1, 1))
  244. m <- prophet(DATA, holidays = holidays, uncertainty.samples = 0)
  245. expect_error(predict(m), NA)
  246. })
  247. test_that("make_future_dataframe", {
  248. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  249. train.t <- DATA[1:234, ]
  250. m <- prophet(train.t)
  251. future <- make_future_dataframe(m, periods = 3, freq = 'day',
  252. include_history = FALSE)
  253. correct <- prophet:::set_date(c('2013-04-26', '2013-04-27', '2013-04-28'))
  254. expect_equal(future$ds, correct)
  255. future <- make_future_dataframe(m, periods = 3, freq = 'month',
  256. include_history = FALSE)
  257. correct <- prophet:::set_date(c('2013-05-25', '2013-06-25', '2013-07-25'))
  258. expect_equal(future$ds, correct)
  259. })
  260. test_that("auto_weekly_seasonality", {
  261. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  262. # Should be enabled
  263. N.w <- 15
  264. train.w <- DATA[1:N.w, ]
  265. m <- prophet(train.w, fit = FALSE)
  266. expect_equal(m$weekly.seasonality, 'auto')
  267. m <- fit.prophet(m, train.w)
  268. expect_true('weekly' %in% names(m$seasonalities))
  269. true <- list(period = 7, fourier.order = 3, prior.scale = 10)
  270. for (name in names(true)) {
  271. expect_equal(m$seasonalities$weekly[[name]], true[[name]])
  272. }
  273. # Should be disabled due to too short history
  274. N.w <- 9
  275. train.w <- DATA[1:N.w, ]
  276. m <- prophet(train.w)
  277. expect_false('weekly' %in% names(m$seasonalities))
  278. m <- prophet(train.w, weekly.seasonality = TRUE)
  279. expect_true('weekly' %in% names(m$seasonalities))
  280. # Should be False due to weekly spacing
  281. train.w <- DATA[seq(1, nrow(DATA), 7), ]
  282. m <- prophet(train.w)
  283. expect_false('weekly' %in% names(m$seasonalities))
  284. m <- prophet(DATA, weekly.seasonality = 2, seasonality.prior.scale = 3)
  285. true <- list(period = 7, fourier.order = 2, prior.scale = 3)
  286. for (name in names(true)) {
  287. expect_equal(m$seasonalities$weekly[[name]], true[[name]])
  288. }
  289. })
  290. test_that("auto_yearly_seasonality", {
  291. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  292. # Should be enabled
  293. m <- prophet(DATA, fit = FALSE)
  294. expect_equal(m$yearly.seasonality, 'auto')
  295. m <- fit.prophet(m, DATA)
  296. expect_true('yearly' %in% names(m$seasonalities))
  297. true <- list(period = 365.25, fourier.order = 10, prior.scale = 10)
  298. for (name in names(true)) {
  299. expect_equal(m$seasonalities$yearly[[name]], true[[name]])
  300. }
  301. # Should be disabled due to too short history
  302. N.w <- 240
  303. train.y <- DATA[1:N.w, ]
  304. m <- prophet(train.y)
  305. expect_false('yearly' %in% names(m$seasonalities))
  306. m <- prophet(train.y, yearly.seasonality = TRUE)
  307. expect_true('yearly' %in% names(m$seasonalities))
  308. m <- prophet(DATA, yearly.seasonality = 7, seasonality.prior.scale = 3)
  309. true <- list(period = 365.25, fourier.order = 7, prior.scale = 3)
  310. for (name in names(true)) {
  311. expect_equal(m$seasonalities$yearly[[name]], true[[name]])
  312. }
  313. })
  314. test_that("auto_daily_seasonality", {
  315. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  316. # Should be enabled
  317. m <- prophet(DATA2, fit = FALSE)
  318. expect_equal(m$daily.seasonality, 'auto')
  319. m <- fit.prophet(m, DATA2)
  320. expect_true('daily' %in% names(m$seasonalities))
  321. true <- list(period = 1, fourier.order = 4, prior.scale = 10)
  322. for (name in names(true)) {
  323. expect_equal(m$seasonalities$daily[[name]], true[[name]])
  324. }
  325. # Should be disabled due to too short history
  326. N.d <- 430
  327. train.y <- DATA2[1:N.d, ]
  328. m <- prophet(train.y)
  329. expect_false('daily' %in% names(m$seasonalities))
  330. m <- prophet(train.y, daily.seasonality = TRUE)
  331. expect_true('daily' %in% names(m$seasonalities))
  332. m <- prophet(DATA2, daily.seasonality = 7, seasonality.prior.scale = 3)
  333. true <- list(period = 1, fourier.order = 7, prior.scale = 3)
  334. for (name in names(true)) {
  335. expect_equal(m$seasonalities$daily[[name]], true[[name]])
  336. }
  337. m <- prophet(DATA)
  338. expect_false('daily' %in% names(m$seasonalities))
  339. })
  340. test_that("test_subdaily_holidays", {
  341. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  342. holidays <- data.frame(ds = c('2017-01-02'),
  343. holiday = c('special_day'))
  344. m <- prophet(DATA2, holidays=holidays)
  345. fcst <- predict(m)
  346. expect_equal(sum(fcst$special_day == 0), 575)
  347. })
  348. test_that("custom_seasonality", {
  349. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  350. holidays <- data.frame(ds = c('2017-01-02'),
  351. holiday = c('special_day'),
  352. prior_scale = c(4))
  353. m <- prophet(holidays=holidays)
  354. m <- add_seasonality(m, name='monthly', period=30, fourier.order=5)
  355. true <- list(period = 30, fourier.order = 5, prior.scale = 10)
  356. for (name in names(true)) {
  357. expect_equal(m$seasonalities$monthly[[name]], true[[name]])
  358. }
  359. expect_error(
  360. add_seasonality(m, name='special_day', period=30, fourier_order=5)
  361. )
  362. expect_error(
  363. add_seasonality(m, name='trend', period=30, fourier_order=5)
  364. )
  365. m <- add_seasonality(m, name='weekly', period=30, fourier.order=5)
  366. # Test priors
  367. m <- prophet(holidays = holidays, yearly.seasonality = FALSE)
  368. m <- add_seasonality(
  369. m, name='monthly', period=30, fourier.order=5, prior.scale = 2)
  370. m <- fit.prophet(m, DATA)
  371. prior.scales <- prophet:::make_all_seasonality_features(
  372. m, m$history)$prior.scales
  373. expect_true(all(prior.scales == c(rep(2, 10), rep(10, 6), 4)))
  374. })
  375. test_that("added_regressors", {
  376. skip_if_not(Sys.getenv('R_ARCH') != '/i386')
  377. m <- prophet()
  378. m <- add_regressor(m, 'binary_feature', prior.scale=0.2)
  379. m <- add_regressor(m, 'numeric_feature', prior.scale=0.5)
  380. m <- add_regressor(m, 'binary_feature2', standardize=TRUE)
  381. df <- DATA
  382. df$binary_feature <- c(rep(0, 255), rep(1, 255))
  383. df$numeric_feature <- 0:509
  384. # Require all regressors in df
  385. expect_error(
  386. fit.prophet(m, df)
  387. )
  388. df$binary_feature2 <- c(rep(1, 100), rep(0, 410))
  389. m <- fit.prophet(m, df)
  390. # Check that standardizations are correctly set
  391. true <- list(prior.scale = 0.2, mu = 0, std = 1, standardize = 'auto')
  392. for (name in names(true)) {
  393. expect_equal(true[[name]], m$extra_regressors$binary_feature[[name]])
  394. }
  395. true <- list(prior.scale = 0.5, mu = 254.5, std = 147.368585)
  396. for (name in names(true)) {
  397. expect_equal(true[[name]], m$extra_regressors$numeric_feature[[name]],
  398. tolerance = 1e-5)
  399. }
  400. true <- list(prior.scale = 10., mu = 0.1960784, std = 0.3974183)
  401. for (name in names(true)) {
  402. expect_equal(true[[name]], m$extra_regressors$binary_feature2[[name]],
  403. tolerance = 1e-5)
  404. }
  405. # Check that standardization is done correctly
  406. df2 <- prophet:::setup_dataframe(m, df)$df
  407. expect_equal(df2$binary_feature[1], 0)
  408. expect_equal(df2$numeric_feature[1], -1.726962, tolerance = 1e-4)
  409. expect_equal(df2$binary_feature2[1], 2.022859, tolerance = 1e-4)
  410. # Check that feature matrix and prior scales are correctly constructed
  411. out <- prophet:::make_all_seasonality_features(m, df2)
  412. seasonal.features <- out$seasonal.features
  413. prior.scales <- out$prior.scales
  414. expect_true('binary_feature' %in% colnames(seasonal.features))
  415. expect_true('numeric_feature' %in% colnames(seasonal.features))
  416. expect_true('binary_feature2' %in% colnames(seasonal.features))
  417. expect_equal(ncol(seasonal.features), 29)
  418. expect_true(all(sort(prior.scales[27:29]) == c(0.2, 0.5, 10.)))
  419. # Check that forecast components are reasonable
  420. future <- data.frame(
  421. ds = c('2014-06-01'), binary_feature = c(0), numeric_feature = c(10))
  422. expect_error(predict(m, future))
  423. future$binary_feature2 <- 0.
  424. fcst <- predict(m, future)
  425. expect_equal(ncol(fcst), 31)
  426. expect_equal(fcst$binary_feature[1], 0)
  427. expect_equal(fcst$extra_regressors[1],
  428. fcst$numeric_feature[1] + fcst$binary_feature2[1])
  429. expect_equal(fcst$seasonalities[1], fcst$yearly[1] + fcst$weekly[1])
  430. expect_equal(fcst$seasonal[1],
  431. fcst$seasonalities[1] + fcst$extra_regressors[1])
  432. expect_equal(fcst$yhat[1], fcst$trend[1] + fcst$seasonal[1])
  433. })
  434. test_that("copy", {
  435. inputs <- list(
  436. growth = c('linear', 'logistic'),
  437. changepoints = c(NULL, c('2016-12-25')),
  438. n.changepoints = c(3),
  439. yearly.seasonality = c(TRUE, FALSE),
  440. weekly.seasonality = c(TRUE, FALSE),
  441. daily.seasonality = c(TRUE, FALSE),
  442. holidays = c(NULL, 'insert_dataframe'),
  443. seasonality.prior.scale = c(1.1),
  444. holidays.prior.scale = c(1.1),
  445. changepoints.prior.scale = c(0.1),
  446. mcmc.samples = c(100),
  447. interval.width = c(0.9),
  448. uncertainty.samples = c(200)
  449. )
  450. products <- expand.grid(inputs)
  451. for (i in 1:length(products)) {
  452. if (products$holidays[i] == 'insert_dataframe') {
  453. holidays <- data.frame(ds=c('2016-12-25'), holiday=c('x'))
  454. } else {
  455. holidays <- NULL
  456. }
  457. m1 <- prophet(
  458. growth = products$growth[i],
  459. changepoints = products$changepoints[i],
  460. n.changepoints = products$n.changepoints[i],
  461. yearly.seasonality = products$yearly.seasonality[i],
  462. weekly.seasonality = products$weekly.seasonality[i],
  463. daily.seasonality = products$daily.seasonality[i],
  464. holidays = holidays,
  465. seasonality.prior.scale = products$seasonality.prior.scale[i],
  466. holidays.prior.scale = products$holidays.prior.scale[i],
  467. changepoints.prior.scale = products$changepoints.prior.scale[i],
  468. mcmc.samples = products$mcmc.samples[i],
  469. interval.width = products$interval.width[i],
  470. uncertainty.samples = products$uncertainty.samples[i],
  471. fit = FALSE
  472. )
  473. m2 <- prophet:::prophet_copy(m1)
  474. # Values should be copied correctly
  475. for (arg in names(inputs)) {
  476. expect_equal(m1[[arg]], m2[[arg]])
  477. }
  478. }
  479. # Check for cutoff
  480. changepoints <- seq.Date(as.Date('2012-06-15'), as.Date('2012-09-15'), by='d')
  481. cutoff <- as.Date('2012-07-25')
  482. m1 <- prophet(DATA, changepoints = changepoints)
  483. m2 <- prophet:::prophet_copy(m1, cutoff)
  484. changepoints <- changepoints[changepoints <= cutoff]
  485. expect_equal(prophet:::set_date(changepoints), m2$changepoints)
  486. })