Coder Social home page Coder Social logo

dgrtwo.github.com's Issues

Bayesian hierarchical modeling: mutate: non-numeric argument to binary operator

I'm having an issue running the example from "Understanding empirical Bayesian hierarchical modeling (using baseball statistics)"
http://varianceexplained.org/r/hierarchical_bayes_baseball/

I run everything before and up to:

crossing(bats = c("L", "R"),
         AB = c(10, 100, 1000, 10000)) %>%
  augment(fit2, newdata = .) %>%
  mutate(H = .3 * AB,
         alpha0 = .fitted / sigma,
         beta0 = (1 - .fitted) / sigma,
         alpha1 = alpha0 + H,
         beta1 = beta0 + AB - H,
         estimate = alpha1 / (alpha1 + beta1),
         conf.low = qbeta(.025, alpha1, beta1),
         conf.high = qbeta(.975, alpha1, beta1),
         record = paste(H, AB, sep = " / ")) %>%
  ggplot(aes(estimate, record, color = bats)) +
  geom_point() +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) +
  labs(x = "Estimate w/ 95% credible interval",
       y = "Batting record",
       color = "Batting hand")

and get:

Error in mutate_impl(.data, dots) : 
  Evaluation error: non-numeric argument to binary operator.

I figured out the error is coming from the fact that sigma is a function, and so is causing the calculation of alpha0 to fail. I'm not too familiar with tidyr, and so am not sure how to pull out sigma for the predicted/fitted new data...

I appreciate your help in advance!

It seems to me that inflate function is not working properly...

I could not figure out how to use inflate function properly...

When I reproduce what you implemented, I've got the following errors.

http://varianceexplained.org/r/bayesian_ab_baseball/

two_players %>%
+ broom::inflate(x = seq(.28, .33, .00025)) %>%
+ mutate(density = dbeta(x, alpha1, beta1)) %>%
+ ggplot(aes(x, density, color = name)) +
+ geom_line() +
+ labs(x = "Batting average", color = "")
Error in mutate_impl(.data, dots) :
Evaluation error: object 'alpha1' not found.

question on alignment

Hey David, fan of your site. I'm trying to use Minimal Mistakes as well - was wondering how you left-aligned the masthead links?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.