楼主: 410234198
4105 17

[学科前沿] Introduction to Bayesian Statistics 2th [推广有奖]

11
Nicolle(真实交易用户) 学生认证  发表于 2014-10-27 05:50:36
提示: 作者被禁止或删除 内容自动屏蔽

12
Nicolle(真实交易用户) 学生认证  发表于 2014-10-27 05:52:26
提示: 作者被禁止或删除 内容自动屏蔽

13
Nicolle(真实交易用户) 学生认证  发表于 2014-10-27 05:53:58
提示: 作者被禁止或删除 内容自动屏蔽

14
HZZH(真实交易用户) 发表于 2014-11-20 21:58:32
谢谢楼主分享哈

15
wh7064rg(真实交易用户) 发表于 2015-1-27 09:44:03
谢谢分享

16
bugbugbu(未真实交易用户) 在职认证  发表于 2015-4-15 17:15:49
thank y

17
Lisrelchen(未真实交易用户) 发表于 2016-5-14 22:37:14
  1. MACRO
  2. BayesMultReg.mac kpar y Xmat;
  3. sigma sig;
  4. prior b0 V0.
  5. # BayesMultReg.mac calculates the joint probability distribution for the
  6. # multiple linear regression model

  7. ###############################################################
  8. #
  9. # Instructions for using this macro
  10. # are contained in  "Introduction to Bayesian Statistics, 3rd Edition" by
  11. # William M. Bolstad and James Curran (John Wiley & Sons)
  12. #
  13. ###############################################################
  14. #  
  15. #  Neither Minitab Inc. nor the author of this MACRO makes
  16. #  any claim or offers any warranty whatsoever with regard to
  17. #  the accuracy of this MACRO or its suitability for use, and
  18. #  Minitab Inc. and the author of this MACRO each disclaims     
  19. #  any liability with respect thereto.            
  20. #
  21. ###############################################################


  22. # MACRO NAME: BayesMultReg.mac
  23. # AUTHORS NAME AND ADDRESS
  24. # William M (Bill) Bolstad
  25. # Statistics Department
  26. # Waikato UNIVERSITY
  27. # Hamilton, New Zealand

  28. # DATE: October 2015

  29. mconstant nobs kpar isig sig var  prb0 prb1  ma0
  30. mconstant df ssr  xbar ybar xybar  x2bar y2bar bls als ssx
  31. mconstant pre0 pre1 preLS k1 k2 k3 k4 kint npred kpred
  32. mcolumn y bL b0 B1 x0 xc.1-xc.kpar
  33. mcolumn fit res
  34. mcolumn xp yp lp up
  35. mmatrix Xmat X XT XTX XTXinv V0 VL V1 V0inv VLinv V1inv W W1 W2 W3 W4
  36. default sig=0

  37. # nobs is number of observations, kpred is number of predictors,
  38. # kpar (=kpred+1) is the number of parameters (including intercept)
  39. # xmat is matrix of predictors in columns xc.2-xc.kpar.  
  40. # xc.1 is column of 1's for intercept.   xc.1-xc.kpar is combined into Matrix X
  41. # b0 and VL are mean vector and covariance matrix of likelihood (least squares)
  42. # b1 and V0 are prior meanvector and covariance matrix (kpar by kpar)
  43. # bL and V1 are posterior mean vector and covariance matrix (kpar by kpar)
  44. # sig is standard deviation. When it is not input, estimate
  45. # calculated from residuals is used which gives approximation.
  46. # ia indicator for intercept prior, 0=flat prior, 1=normal prior
  47. # ib indicator for coefficients prior, 0=joint flat prior, 1=joint normal prior


  48. let nobs=n(y)

  49. ## prepare matrix X including column for intercept
  50. copy Xmat xc.2-xc.kpar
  51. set xc.1
  52. nobs(1)
  53. end
  54. copy xc.1-xc.kpar X

  55. ## Find least squares vector (MLE) and covariance matrix

  56. trans X XT
  57. mult XT X XTX
  58. inve XTX XTXinv
  59. mult XTXinv XT W
  60. mult W y bL

  61. print bL
  62. mult X bL fit
  63. let res=y-fit

  64. if (sig=0)
  65. let df=nobs-kpar
  66. let ssr=sum(res**2)
  67. let sig=sqrt(ssr/df)
  68. print df ssr sig
  69. let var=sum(res**2)/(df)
  70. let sig=sqrt(var)
  71. print "Standard deviation of residuals" sig
  72. elseif (sig > 0)
  73. print "known standard deviation" sig
  74. let var=sig**2
  75. let isig=1
  76. endif
  77. mult var XTXinv VL

  78. print bL VL

  79. inve V0 V0inv
  80. inve VL VLinv

  81. add V0inv VLinv V1inv
  82. inve V1inv V1
  83. print V0inv VLinv V1inv V1

  84. mult V1 V0inv W1
  85. mult V1 VLinv W2
  86. print w1 w2

  87. mult W1 b0  W3
  88. mult W2 bL W4
  89. add W3 W4 b1
  90. print w3 w4
  91. print b0 V0 bL VL b1 V1

  92. endmacro
复制代码

18
Nicolle(真实交易用户) 学生认证  发表于 2016-5-16 01:15:53
提示: 作者被禁止或删除 内容自动屏蔽

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-25 17:49