user89861 - 1 year ago 75

R Question

When I look at the help file for the above, it gives this sample program in R:

`##`

## rbprobitGibbs example

##

if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=2000} else {R=10}

set.seed(66)

simbprobit=

function(X,beta) {

## function to simulate from binary probit including x variable

y=ifelse((X%*%beta+rnorm(nrow(X)))<0,0,1)

list(X=X,y=y,beta=beta)

}

nobs=200

X=cbind(rep(1,nobs),runif(nobs),runif(nobs))

beta=c(0,1,-1)

nvar=ncol(X)

simout=simbprobit(X,beta)

Data1=list(X=simout$X,y=simout$y)

Mcmc1=list(R=R,keep=1)

out=rbprobitGibbs(Data=Data1,Mcmc=Mcmc1)

summary(out$betadraw,tvalues=beta)

if(0){

## plotting example

plot(out$betadraw,tvalues=beta)

}

So, my question is, does the code for simbprobit simply prepare some simulated values for the rbprobitGibbs function? That is, if I am computing the results from rbprobitGibbs, can I effectively ignore simbprobit and simply prepare the Data, Prior, Mcmc input values?

Answer Source

Yes, after some research, I discovered it is a simulated random input via `simbprobit`

, because of the function call `rnorm`

which means that it is a random variable. From the help file:

"`dnorm`

gives the density, `pnorm`

gives the distribution function, `qnorm`

gives the quantile function, and `rnorm`

generates random deviates."