Description Usage Arguments Value Examples
this functions implements the metropolis-hastings within gibbs algorithm proposed in molano thesis.
1 2 |
dat |
a data frame containing test info. rows for individuals and columns for items. aditionally, a variable which identify individuals must be supied. |
idname |
atomic character giving the name of the id variable in dat. |
psi0 |
a vector of initial values for parameter psi0. See nlf_2pl documentation. |
theta0 |
vector of initial values for latent traits. See nlf_2pl documentation. |
B |
Prior covariance matrix for psi. |
b |
Prior expected values for psi. |
Nc |
number of mcmc iterations. |
a list with the following objects:
fixp: a matrix where each row corresponds to an mcmc simulation of psi parameters.
theta: a matrix where each row corresponds to an mcmc simulation of latent traits.
Dev: a vector where deviance is calculated for each mcmc iteration.
B: Prior covariance matrix used for psi.
b: Prior Expected values used for psi.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | nitems<-7
nind<-100
sort(alpha_o<-runif(nitems,0.6,1.5))
sort(beta_o<-runif(nitems,-2.4,2.4))
d_o<- -alpha_o*beta_o
summary(theta_o<-rnorm(nind))
temp.b<-matrix(beta_o,ncol=nitems,nrow=nind, byrow =T)
temp.a<-matrix(alpha_o,ncol=nitems,nrow=nind, byrow =T)
temp.t<-matrix(theta_o,ncol=nitems,nrow=nind)
eta<-temp.a*(theta_o-temp.b)
pmod<-exp(eta)/(1+exp(eta))
test<-data.frame(ifelse(runif(nitems*nind)<pmod,1,0))
colnames(test)<-paste("t",1:nitems,sep="")
sort(apply(test,2,function(i)sum(i)*100/length(i)))
test<-data.frame(test,id=1:nind)
bres<-mh_gibbs_2pl(test,"id",psi0=c(d_o,log(alpha_o)),theta_o,Nc=1000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.