项目作者: RottenFruits

项目描述 :
Bayesian linear model in R
高级语言: R
项目地址: git://github.com/RottenFruits/blmr.git
创建时间: 2019-05-26T02:19:06Z
项目社区:https://github.com/RottenFruits/blmr

开源协议:Other

下载


blmr

Bayesian linear model in R.


How to install

You can install blmr running the following commands.

  1. devtools::install_github("RottenFruits/blmr")

Example

Here are examples.

  1. library(blmr)
  2. X <- runif(10, 0, 10)
  3. y <- sin(X)
  4. df <- data.frame(X, y)
  5. model <- blm(y ~ X + I(X^2) + I(X^3) + I(X^4), df, 10)
  6. df_test <- data.frame(X = runif(100, 0, 10))
  7. df_test <- df_test[order(df_test$X), , FALSE]
  8. yhat <- predict(model, df_test, type = "response")
  9. sq_hat <- predict(model, df_test, type = "sd")
  10. #plot
  11. plot(df$X, df$y)
  12. lines(df_test$X, yhat)
  13. lines(df_test$X, yhat + 2*sq_hat)
  14. lines(df_test$X, yhat - 2*sq_hat)

References

  • 須山敦志, 2017, 『ベイズ推論による機械学習入門』, 講談社.