r - How to calculate model residuals from MCMCregress -


I'm doing classwork using Bayesian estimation. For this, I am using the MCMCregress function, MCMCpack . The problem occurs when I want to get residual, because the function does not provide them, They have to be calculated in "by hand" (R).

My model is:

  Model & lt; - MCMCregress (Y ~ X1 + X2 + X3 + X4 + X5, Data = Data)  

Where X1 and X5 are continuous , Whereas the X2 , X3 and X4 are duplicate Model Output provides me estimates for each variable:

 < Code> (intercept) = 1.90, x1 = -0.02, x2 = -0.05, x3 = 0.32, x4 = 0.61, x5 = -0.003, I think I have to do something like this:  
  1.90 - 0.02 * X1 - 0.05 * X2 + 0.32 * X3 ...  

But I know that I am missing something important in the R code, so M I want to know is not that balance what is right R code to get close.


Here is a copy presenter example (though it does not conform to the original data):

  w < -c (0.2,0.8,1,4.3, 5,3,5,3,2,1,3,3,2,2,4,3,6,3,5,4,3,3,4,4 , 1,2) X1 & lt; - c (17,13,15, NA, 12, 24, 15, NA, 12, 22, 14, 12, 18, NA, 10, 13, 12, 11, 26, 10) X2 and LT; - C (0,0,0,1,0,0,1,1, 1,1,0,1,0,0,0,0,0,1,1, NA, NA) X3 and LT; -C (0,0,1,1,1,0,1,0,0,0,0,0, 0,1,0, NA, 0, NA, NA, 0,1,0) X4 and LT; - C (1,0,1,0,0,1,0,0, NA, 0, NA, NA, 0,0,1,0,1,1,0,1) X5 and LT; - C (2.46,4,56,32.1, NA, NA, NA, NA, NA, 3.76,5.67,4.56, NA, 17.32, 12.24.56,7.2,1.2, NA, 9.2) X2 and LT; - Eiffel (X2 & 0; C, C ("Yes"), C ("No")) X3 and LT; - Eiffel (x3 & gt; 0, c ("yes"), c ("no")) x 4 and lt; - Eiffel (x4 & gt; 0, c ("yes"), c ("no") data & lt; - Data. Frame (Y, X1, X2, X3, X4, X5) Library (MCMPac) MCMC & amp; Lt; - MCMCregress (Y ~ X1 + X2 + X3 + X4 + X5, Data = Data) Summary (MCMC)  

How do I get residual?

I found that MCMC Chen is somewhat horrible at the end of the run - check out Xyplot (MCMC, layout = c (2,4)) . I do not know what the problem is, you have to solve it, but in the meanwhile I am going to use the median instead of the mean of coefficient.

  (MCMC, 2, Middle) [1: 6] X & LT; - Model.matrix (~ X1 + X2 + X3 + X4 + X5 + Data = Data) pred0 & lt; The most complex part is dealing with NA value: It is built in most of the existing residues () methods ...  
  

pred & lt; - napredict (etar (naaa ayai (data), "neaction"), pd 0) reeds and lt; - Pre-data $ Y

Note that in this case, after the NA value is removed, you are fitting a 5-parameter regression model for 6 full comments . You will probably have to make some allegations to get the right answers of any kind ...


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -