Bayesianmodeling: User Manual
Bayesianmodeling: User Manual
User Manual
Version 1.0 December 2011
email: [email protected]
1
Index Page
Introduction 3
1. Binary Regression 5
1.1. Binary Regression Models 5
1.2. Binary Regression with Asymmetric Links 5
1.3. Bayesian Inference in Binary Regression 8
1.4. Application: Beetles data set 9
1.5. Use of the BayesianModeling 10
1.5.1 Generate the syntax of the model 11
1.5.2 Bayesian estimation using WinBUGS or OpenBugs 15
1.5.3 Bayesian estimation using WinBUGS or OpenBugs in R 22
3. References 50
2
Introduction
This application is for your personal use and must not be used for any commercial
purpose whatsoever without my explicit written permission. The application is provided
“as is” without warranty of any kind. In order appropriately to implement the different
models mentioned in the application, you it must read in detail the literature suggested in
the references and must be familiarized with the Bayesian Inference using MCMC.
BayesianModeling is thought for practitioners that given a data set they wish to know
the syntax of diverse Binary Regression or Item Response models in bugs code, Theory
usually non available in diverse statistical programs including the program R. This
program write two files: a bugs model file for each one of this models considering
adequate priors, lists with sensible starting values and size of the data set and a data
set file in rectangular format, both readable in WinBUGS or OpenBUGS.
This basic application can be considered a different version of BRMUW (Bazán, 2010)
which was developed as part of the projects DAI 3412, 4031 and 2009-0033 of Pontifical
Catholic University of Peru with the purpose to disseminate models developed by the
author.
This application together with some models has been developed for three late years and
throughout that time various people have collaborated in this project reason why I
desire to express my gratefulness. Among them to the colleagues Oscar Millones,
Christian Bayes and Miluska Osorio for theirs aid during the revision of the present
version of the application and the user guide. I also am thankful to Martin Iberico,
Margareth Sequeiros and Pedro Curich for the computational support in some of the
stages of the project. Thank you very much to my family for its patience and support.
3
Installation instructions can be found in the included README file. BayesianModeling
can run smoothly in any operating systems, such as Windows, Mac OS, Linux, in which
the Java Virtual Machine and Perl are supported.
Java: Java SE Runtime Environment 1.6 or later. Perl: Perl v5.10 or later. RAM: ≥ 512M
The BayesianModeling package was introduced at the II Conbratri-2011
(http://187.45.202.74/conbratri/).
4
1. Binary Regression
When a cdf of a symmetric distribution, the response curve is has symmetric form
about . Examples are obtained when is in the class of the elliptical distributions as,
for example, standard normal, logistic, Student- , double exponential and Cauchy
distributions.
In the case that is the cdf of a standard normal distribution we obtain the probit link
and in the case that is the cdf of a logistic distribution we obtain the logit link,
5
textbooks (see, for example, Collet, 2003) reporting situations where an asymmetric link
is more appropriate than a symmetric one.
In this case, it is necessary to consider asymmetric links. A very popular example of
asymmetric link is the complementary log-log link or cloglog, where the cdf of the
Gumbel distribution is considered as defined by
Where the cdf is completely specified and, it does not depend on any unknown
additional parameter and it does not include any particular case as a symmetrical link.
This link is considered in Bayesian Modeling.
Information of how to implement the Bayesian estimation of the binary regression using
the cloglog, probit and logit links in WinBUGS or OpenBUGS can be seeing in the
Example Beetles: logistic, probit and carries far estimates models
of the Manual. Nevertheless Bayesian approach to binary regression models considering
other links as the discussed by Bazán, Bolfarine and Branco (2006 and 2010), Prentice
(1976), Nagler (1994), Chen, Dey and Shao (1999, 2001) are not available at the
moment.
these links are asymmetric logit and are known as scobit and power logit, respectively,
and include the logit link as special case when the parameter . For a review of
these links see Prentice (1976) and Nagler (1994).
In BayesianModeling also are implemented three links that are based in the cdf of a
skew normal distribution (see Azzalini, 1985), this cdf can be represented in general by
the following way:
6
This links were proposed by Bazán, Bolfarine y Branco (2006 and 2010) and as especial
cases of this general formulation, the implemented links in the BayesianModeling are
the following:
probit link (Bazán, Bolfarine y Branco 2006 y 2010), named here as Standard
skew probit.
In these three links, is the shape parameter that controls the asymmetry, so we
have for negative values (positive) of has negative asymmetry (positive).
These three models can see also as belonging to the kind of mixes of eliptic
distributions proposed by Basu and Mukhopadhyay (2000) given by:
,
,
7
1.3. Bayesian Estimation in Binary Regression
Considering the distribution Bernoulli for the variable response, the likelihood function
is given by
The logit, probit, cloglog, scobit and power logit links consider this likelihood function;
however skew probit and skew logit links consider other versions of the likelihood
function considering augmented versions that are discussed in the specific references of
these models.
In the Bayesian Inference, the parameters of interest are assumed like random variables
and so is need establishes a priori probability distributions that reflects our previous
knowledge of its behavior. Combining the likelihood function and the priori distributions
we can obtain the posteriori distributions of the parameters of interest. In the present
work, we consider priors that they are vague proper priors with known distributions but
variance big as well as independence between priors (see Nzoufras, 2009).
In Binary Regression models there is consensus about the prior specification for
regression coefficients, thus is assumed for with to be large,
and this case is considered . In relation with the shape parameter associated
with the link: for Scobit and Power logit models is assumed ( ,
) and for skew probit models , where and .
Bayesian Inference is facilitated with the use of different MCMC methods implemented
in WinBUGS or OpenBUGS software using a minimum programming. For more details
about the use of these software for Bayesian Inference and usual Binary regression
8
models we suggest the book of Congdon (2005), Congdon (2010) and Ntzoufras (2009).
An introduction to MCMC methods is given in Gilks, Richardson, and Spiegelhalter
(1996).
Also, Bayesian Inference for some traditional Binary models considering R packages as
arm, bayesm, DPpackage, LaplacesDemon, MCMCpack are available.
However, for most of the models presented here, there is no program that generates
codes for WinBUGS or OpenBUGS with exception of BRMUW (Bazán 2010) a previous
version of this program in Spanish. In contrast, BUGS codes for all Binary regression
models presented here are facilitated using BayesianModeling. The Binary regression
models implemented in BayesianModeling classified according to its links are:
• Symmetric: probit, logit.
• Asymmetric: cloglog, scobit, power logit, skew logit, skew probit (CDS, BBB and
standard).
All codes for Binary regression models are established considering the likelihood
function presented here and considering the priors suggested with the exception of the
skew logit and skew probit models which use an augmented likelihood function version.
In BayesianModeling, when a specific code is generated for a Binary regression model,
also References to justify the model and the choices of priors are showed.
The BayesianModeling program generates the necessary syntax for the Bayesian
estimation of several models of binary regression, in the WinBUGS program (see
Spiegelhalter et al, 1996) or OpenBUGS (Spiegelhalter et al, 2007), using diverse
methods MCMC. For this only is necessary to have a text file with the data, generated
from any statistics program or from Excel. In the columns normally appear the names of
the variables in the first line and in the first column should appear the response
variable.
As example consider the group of data Beetles: logistic, probit and extreme value models
of the WinBUGS. The group of data is denominated as beetles.txt that is found in this
downloads of the program. The variables used in beetles.txt are:
y: 1 if the beetle died after 5 hours of being exposed to carbon disulfide, 0 otherwise
9
x: concentration of carbon disulfide that a beetle was exposed
The data file has the following structure
y x
1 1.6907
1 1.6907
. .
. .
. .
1 1.8839
Where corresponds to the skew logit link (see Chen, Dey and Shao, 2001). More
details in Bazán, Bolfarine y Branco (2010)
10
2. Navigate to the directory that contains your dataset files. Select the data set file
you want work. The program can open data file in ASCII format (.csv, .txt and .dat)
3. To select the model you want Click on Binary Regression button or Go to Models
> Binary Regression
11
4. This will open the dialog box “Binary Regression Data”.
5. Afterward, select the dependent variable and covariates variable you want. In this
case y and x respectively. Click and drag the variables. Also, you must to indicate
if will use all the data or only a part of them considering the options in Cases. In
the example, select All.
12
6. Then, click Models. This will open the dialog box “Binary Regression Models”.
Here you must to select the models that will be used, in this example only select
the model skew-logit and do click in OK.
7. Two type of files are generated, corresponding for the selected models and for
data. In this case Skew Logit Model and Binary Regression Data. Both files are
readable in WinBUGS or OpenBUGS.
13
These two files will have to be saved with format txt, is to say Binary Regression Data.txt
and Skew Logit Model.txt for its subsequent use.
To generate new models for other data is recommended to restart the program and
follow the steps presented.
14
1.5.2 Bayesian estimation using WinBUGS or OpenBUGS
As we have seen the BayesianModeling generates two files, one that contains the model
of binary regression with the link selected and another that contains the data set. Both
files with txt format have to be opened in the WinBUGS or OpenBUGS program to make
the correspondent analysis of inference. Here we detail the steps that must be followed
to perform the Bayesian inference in WinBUGS. For details, see Chapter 4 of Nzoufras
(2009)
1. Open the files with the syntax of the model and the previous generated data by
the BayesianModeling in WinBUGS or OpenBUGS.
15
2. Click in Model > Specification having active the window of the file Skew Logit
Model.txt.
4. Select the word model highlighting it with the cursor and do click in check model.
In the below left corner has to appear “model is syntactically correct” that
indicates the syntax of the model is properly formulated.
16
5. Select in the file of the model the line under Data, list and do click in load data.
In the below left corner appears “data loaded” indicating that the data have been
read.
17
6. In the data file Binary Regression Data.txt select the names of the variables x and
y and do click in load data.
18
7. The dialogue box “Specification tool” specifies the number of chains that want to
generate in the box of text “num of chains”. Once specified the number of chains
to generate (in this example 1 chain) do click in compile. In the left corner below
has to appear “model compiled”.
19
8. Select the line under Inits in the file of the model and do click in load inits. Then
do click in gen inits. This generates the initial values for the Bayesian Estimation.
In the left corner below has to appear “initial values generated, model initialized”.
20
9. Do click in Model > Update
21
10.This will open the dialogue box “Update tool”. In the text box Update Tool type the
number of iterations that are required and afterwards does click in update.
As we have seen in the previous section with the two files that generates the
BayesianModeling can implement the Bayesian Estimation using WinBUGS or
22
OpenBugs programs. Also Bayesian estimation can be implemented by using
R2WinBUGS or R2OpenBUGS (Sturtz, Ligges and Gelman, 2005), packages for
Running WinBUGS and OpeBUGS from R respectively or BRugs (Thomas, et al, 2006) a
collection of R functions that allow users to analyze graphical models using MCMC
techniques.
Here we will need the file Beatles.txt and the skewlogitModel.txt syntax of the model
generated in the BayesianModeling.
We copy all the syntax before “Inits” and save it in a file, by example as modelbr.txt.
Then the file modelbr.txt would remain as
model {
for(i in 1:n) {
m[i] <- beta[1] + beta[2]*x[i]
muz[i]<- m[i]+delta*sigma*V[i]
zs[i]~dlogis(muz[i],1)I(lo[y[i]+1],up[y[i]+1])
V[i] ~ dnorm(0,1)I(0,)
}
for (j in 1:k) {
beta[j] ~ dnorm(0.0,1.0E-3)
}
delta ~ dunif(-1,1)
lambda<-delta/sqrt(1-pow(delta,2))
sigma<-1/sqrt(1-pow(delta,2))
lo[1]<- -50; lo[2]<- 0;
up[1]<- 0; up[2]<-50;
}
To implement the Bayesian estimation in R we follow the following steps to use the
library R2WinBUGS.
library(R2WinBUGS)
2. Read the data (the file beetles.txt for this Example is in F:\MILUS\beetles.txt)
23
3. Create a list that contain the data and the information of the size of the data set
typing:
n=nrow(datos)
k=ncol(datos)
data<-c(as.list(datos),list(n=n,k=k))
inits<-function(){list(beta=rep(0,k),delta=0.5)}
5. Finally with the command bugs implements the Bayesian estimation. Here will
explain in brief the syntax of the command Bugs
With the following command the Bayesian estimation is implemented and the
simulations are saved in the object out.
out<-bugs(data,inits,parameters.to.save=c("beta","lambda"),
n.burnin=4000,program="WinBUGS")
24
> out
Inference for Bugs model at "G:/MILUS/modelbr.txt", fit using WinBUGS,
1 chains, each with 44000 iterations (first 4000 discarded), n.thin =
40
n.sims = 1000 iterations saved
mean sd 2.5% 25% 50% 75% 97.5%
beta[1] -62.2 3.1 -67.8 -64.4 -62.3 -60.1 -55.9
beta[2] 35.0 1.6 31.4 33.9 35.2 36.2 38.0
lambda 0.2 0.8 -1.2 -0.3 0.1 0.7 1.7
deviance 1029.3 15.7 986.7 1024.7 1035.0 1040.0 1044.0
7. Finally, to greater details about the command bugs you can obtain help typing in
the line of the commands the following
?bugs
Note. You can specify Bug.directory. The directory that contains the WinBUGS
as the default. Also you can specify the program to use, either winbugs/WinBUGS or
openbugs/OpenBUGS, the latter makes use of function openbugs and requires the
25
2. Item Response Theory
Consider data collected of persons who have each given responses on different
items of a test. A Two-Parameter Item Response Theory (IRT) model one-dimensional
and binary is a system in which for each person has a unidimensional monotone
latent variable model , defined by the following expressions:
where
is the manifest variable which model the binary response of the person that
answer to the item . The items have binary outcomes, i.e., the items are scored
as 1 if correct and 0 if no.
are two parameters that represent, respectively, to the discrimination
and the difficulty of the item .
is the value of the latent variable or trait latent for the person , and some
occasions it is interpreted as the latent ability of the person .
is the conditional probability given to respond correctly to item .
is called the item characteristic curve (ICC) and
is a latent lineal predictor associated with the latent trait of the person and
the item parameters for the item .
Observations
The Two-Parameter IRT model
satisfies the property of latent conditional independence; it is, for a person the
response to the different items are conditionally independent given the latent
variable
satisfies the property of latent monotonicity, because is a function strictly no
decreasing of ,
is one-dimensional latent.
26
, where and , is the same for each case and
is called the link function.
Also is assumed that responses are independent between persons.
The parameters of difficulty and of discrimination represent the location
and inclination of the item, respectively, being a proportional value to the
inclination of the ICC in the point and is the point on where the ICC has its
maximum slope. Values as are not expected. The parametric space for the
parameter is arbitrary and to be the same as than by the usual take values in
the line real.
the previous parameter of difficulty can be obtained doing in the obtained result.
In The Two-Parameter IRT model, the conjoint density of the vector of multivariate
responses , with given the vector of latent variables
and the vector of parameters of the items can be
written as:
The proof of this result is direct by considering the latent conditional independence.
The first IRT binary model was introduced by Lord (1952) with an ICC given by
being the cdf of a standard normal variable. This model is known in the
psychometric literature as normal ogive model which corresponds in the context of
Generalize Linear Models, for a probit link function and empathizing this can be named
as 2P model.
27
On the other hand, Birbaum (1968) considered a ICC given by , where
denotes the cdf of a logistic variable. This induces, in the language of the
generalized linear models, to a logit link function. This model is known as the logistic
model and empathizing the link is named here as 2L model.
Particular cases
The IRT model admits diverse formulations, which depend basically of as it considers
the ICC. In its simplest version could take and consider an ICC of the form
This is called of one-parameter IRT model and when probit or logit links are considered
we have 1P or 1L IRT model respectively.
Where the parameter indicates the probability that very low ability individuals will
get this item correct by chance, and is the distribution function. This is known as the
three-parameter IRT model. If , the model is reduced to the two- parameters IRT
model. Again, when probit or logit links are considered we have 3P or 3L IRT model
respectively.
The IRT model with logit link or logistic model is probably the model more used in IRT.
The version of three parameters for this model establishes that the probability that the
person hit the item is given by:
28
where usually is assumed that although some authors consider also the value
for approximating this model to the normal ogive model. As particular cases
have
The last model of a parameter, is knows as well as the Rasch model but it has own
interpretations and derivations (see for example Fischer and Molenaar, 1995).
The BayesianModeling program allows implementing the code in WinBUGS for the
models 1L, 2L, 3L, 1P, 2P and 3P IRT models. By considering this links, these models
are symmetric IRT models. In addition, news IRT models with asymmetric links are
considered also in BayesianModeling which are presented in the next section.
In the traditional IRT models, the asymmetric ICC are considered symmetrical; this is
the case of the logistic and of normal ogive models. However, as it has observed
Samejima (2000), Bazán et al (2006) and Bolfarine and Bazán (2010) asymmetric ICC
can be incorporated considering a new parameter of item that controls the shape of the
curve. This asymmetry is necessary in many cases for a better modelization of answers
with a low proportion of 0´s or 1's. Then will show three of these models.
29
where is a parameter of asymmetry, is the latent linear predictor
and denote the cdf of a skew normal distributions with function of density
being the pdf of a standard normal variable.
Notice that if , the normal ogive model (2P) is obtained, but as indicated in Bazán
et al (2006) if , the probability of correct response has a slow growth for low values
of latent variable . On the other hand, if , the probability of correct response
has a quick growth for low values of the latent variable . Is because this behavior that
this parameter is interpreted as a penalization parameter for item. Main details about
this model can be reviewed in Bazán et al (2006). In this formulation the link considered
is the BBB skew probit link (see Bazán, Bolfarine and Branco, 2010) and for this reason
the model can be named also two-parameter skew probit or 2SP IRT model. When only
difficulty parameter is considered we have the 1SP IRT model.
where is the cdf of the logistic distribution indexed by the parameter and
These correspond to the cdf of the Scobit distribution and Burr of type II, respectively.
30
Note that or and y are asymmetric
but it holds that or
In both models can also interpret like a parameter of penalty or bonus of similar way
to the case of the model of skew normal ogive model given by Bazán, Branco and
Bolfarine (2006). More details of this model can review in Bolfarine y Bazán (2010).
Particular cases and extensions considering one-parameter or three-parameters are
possible. Thus, 1LPE, 1RLPE, 3LPE and 3RLPE are another IRT models implemented in
BayesianModeling.
The Logistic (logit), Normal ogive (probit), LPE and RLPE consider this likelihood
function; however skew probit IRT consider other version of the likelihood function
considering augmented version that is discussed in the specific references of this model.
In WinBUGS, the implementation of this procedure is not direct because it requires of a
correct specification of the indicator variables. Main details can find in Bazán, Branco
and Bolfarine (2006).
In the Bayesian Inference, the parameters of interest are assumed like random variables
and so is need establishes a priori probability distributions that reflects our previous
knowledge of its behavior. Combining the likelihood function and the priori distributions
we can obtain the posteriori distributions of the parameters of interest. In the present
work, we consider priors that they are vague proper priors with known distributions but
variance big as well as independence between priors (see Nzoufras, 2009). In traditional
31
IRT models priors are discussed in Albert (1992), Johnson and Albert (1999), Patz and
Junker (1999), Sahu (2002), Rupp, Dey and Zumbo (2004), Bazán, Bolfarine and
Leandro (2006), Fox (2010).
In IRT models there is consensus about the prior specification for latent trait, thus is
assumed for . However about item parameter there is several
proposals. Here is assumed independent priors as
Bayesian Inference in IRT models is facilitated with the use of different methods MCMC
implemented in WinBUGS or OpenBUGS software. An introduction to MCMC methods
is given in Gilks, Richardson, and Spiegelhalter (1996). For more details about the use
of these softwares for Bayesian Inference we suggest the book of Congdon (2005),
Congdon (2010) and Ntzoufras (2009). For traditional IRT models Bugs codes are
available by example in Curtis (2010), Fox (2010), Bazan, Valdivieso and Calderón
(2010).
Also, Bayesian Inference for some traditional IRT models using R package (MCMCpack:
Martin, Quinn and Park, 2011) and Matlab package: (IRTuno: Sheng, 2008a, IRTmu2no:
Sheng, 2008b, IRTm2noHA: Sheng, 2010) are available.
However, for most of the models presented here, there is no program that generates
codes for WinBUGS or OpenBUGS. This is facilitated using BayesianModeling. The IRT
models implemented in BayesianModeling classified according to its links are:
32
• Symmetric: logistic (1L, 2L, 3L), probit (1P, 2P, 3P).
• Asymmetric: LPE (1LPE, 2LPE, 3LPE), RLPE (1RLPE, 2RLPE, 3RLPE), skew probit
(1SP, 2SP).
All codes for IRT models are established considering the likelihood function presented
here and considering the priors suggested with the exception of the skew probit IRT
models which use an augmented likelihood function version. In BayesianModeling,
when a specific code is generated for a IRT model, also References to justify the model
and the choices of priors are showed.
The program BayesianModeling generates the syntaxes necessary for the Bayesian
estimation of several models of the Item Response Theory, for posterior use in WinBUGS
(see Spiegelhalter et al 1996) or OpenBUGS (Spiegelhalter et al 2007) program, using
diverse MCMC methods. For this only is necessary to have a file of text with the data,
generated from any statistics program or from Excel. In each column, usually appear
the names of the items in the first line.
The released items are a sampling from a test that appears published in the following
link:
http://www2.minedu.gob.pe/umc/admin/images/publicaciones/boletines/Boletin-
13.pdf
In the table appears the identification corresponding to the number of item with the
number in the UMEQ test.
33
Number of item in the UMEQ test 1 8 9 11 12 13 21 25 32 5 17 30 2 10
The data file can be found in the file zip of the program and has the following structure:
I01 I02 I03 I04 I05 I06 I07 ... I12 I13 I14
1 1 0 1 1 0 1 ... 0 0 1
1 1 1 1 1 1 1 ... 0 1 1
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
1 1 0 1 0 0 1 ... 0 1 1
We described the use of the BayesianModeling to implements the 2SP IRT model to the
data of MathData.dat described in the previous section. For more details of this
application, review Bazán, Branco and Bolfarine (2006).
34
2. Open the file with the data set.
35
4. This will open the dialogue box “Item Response Data”.
5. Then select the items that will be used. As well as to indicate if will use all the
data or only a part of them.
36
In our case will select all the variables as items and then click in All.
6. Then click in Models to open the dialogue box “Item Response Theory”. Here have
to select the models that will be used, in this example only select the 2SP model
and click OK.
37
7. This generates two data files: the file with the syntax of the model chosen in
WinBUGS (Skew Probit 2SP Model) and another file with the syntax of the data.
(Item Response Data).
BayesianModeling generates two files, one that contains the model of Binary regression
with the link selected and another file that contains the data set. Both files in format txt
have to be saved to be opened in the program WinBUGS or OpenBUGS to do the
appropriate analysis of Bayesian inference.
For a appropriate analysis of Bayesian inference of the model generated make the
following.
38
1. Open the files with the syntax of the model and of the data previously generated
by the BayesianModeling in WinBUGS or OpenBUGS.
2. Having activated the window of Skew Probit 2SP Model. txt, click Model >
Specification
39
4. Select the model, highlighting the word model and click check model. In the left
corner below has to appear “model is syntactically correct” that indicates that the
syntax of the model has been properly formulated
5. Select in the Skew Probit 2SP Model.txt file, the line under data and do click load
data. In the left corner below appears “data loaded” indicating that the data have
been loaded.
40
6. In the data file select the list of the variables that are placed in the first row and
click load data.
41
7. In the dialogue box “Specification tool” indicate the number of chains that want to
generate in the text box “num of chains”. Once specified the number of chains to
generate (in this example 1 chain) do click compile.
8. Select the line under Inits in the file of the model and click load inits. Then click
gen inits. This generates the initial values for the Bayesian estimation. In the left
corner below has to appears “initial values generated, model initialized”
42
9. Click Model > Update
10. This will open the dialogue box “Update tool”. In the text box updates enter the
number of iterations that requires and then click update.
43
While the program does the iterations, in the left corner below will appear the following
message “model is updating” until the iterations finish when the following message
“4000 updates took 61 s” appears.
11. Then should specify that parameters need the program save, for this go to
Inference > Samples, which will open the dialogue box “Sample monitor tool”. In
the text box node type the name of the parameter and then click set; this has to
be done for each parameter.
12. Repeat the step 10 generating more iterations that now have being saved by the
WinBUGS or OpenBugs. In the dialogue box “Sample Monitor Tool”, can calculate
posteriori statistics of the parameters clicking stats, a historical of the chains
clicking history, an estimation of the posteriori density and others statistics of the
chains can be calculated using this dialogue box.
44
2.5.3 Bayesian Estimation using WinBUGS or OPENBUGS in R
As we have seen in the previous section with the two files that generates the
BayesianModeling can implement the Bayesian Estimation using WinBUGS or
OpenBugs programs. Also Bayesian estimation can be implemented by using
R2WinBUGS or R2OpenBUGS (Sturtz, Ligges and Gelman, 2005), packages for
Running WinBUGS and OpeBUGS from R respectively or BRugs (Thomas, et al, 2006) a
collection of R functions that allow users to analyze graphical models using MCMC
techniques.
For this will need the original text file with the data in columns:
I01 I02 I03 I04 I05 I06 ... I12 I13 I14
1 1 0 1 1 0 1 ... 0 0 1
1 1 1 1 1 1 1 ... 0 1 1
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
1 1 0 1 0 0 1 ... 0 1 1
i.e. the file called MathData.dat (See section 2.5.1) and the syntax of the model
generated in BayesianModeling will have to copy only the syntax of the model. In the
example below implement the 2SP model.
45
model{
for (i in 1:n) {
for (j in 1:k) {
m[i,j]<-a[j]*theta[i]-b[j]
muz[i,j]<-m[i,j]-delta[j]*V[i,j]
Zs[i,j] ~ dnorm(muz[i,j],preczs[j])I(lo[y[i,j]+1],up[y[i,j]+1])
V[i,j] ~ dnorm(0,1)I(0,)
}
}
#abilities priors
for (i in 1:n) {
theta[i]~dnorm(0,1)
}
#items priors
for (j in 1:k) {
# usual priors
#Bazan et al (2006)
# difficulty (-intercept) with prior similar to bilog
b[j] ~ dnorm(0,0.5)
# discrimination
a[j] ~ dnorm(1,2)I(0,)
# difficulty centred in zero
bc[j] <- b[j] - mean(b[])
#Bazan et al 2006
delta[j] ~ dunif(-1,1)
preczs[j]<- 1/(1-pow(delta[j],2))
lambda[j]<-delta[j]*sqrt(preczs[j])
}
lo[1]<- -50; lo[2]<- 0 ## Zs*|y=0~N(-delta*V+m,1-delta^2)I(-50,0)
up[1]<- 0; up[2]<-50 ## Zs*|y=1~N(-delta*V+m,1-delta^2)I(0,50)
mu<-mean(theta[])
du<-sd(theta[])
}
}
data
list(n=131, k=14)
#load your data in other file
Inits
list(a=c(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0),b=c(0.0,0.0,0.0,0.
0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0),delta=c(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0
.0,0.0,0.0,0.0,0.0,0.0),theta=c(0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5))
#Bazán, J. L., Branco, D. M. & Bolfarine (2006). A skew item response model.
#Bayesian Analysis, 1, 861-892.
This should copy the syntax before “data” and save it in a file, for this example
modelirt.txt. Then the file modelirt.txt would remain
46
model{
for (i in 1:n) {
for (j in 1:k) {
m[i,j]<-a[j]*theta[i]-b[j]
muz[i,j]<-m[i,j]-delta[j]*V[i,j]
Zs[i,j] ~
dnorm(muz[i,j],preczs[j])I(lo[y[i,j]+1],up[y[i,j]+1])
V[i,j] ~ dnorm(0,1)I(0,)
}
}
#abilities priors
for (i in 1:n) {
theta[i]~dnorm(0,1)
}
#items priors
for (j in 1:k) {
# usual priors
#Bazan et al (2006)
# difficulty (-intercept) with prior similar to bilog
b[j] ~ dnorm(0,0.5)
# discrimination
a[j] ~ dnorm(1,2)I(0,)
# difficulty centred in zero
bc[j] <- b[j] - mean(b[])
#Bazan et al 2006
delta[j] ~ dunif(-1,1)
preczs[j]<- 1/(1-pow(delta[j],2))
lambda[j]<-delta[j]*sqrt(preczs[j])
}
lo[1]<- -50; lo[2]<- 0 ## Zs*|y=0~N(-delta*V+m,1-delta^2)I(-50,0)
up[1]<- 0; up[2]<-50 ## Zs*|y=1~N(-delta*V+m,1-delta^2)I(0,50)
mu<-mean(theta[])
du<-sd(theta[])
}
}
Then, to implement the Bayesian estimation in R will follow the next steps to use the
library R2WinBUGS. Remember to install it previously.
library(R2WinBUGS)
2. Read the data (the MathData.dat file for this example is placed in the folder
F:\MILUS\MathData.dat)
3. Create a list that contain the data and the information of the number of persons
and items using the following command
n=nrow(datos)
k=ncol(datos)
data<-list(y=as.matrix(datos),n=131,k=14)
47
4. Create a program that will generate initial values.
5. Finally the command bugs implements the Bayesian estimation. Here will
explain in brief the syntax of the command bugs
program = is the program that will be used to implement the Bayesian inference
Then the following command implements the Bayesian estimation and the
simulations are stored in the object out.
out<-
bugs(data,inits,parameters.to.save=c("a","b","delta"),
model.file="F:/MILUS/modelirt.txt", n.chains=1, n.iter=24000,
n.burnin=4000, program="WinBUGS")
48
b[1] -0.9 0.4 -1.5 -1.2 -0.9 -0.6 0.0
b[2] -0.9 0.4 -1.6 -1.3 -1.0 -0.6 0.0
b[3] 0.0 0.4 -0.7 -0.4 0.0 0.3 0.7
b[4] -1.7 0.6 -2.7 -2.1 -1.7 -1.2 -0.5
b[5] -1.1 0.5 -1.8 -1.4 -1.1 -0.8 -0.1
b[6] 0.3 0.4 -0.5 0.0 0.3 0.6 1.0
b[7] -1.6 0.6 -2.6 -2.0 -1.6 -1.2 -0.5
b[8] -1.3 0.6 -2.3 -1.7 -1.4 -0.9 -0.2
b[9] -0.7 0.4 -1.3 -1.0 -0.7 -0.4 0.2
b[10] -1.0 0.5 -1.7 -1.4 -1.0 -0.6 0.0
b[11] -1.9 0.7 -3.3 -2.3 -1.9 -1.5 -0.5
b[12] 0.4 0.4 -0.4 0.0 0.4 0.8 1.0
b[13] -0.9 0.4 -1.6 -1.3 -1.0 -0.7 0.0
b[14] -1.6 0.5 -2.4 -1.9 -1.6 -1.2 -0.5
delta[1] 0.1 0.5 -0.8 -0.4 0.0 0.5 1.0
delta[2] -0.1 0.5 -0.9 -0.5 -0.1 0.2 0.9
delta[3] 0.0 0.5 -0.9 -0.4 0.0 0.4 0.9
delta[4] -0.1 0.5 -0.9 -0.5 -0.2 0.2 0.9
delta[5] -0.1 0.5 -0.9 -0.5 -0.1 0.3 0.9
delta[6] 0.0 0.5 -0.9 -0.4 0.0 0.4 1.0
delta[7] -0.1 0.5 -0.9 -0.6 -0.2 0.3 0.9
delta[8] -0.1 0.5 -0.9 -0.6 -0.2 0.2 0.9
delta[9] -0.1 0.5 -0.9 -0.4 -0.1 0.3 0.8
delta[10] -0.1 0.5 -0.9 -0.5 -0.2 0.3 0.9
delta[11] -0.3 0.6 -1.0 -0.8 -0.5 0.1 0.9
delta[12] 0.0 0.5 -1.0 -0.5 0.0 0.4 0.9
delta[13] 0.0 0.5 -0.8 -0.4 0.0 0.4 1.0
delta[14] -0.1 0.5 -0.9 -0.5 -0.1 0.3 0.9
deviance 3855.8 66.3 3703.9 3814.0 3865.0 3904.0 3963.0
Note that for now we just asked for monitoring the parameters a, b and delta. But if it
requires could ask for .
7. Finally, for more details in the command bugs can consult Help writing in the line
of commands
?bugs
Note. You can specify Bug.directory. The directory that contains the WinBUGS
as the default. Also you can specify the program to use, either winbugs/WinBUGS or
openbugs/OpenBUGS, the latter makes use of function openbugs and requires the
CRAN package BRugs. In addition, because of the large number of parameters in IRT
models, execution may be delayed!
49
References
Bazán JL, Branco MD, Bolfarine H (2006) “A skew item response model.” Bayesian
Analysis, 1, 861- 892.
Bazán JL, Bolfarine H, Branco MD (2006). A generalized skew probit class link for
binary regression. Technical report (RT-MAE-2006-05). Department of Statistics.
University of São Paulo. URL
http://argos.pucp.edu.pe/~jlbazan/download/gspversion14.pdf
50
Birnbaum A (1968). Some Latent Trait Models and Their Use in Infering an
Examinee's Ability. In FM Lord, MR Novick (eds) Statistical Theories of Mental Test
Scores. New York: Addison-Wesley.
Carlin BP, Louis TA (2000). Bayes and Empirical Bayes Methods for Data Analysis.
Chapman & Hall, CRC, London, Boca Raton, FL.
Collet D (2003). Modelling binary data. Chapman & Hall/CRC, Second Edition, Boca
Raton, USA.
Congdon P (2010). Applied Bayesian Hierarchical Methods, Chapman & Hall / CRC.
Chen MH, Dey D, Shao Q-M. (2001). “Bayesian analysis of binary data using Skewed
logit models.” Calcutta Statistical Association Bulletin, 51, 201-202.
Curtis MS (2010) “BUGS Code for Item Response Theory.” Journal of Statistical
Software. 36(1), 1-34.
Fox JP (2010). Bayesian Item Response Modeling: Theory and Applications. New York:
Springer.
51
Gilks, WR, Wild P (1992). “Adaptive rejection sampling for Gibbs sampling.” Applied
Statistics, 41: 337-348
Martin AD, Quinn KM, Park, JH (2011). “MCMCpack: Markov Chain Monte Carlo in
R.” Journal of Statistical Software, 42(9): 1-21.
Prentice RL (1976). “A Generalization of the probit and logit methods for Dose
response curves”. Biometrika, 32(4), 761-768.
Rupp A, Dey DK, Zumbo B (2004). “To Bayes or Not to Bayes, from Whether to
When: Applications of Bayesian Methodology to Item Response Modeling.” Structural
Equations Modeling. 11, 424-451.
Sahu SK (2002). “Bayesian estimation and model choice in item response models”.
Journal Statistical Computing Simulation, 72: 217-232.
52
Sheng Y (2008a). “Markov Chain Monte Carlo Estimation of Normal Ogive IRT Models
in MATLAB.” Journal of Statistical Software, 25(8), 1–15.
Sheng Y (2008b). “A MATLAB Package for Markov Chain Monte Carlo with a
Multi-unidimensional IRT Model.” Journal of Statistical Software, 28(10), 1–19.
Sheng Y (2010). Bayesian Estimation of MIRT Models with General and Specific
Latent Traits in MATLAB. Journal of Statistical Software, 34(3), 1-27.
Spiegelhalter DJ, Thomas A, Best NG, Gilks, WR (1996) BUGS 0.5 examples (Vol. 1
Version i). Cambridge, UK: University of Cambridge.
Spiegelhalter DJ, Thomas A, Best NG, Lunn D (2003). WinBUGS Version 1.4 Users
Manual. MRC Biostatistics Unit, Cambridge. URL http://www.mrc-
bsu.cam.ac.uk/bugs/.
53