[R] MCMC regress, using runif()

Johannes Radinger JRadinger at gmx.at
Mon Aug 15 11:22:40 CEST 2011


Hello...

just some additional thoughts:
Maybe I can try it in a simple way with a repeated lm-regression, like:

Y=c(15,14,23,18,19,9,19,13)
X1=c(0.2,0.6,0.45,0.27,0.6,0.14,0.1,0.52)
X2a=c(17,22,21,18,19,25,8,19)
X2b=c(22,22,29,34,19,26,17,22)

X2 <- function()runif(length(X2a), X2a, X2b)

for loop --> repeat lm(Y~X1+X2()) for let's say 1000 times
and write the regression coefficients into a vector. Afterwards
just get e.g the mean and standard deviation for Intercept, and beta.
How is the for loop done in this case? I tried

for(i in 1:1000) model(i) <-lm(Y~X1+X2()) but that is not working....

/johannes



-------- Original-Nachricht --------
Datum: Mon, 15 Aug 2011 10:20:53 +0200
Von: "Johannes Radinger" <JRadinger at gmx.at>
An: r-help at r-project.org
Betreff: MCMC regress, using runif()

Hello,

just to follow up a question from last week. Here what I've done so far (here an example):


library(MCMCpack)

Y=c(15,14,23,18,19,9,19,13)
X1=c(0.2,0.6,0.45,0.27,0.6,0.14,0.1,0.52)
X2a=c(17,22,21,18,19,25,8,19)
X2b=c(22,22,29,34,19,26,17,22)

X2 <- function()runif(length(X2a), X2a, X2b)

model1 <- MCMCregress(Y~X1+X2())
summary(model1)


but I am not sure if my X2-function is working in the MCMCpack?
Is a random number drawn each iteration step? I don't think so
as the results are varying greatly if I run the script several times.

Is there any other way to do several thousand runs of a linear regression,always drawing a random number for X2 and then compute average values for the regressions?

/Johannes


-- 




--



More information about the R-help mailing list