add_regressor with continuous variable warning: longer object length is not a multiple of shorter object length
See original GitHub issueHi,
I really love your package and happy that add_regressor feature was added. However I faced a strange warning and felt not very comfortable adding several regressors with multiple calls to add_regressor.
- Let’s start with the warning:
Here are two reproducible examples.
The first one is based on tutorial example data
df <- read.csv("https://raw.githubusercontent.com/facebookincubator/prophet/master/examples/example_wp_peyton_manning.csv")
set.seed(42)
# Add random zeros and ones (code from original add_regressors example somehow returns only zeros)
df$nfl_sunday <- sample(c(0, 1), 2905, replace = TRUE)
# Fit model
m <- prophet()
m <- add_regressor(m, 'nfl_sunday')
m <- fit.prophet(m, df)
# Make future data.frame
future <- make_future_dataframe(m, periods = 365)
# Yep I know that is not correct way to add future values in case of randomly generated data
future$nfl_sunday <- sample(c(0, 1), 3270, replace = TRUE)`
In the end I get no trouble. The model is fitted correctly:
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
Initial log joint probability = -4.27118
Optimization terminated normally:
Convergence detected: relative gradient magnitude is below tolerance
Now let me try an example with continuous regressor:
df <-
read.csv("https://raw.githubusercontent.com/facebookincubator/prophet/master/examples/example_wp_peyton_manning.csv")
set.seed(42)
# Add random normal
df$nfl_sunday <- rnorm(2905)
# Fit model
m <- prophet()
m <- add_regressor(m, 'nfl_sunday')
m <- fit.prophet(m, df)
# Make future data.frame
future <- make_future_dataframe(m, periods = 365)
# Yep I know that is not correct way to add future values in case of randomly generated data
future$nfl_sunday <- rnorm(3270)
After this I get a warning message, though the model seems to have been fitted:
Optimization terminated normally:
Convergence detected: relative gradient magnitude is below tolerance
Warning message:
In sort(unique(df[[name]])) == c(0, 1) :
longer object length is not a multiple of shorter object length
- Also it would be cool to add several regressors with one call to
add_regressor()
.
Thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How To Fix R Error Message: longer object length is not a ...
The longer object length is not a multiple of shorter object length R warning message appears when you place vectors of different lengths...
Read more >Why do I get "warning longer object length is not a multiple of ...
If the longer object is a multiple of the shorter, this amounts to simply repeating the shorter object several times. Oftentimes R programmers ......
Read more >Forecast Model Tuning with Additional Regressors in Prophet
Regressor must be a variable which was known in the past and known (or separately forecasted for the future). Resources:.
Read more >add_regressor: Add an additional regressor to be used for ...
The dataframe passed to 'fit' and 'predict' will have a column with the specified name to be used as a regressor. When standardize='auto' ......
Read more >University - ERIC
Pierce (1952:206;7) goes tp some length to ... understandini of every item In the text, not just selected points of content, ... diiillotomous...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for pointing this out, and for the really clean repro steps. You can safely ignore this warning message. It is in some code checking whether the regressor should be standardized or not, and despite the warning it is doing the right thing. It should however be fixed to not raise the warning 😃
Adding multiple regressors at a time seems nice but the interface might be challenging, since then we’d have to potentially specify the other inputs to
add_regressor
(prior_scale and standardize) separately for each regressor.The fix has been pushed to CRAN in v0.2.1