Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running the model with timetk #162

Open
FelipeCarrillo opened this issue Feb 12, 2024 · 1 comment
Open

Error running the model with timetk #162

FelipeCarrillo opened this issue Feb 12, 2024 · 1 comment

Comments

@FelipeCarrillo
Copy link

I am trying to predict some fish numbers and I found an older post that looks promising here:
[https://www.r-bloggers.com/2017/10/demo-week-time-series-machine-learning-with-timetk/]

However, I think the code does not longer work. Could you tell me what have changed to make the example work again?
I got an error message here:

> fit_lm <- lm(price ~ ., data = select(beer_sales_tbl_aug, -c(date, diff)))
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels
@olivroy
Copy link
Contributor

olivroy commented Feb 23, 2024

This is because tq_get() now adds a symbol column.

The following code would now be required.

# linear regression model used, but can use any model
fit_lm <- lm(price ~ ., data = dplyr::select(beer_sales_tbl_aug, -c(date, diff, symbol)))
summary(fit_lm)

Call:
lm(formula = price ~ ., data = dplyr::select(beer_sales_tbl_aug, 
    -c(date, diff, symbol)))

Residuals:
    Min      1Q  Median      3Q     Max 
-463.59 -135.17   -0.43  148.24  448.78 

Coefficients: (16 not defined because of singularities)
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)   4.412e+08  1.232e+08   3.581 0.000709 ***
index.num     7.110e-03  1.982e-03   3.587 0.000695 ***
year         -2.216e+05  6.157e+04  -3.600 0.000668 ***
year.iso     -2.341e+03  6.478e+03  -0.361 0.719185    
half         -2.124e+03  6.043e+02  -3.514 0.000871 ***
quarter      -2.270e+04  2.168e+04  -1.047 0.299515    
month        -3.605e+03  7.279e+03  -0.495 0.622315    
month.xts            NA         NA      NA       NA    
month.lbl.L          NA         NA      NA       NA    
month.lbl.Q  -1.764e+03  2.048e+02  -8.613 6.66e-12 ***
month.lbl.C   8.207e+02  5.086e+02   1.614 0.112132    
month.lbl^4   7.052e+02  1.330e+02   5.302 1.94e-06 ***
month.lbl^5   7.415e+02  4.197e+02   1.767 0.082631 .  
month.lbl^6   3.274e+02  1.593e+02   2.055 0.044424 *  
month.lbl^7  -3.364e+02  1.848e+02  -1.821 0.073913 .  
month.lbl^8   3.261e+02  3.183e+02   1.024 0.309948    
month.lbl^9          NA         NA      NA       NA    
month.lbl^10  6.331e+02  2.217e+02   2.856 0.005968 ** 
month.lbl^11         NA         NA      NA       NA    
day                  NA         NA      NA       NA    
hour                 NA         NA      NA       NA    
minute               NA         NA      NA       NA    
second               NA         NA      NA       NA    
hour12               NA         NA      NA       NA    
am.pm                NA         NA      NA       NA    
wday         -8.728e+01  1.879e+01  -4.646 2.05e-05 ***
wday.xts             NA         NA      NA       NA    
wday.lbl.L           NA         NA      NA       NA    
wday.lbl.Q   -8.681e+02  1.082e+02  -8.023 6.28e-11 ***
wday.lbl.C    3.093e+02  1.322e+02   2.340 0.022833 *  
wday.lbl^4    2.907e+01  1.121e+02   0.259 0.796405    
wday.lbl^5    8.261e+01  7.946e+01   1.040 0.302881    
wday.lbl^6    2.784e+01  8.115e+01   0.343 0.732814    
mday                 NA         NA      NA       NA    
qday         -2.495e+02  2.393e+02  -1.043 0.301504    
yday         -1.936e+02  1.401e+02  -1.382 0.172373    
mweek        -1.368e+02  1.461e+02  -0.936 0.353126    
week         -2.137e+02  1.871e+02  -1.142 0.258170    
week.iso     -3.410e+01  1.243e+02  -0.274 0.784886    
week2        -9.472e+01  1.531e+02  -0.619 0.538707    
 [ getOption("max.print") est atteint -- 3 lignes omises ]
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 257.7 on 57 degrees of freedom
Multiple R-squared:  0.9805,	Adjusted R-squared:  0.9716 
F-statistic:   110 on 26 and 57 DF,  p-value: < 2.2e-16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants