dgrtwo / empirical-bayes-book

Introduction to Empirical Bayes: Examples from Baseball Statistics
Other
189 stars 76 forks source link

error running code from chapter 11: The ebbr package #34

Closed marboe123 closed 4 years ago

marboe123 commented 4 years ago

Hi David,

Last month I asked you a question about fuzzyjoin. From there I discovered you have written a book. I have printed your book and it is very interesting to read!

Currently I try to run the code from chapter 11. If I run this code snippet I receive an error:

## Hierarchical modeling

library(splines)
eb_career_prior <- career_full %>%
  ebb_fit_prior(H, AB, method = "gamlss",
                mu_predictors = ~ 0 + ns(year, df = 5) * bats + log(AB))

The error is:

Error: Argument 2 must be length 1, not 20

> lifecycle::last_warning()
<deprecated>
message: `data_frame()` is deprecated as of tibble 1.1.0.
Please use `tibble()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
backtrace:
 1. ebbr::ebb_fit_mixture(career_w_pitchers, H, AB, clusters = 2)
 2. ebbr::ebb_fit_mixture_(...)
 3. dplyr::data_frame(...)

Do you know which can be the cause?

Thanks a lot!

Kind regards, Marcel

marboe123 commented 4 years ago

The error was caused by "0 +" in the mu_predictors part. If I ommit "0 +" the error disappears. The code becomes this in that case:

## Hierarchical modeling

library(splines)
eb_career_prior <- career_full %>%
  ebb_fit_prior(H, AB, method = "gamlss",
                mu_predictors = ~ ns(year, df = 5) * bats + log(AB))