### Beta_MPT_Model

 Both the Model and MatLab Code displayed here can be found in the attachements at the bottom of this page.To run this You would need to first download the free software WinBUGS at: http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtmlSecondly, I am using MatLab so to give MatLab the ability to interact with WinBUGS, download the freely available matbugs.m function and put it in your Matlab working directory. You can download matbugs.m directly from http://www.cs.ubc.ca/~murphyk/Software/MATBUGS/ matbugs.html # Save this model in a text file as Beta_MPT_Pair_Clustering.txt and you will be able to run the following code found below the model in #MatLab/WinBUGSmodel {        # Following loop defines the base MPT model for (n in 1:subjs) {       # Loop iterates through, subjs, subjects    # theta[s,n] defines the base parameters where s indexes the parameters, and n the subjects    # p[n,k] defines the category probabilities where, n indexes the subject and k the category     p[n,1] <- theta[1,n]*theta[2,n]    p[n,2] <- (1-theta[1,n])*pow(theta[3,n],2)    p[n,3] <- (1-theta[1,n])*(2*theta[3,n])*(1-theta[3,n])    p[n,4] <- theta[1,n]*(1-theta[2,n])+(1-theta[1,n])*pow((1-theta[3,n]),2)     # Designates the data follows a multinomial distribution given the category probabilities response[n,k] is the data matrix    response[n,1:4] ~ dmulti(p[n,1:4],items)} # Following loop defines the hierarchical distribution for (s in 1:3) {    for (n in 1:subjs) {    theta[s,n] ~ dbeta(alph[s],bet[s])I(.001,.999)   # Designates that the base MPT parameters are beta distributed    }} # Priors for each parameterfor (s in 1:3) { # Sets up the priors to be close to flat on the mean and standard deviation of the beta distribution    zero[s] <- 0    zero[s] ~ dpois(phi[s])    phi[s] <- -log(1/pow(alph[s]+bet[s],5/2))         alph[s] ~ dunif(.01,5000)    bet[s] ~ dunif(.01,5000)        mnb[s] <- alph[s]/(alph[s]+bet[s]) # Used to monitor the mean    varp[s] <- sqrt(alph[s]*bet[s]/(pow(alph[s]+bet[s],2)*(alph[s]+bet[s]+1)))    }}_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+% This is what you would add in Matlab after you had installed MatBUGS to run WinBUGS. The data set that you see here is Trial 1 #from Organic Alcoholics. response=[14   3   1   212  3   1   418  0   1   115  3   0   27   1   10  23   6   11  08   4   3   517  1   1   113  4   3   011  6   1   216  1   2   110  1   3   67   13  0   08   4   3   516  1   1   25   4   7   415  0   5   06   3   6   517  2   0   117  1   0   28   3   6   3]; [subjs notused] =size(response); items=20; % The number of items used in the experiment. A row would add up to 20 nchains = 1; % number of chainsnburnin = 20000; % number of burn-in samplesnsamples = 25000; % number of samples % Data to Supply to WinBugsdatastruct = struct('subjs',subjs,'response',response,'items',items); % Initial Values to Supply to WinBugsfor i=1:nchains S.alph = 1/2; S.bet = 1/2; S.theta = 1/2; init0(i) = S;end  [samples, stats] = matbugs(datastruct, ... fullfile(pwd, 'Beta_MPT_Pair_Clustering.txt'), ... 'init', init0, ... 'nChains', nchains, ... 'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ... 'thin', 1, 'DICstatus', 0, 'refreshrate',100, ... 'monitorParams', {'alph','bet','varp','mnb','lambda'}, ... 'Bugdir', 'C:/Program Files/WinBUGS14');
ċ
Gregory Alexander,
Jul 19, 2011, 6:07 AM
ċ
Beta_MPT_Pair_Clustering_Model.m
(1k)
Gregory Alexander,
Jul 19, 2011, 6:14 AM
Comments